[Python-checkins] [2.7] bpo-33026: Fix jumping out of "with" block by setting f_lineno. (GH-6026). (GH-6074) (GH-6076)

Serhiy Storchaka webhook-mailer at python.org
Sun Mar 11 04:56:02 EDT 2018


https://github.com/python/cpython/commit/3854f5885edc8dc67b1aba82fbb525604fbc625b
commit: 3854f5885edc8dc67b1aba82fbb525604fbc625b
branch: 2.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Serhiy Storchaka <storchaka at gmail.com>
date: 2018-03-11T10:55:59+02:00
summary:

[2.7] bpo-33026: Fix jumping out of "with" block by setting f_lineno. (GH-6026). (GH-6074) (GH-6076)

(cherry picked from commit 26c9f565d016db21257a60d29ab2c99383dd5ac7)
(cherry picked from commit 04aadf23eac51fec2e436c5960c1362bbb7d03de)

Co-authored-by: Serhiy Storchaka <storchaka at gmail.com>

files:
A Misc/NEWS.d/next/Core and Builtins/2018-03-08-09-48-38.bpo-33026.QZA3Ba.rst
M Lib/test/test_sys_settrace.py
M Objects/frameobject.c

diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py
index 7e1d7a131f5a..04b1ac339a49 100644
--- a/Lib/test/test_sys_settrace.py
+++ b/Lib/test/test_sys_settrace.py
@@ -723,6 +723,34 @@ def test_jump_across_with(output):
         with tracecontext(output, 4):
             output.append(5)
 
+    @jump_test(4, 5, [1, 3, 5, 6])
+    def test_jump_out_of_with_block_within_for_block(output):
+        output.append(1)
+        for i in [1]:
+            with tracecontext(output, 3):
+                output.append(4)
+            output.append(5)
+        output.append(6)
+
+    @jump_test(4, 5, [1, 2, 3, 5, -2, 6])
+    def test_jump_out_of_with_block_within_with_block(output):
+        output.append(1)
+        with tracecontext(output, 2):
+            with tracecontext(output, 3):
+                output.append(4)
+            output.append(5)
+        output.append(6)
+
+    @jump_test(5, 6, [2, 4, 6, 7])
+    def test_jump_out_of_with_block_within_finally_block(output):
+        try:
+            output.append(2)
+        finally:
+            with tracecontext(output, 4):
+                output.append(5)
+            output.append(6)
+        output.append(7)
+
     @jump_test(8, 11, [1, 3, 5, 11, 12])
     def test_jump_out_of_complex_nested_blocks(output):
         output.append(1)
diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-03-08-09-48-38.bpo-33026.QZA3Ba.rst b/Misc/NEWS.d/next/Core and Builtins/2018-03-08-09-48-38.bpo-33026.QZA3Ba.rst
new file mode 100644
index 000000000000..dc166d1e5771
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2018-03-08-09-48-38.bpo-33026.QZA3Ba.rst	
@@ -0,0 +1 @@
+Fixed jumping out of "with" block by setting f_lineno.
diff --git a/Objects/frameobject.c b/Objects/frameobject.c
index 2c8fb017492e..bf1c7c52737d 100644
--- a/Objects/frameobject.c
+++ b/Objects/frameobject.c
@@ -340,6 +340,11 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno)
             PyObject *v = (*--f->f_stacktop);
             Py_DECREF(v);
         }
+        if (b->b_type == SETUP_WITH) {
+            /* Pop the exit function. */
+            PyObject *v = (*--f->f_stacktop);
+            Py_DECREF(v);
+        }
     }
 
     /* Finally set the new f_lineno and f_lasti and return OK. */



More information about the Python-checkins mailing list