Skip to content

Commit 6a67945

Browse files
miss-islingtonaisk
andauthored
[3.15] gh-155823: Fix stale stack on _SEND_VIRTUAL_TIER_TWO exhausted exit (GH-155844) (GH-158559)
(cherry picked from commit 1071f74) Co-authored-by: An Long <aisk@users.noreply.github.com>
1 parent 261fe71 commit 6a67945

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
@@ -5699,6 +5699,20 @@ def testfunc(n):
56995699
self.assertIn("_FOR_ITER_GEN_FRAME", uops)
57005700
self.assertIn("_SEND_VIRTUAL_TIER_TWO", uops)
57015701

5702+
def test_send_virtual_exhausted(self):
5703+
# gh-155823: warm up on a non-empty list, then take the exhausted exit.
5704+
def gen(x):
5705+
yield from x
5706+
def testfunc(n, x):
5707+
total = 0
5708+
for _ in range(n):
5709+
for v in gen(x):
5710+
total += v
5711+
return total
5712+
5713+
testfunc(TIER2_THRESHOLD * 10, [1])
5714+
self.assertEqual(testfunc(1000, []), 0)
5715+
57025716
def test_binary_op_subscr_init_frame(self):
57035717
class B:
57045718
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)