Skip to content

Commit e42fb30

Browse files
committed
SETUP_WITH acts like SETUP_FINALLY for the purposes of setting f_lineno (closes python#14612)
1 parent 32c59b6 commit e42fb30

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

Lib/test/test_sys_settrace.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,14 @@ def no_jump_to_non_integers(output):
671671
no_jump_to_non_integers.jump = (2, "Spam")
672672
no_jump_to_non_integers.output = [True]
673673

674+
def jump_across_with(output):
675+
with open(support.TESTFN, "wb") as fp:
676+
pass
677+
with open(support.TESTFN, "wb") as fp:
678+
pass
679+
jump_across_with.jump = (1, 3)
680+
jump_across_with.output = []
681+
674682
# This verifies that you can't set f_lineno via _getframe or similar
675683
# trickery.
676684
def no_jump_without_trace_function():
@@ -740,6 +748,9 @@ def test_18_no_jump_to_non_integers(self):
740748
self.run_test(no_jump_to_non_integers)
741749
def test_19_no_jump_without_trace_function(self):
742750
no_jump_without_trace_function()
751+
def test_jump_across_with(self):
752+
self.addCleanup(support.unlink, support.TESTFN)
753+
self.run_test(jump_across_with)
743754

744755
def test_20_large_function(self):
745756
d = {}

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 3.2.4
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #14612: Fix jumping around with blocks by setting f_lineno.
14+
1315
- Issue #14607: Fix defaults keyword-only arguments which started with ``__``.
1416

1517
- Issue #13889: Check and (if necessary) set FPU control word before calling

Objects/frameobject.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,15 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno)
199199
case SETUP_LOOP:
200200
case SETUP_EXCEPT:
201201
case SETUP_FINALLY:
202+
case SETUP_WITH:
202203
blockstack[blockstack_top++] = addr;
203204
in_finally[blockstack_top-1] = 0;
204205
break;
205206

206207
case POP_BLOCK:
207208
assert(blockstack_top > 0);
208209
setup_op = code[blockstack[blockstack_top-1]];
209-
if (setup_op == SETUP_FINALLY) {
210+
if (setup_op == SETUP_FINALLY || setup_op == SETUP_WITH) {
210211
in_finally[blockstack_top-1] = 1;
211212
}
212213
else {
@@ -221,7 +222,7 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno)
221222
* be seeing such an END_FINALLY.) */
222223
if (blockstack_top > 0) {
223224
setup_op = code[blockstack[blockstack_top-1]];
224-
if (setup_op == SETUP_FINALLY) {
225+
if (setup_op == SETUP_FINALLY || setup_op == SETUP_WITH) {
225226
blockstack_top--;
226227
}
227228
}
@@ -283,6 +284,7 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno)
283284
case SETUP_LOOP:
284285
case SETUP_EXCEPT:
285286
case SETUP_FINALLY:
287+
case SETUP_WITH:
286288
delta_iblock++;
287289
break;
288290

0 commit comments

Comments
 (0)