Skip to content

Commit 1071f74

Browse files
authored
gh-155823: Fix stale stack on _SEND_VIRTUAL_TIER_TWO exhausted exit (GH-155844)
1 parent 763b6ed commit 1071f74

4 files changed

Lines changed: 21 additions & 9 deletions

File tree

‎Lib/test/test_capi/test_opt.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5821,6 +5821,20 @@ def testfunc(n):
58215821
self.assertIn("_FOR_ITER_GEN_FRAME", uops)
58225822
self.assertIn("_SEND_VIRTUAL_TIER_TWO", uops)
58235823

5824+
def test_send_virtual_exhausted(self):
5825+
# gh-155823: warm up on a non-empty list, then take the exhausted exit.
5826+
def gen(x):
5827+
yield from x
5828+
def testfunc(n, x):
5829+
total = 0
5830+
for _ in range(n):
5831+
for v in gen(x):
5832+
total += v
5833+
return total
5834+
5835+
testfunc(TIER2_THRESHOLD * 10, [1])
5836+
self.assertEqual(testfunc(1000, []), 0)
5837+
58245838
def test_binary_op_subscr_init_frame(self):
58255839
class B:
58265840
def __getitem__(self, other):
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fix a JIT bug where the side exit taken when a virtual iterator is exhausted
2+
left a stale value on the stack, so the tier one interpreter resumed with
3+
corrupted state and ``yield from`` raised :exc:`AttributeError` instead of
4+
finishing normally.

‎Python/bytecodes.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,8 +1786,6 @@ dummy_func(
17861786
if (index < 0) {
17871787
ERROR_NO_POP();
17881788
}
1789-
next = none;
1790-
DEAD(none);
17911789
EXIT_IF(true);
17921790
}
17931791
DEAD(none);

‎Python/executor_cases.c.h‎

Lines changed: 3 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)