Skip to content

Commit ff663ef

Browse files
committed
pop the loop block even for infinite while loops (closes #23048)
1 parent e9bdc84 commit ff663ef

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

Lib/test/test_sys_settrace.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,15 @@ def jump_in_nested_finally(output):
551551
jump_in_nested_finally.jump = (4, 9)
552552
jump_in_nested_finally.output = [2, 9]
553553

554+
def jump_infinite_while_loop(output):
555+
output.append(1)
556+
while 1:
557+
output.append(2)
558+
output.append(3)
559+
560+
jump_infinite_while_loop.jump = (3, 4)
561+
jump_infinite_while_loop.output = [1, 3]
562+
554563
# The second set of 'jump' tests are for things that are not allowed:
555564

556565
def no_jump_too_far_forwards(output):
@@ -723,6 +732,8 @@ def test_06_jump_to_same_line(self):
723732
self.run_test(jump_to_same_line)
724733
def test_07_jump_in_nested_finally(self):
725734
self.run_test(jump_in_nested_finally)
735+
def test_jump_infinite_while_loop(self):
736+
self.run_test(jump_infinite_while_loop)
726737
def test_08_no_jump_too_far_forwards(self):
727738
self.run_test(no_jump_too_far_forwards)
728739
def test_09_no_jump_too_far_backwards(self):

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ What's New in Python 2.7.10?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #23048: Fix jumping out of an infinite while loop in the pdb.
14+
1315
Library
1416
-------
1517

Python/compile.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,10 +1716,9 @@ compiler_while(struct compiler *c, stmt_ty s)
17161716
if there is no else clause ?
17171717
*/
17181718

1719-
if (constant == -1) {
1719+
if (constant == -1)
17201720
compiler_use_next_block(c, anchor);
1721-
ADDOP(c, POP_BLOCK);
1722-
}
1721+
ADDOP(c, POP_BLOCK);
17231722
compiler_pop_fblock(c, LOOP, loop);
17241723
if (orelse != NULL) /* what if orelse is just pass? */
17251724
VISIT_SEQ(c, stmt, s->v.While.orelse);

0 commit comments

Comments
 (0)