]> granicus.if.org Git - python/commitdiff
pop the loop block even for infinite while loops (closes #23048)
authorBenjamin Peterson <benjamin@python.org>
Sat, 13 Dec 2014 21:06:19 +0000 (16:06 -0500)
committerBenjamin Peterson <benjamin@python.org>
Sat, 13 Dec 2014 21:06:19 +0000 (16:06 -0500)
Lib/test/test_sys_settrace.py
Misc/NEWS
Python/compile.c

index 9c7bcef2e7e70a4a0ac70b9a9b7af36ff4835df3..1eea7862daf20e2b2b15ff12a0170c1a13c21567 100644 (file)
@@ -551,6 +551,15 @@ def jump_in_nested_finally(output):
 jump_in_nested_finally.jump = (4, 9)
 jump_in_nested_finally.output = [2, 9]
 
+def jump_infinite_while_loop(output):
+    output.append(1)
+    while 1:
+        output.append(2)
+    output.append(3)
+
+jump_infinite_while_loop.jump = (3, 4)
+jump_infinite_while_loop.output = [1, 3]
+
 # The second set of 'jump' tests are for things that are not allowed:
 
 def no_jump_too_far_forwards(output):
@@ -723,6 +732,8 @@ class JumpTestCase(unittest.TestCase):
         self.run_test(jump_to_same_line)
     def test_07_jump_in_nested_finally(self):
         self.run_test(jump_in_nested_finally)
+    def test_jump_infinite_while_loop(self):
+        self.run_test(jump_infinite_while_loop)
     def test_08_no_jump_too_far_forwards(self):
         self.run_test(no_jump_too_far_forwards)
     def test_09_no_jump_too_far_backwards(self):
index 3f86e90873e001e7b5121c8a9cbf1d7cfbd6518b..c0c860372455deee290c9524e865234a4479cc0d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,8 @@ What's New in Python 2.7.10?
 Core and Builtins
 -----------------
 
+- Issue #23048: Fix jumping out of an infinite while loop in the pdb.
+
 Library
 -------
 
index 9d9e62904cde4dca2a64073968a246434548748e..1f59c8c9a4d2758e9de30250e428a3ac759a16c4 100644 (file)
@@ -1716,10 +1716,9 @@ compiler_while(struct compiler *c, stmt_ty s)
        if there is no else clause ?
     */
 
-    if (constant == -1) {
+    if (constant == -1)
         compiler_use_next_block(c, anchor);
-        ADDOP(c, POP_BLOCK);
-    }
+    ADDOP(c, POP_BLOCK);
     compiler_pop_fblock(c, LOOP, loop);
     if (orelse != NULL) /* what if orelse is just pass? */
         VISIT_SEQ(c, stmt, s->v.While.orelse);