Skip to content

Commit 1cefb76

Browse files
aiskmiss-islington
authored andcommitted
gh-155823: Fix stale stack on _SEND_VIRTUAL_TIER_TWO exhausted exit (GH-155844)
(cherry picked from commit 1071f74) Co-authored-by: An Long <aisk@users.noreply.github.com>
1 parent 3105a34 commit 1cefb76

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
@@ -5554,6 +5554,20 @@ def testfunc(n):
55545554
self.assertIn("_FOR_ITER_GEN_FRAME", uops)
55555555
self.assertIn("_SEND_VIRTUAL_TIER_TWO", uops)
55565556

5557+
def test_send_virtual_exhausted(self):
5558+
# gh-155823: warm up on a non-empty list, then take the exhausted exit.
5559+
def gen(x):
5560+
yield from x
5561+
def testfunc(n, x):
5562+
total = 0
5563+
for _ in range(n):
5564+
for v in gen(x):
5565+
total += v
5566+
return total
5567+
5568+
testfunc(TIER2_THRESHOLD * 10, [1])
5569+
self.assertEqual(testfunc(1000, []), 0)
5570+
55575571
def test_binary_op_subscr_init_frame(self):
55585572
class B:
55595573
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
@@ -1785,8 +1785,6 @@ dummy_func(
17851785
if (index < 0) {
17861786
ERROR_NO_POP();
17871787
}
1788-
next = none;
1789-
DEAD(none);
17901788
EXIT_IF(true);
17911789
}
17921790
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)