10000 bpo-44570: Fix line tracing for forwards jumps to duplicated tails (G… · python/cpython@da6414f · GitHub
[go: up one dir, main page]

Skip to content

Commit da6414f

Browse files
authored
bpo-44570: Fix line tracing for forwards jumps to duplicated tails (GH-27068)
1 parent 91a8f8c commit da6414f

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

Lib/test/test_sys_settrace.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,41 @@ def func_return():
10411041
(-8, 'return'),
10421042
(1, 'return')])
10431043

1044+
def test_flow_converges_on_same_line(self):
1045+
1046+
def foo(x):
1047+
if x:
1048+
try:
1049+
1/(x - 1)
1050+
except ZeroDivisionError:
1051+
pass
1052+
return x
1053+
1054+
def func():
1055+
for i in range(2):
1056+
foo(i)
1057+
1058+
self.run_and_compare(func,
1059+
[(0, 'call'),
1060+
(1, 'line'),
1061+
(2, 'line'),
1062+
(-8, 'call'),
1063+
(-7, 'line'),
1064+
(-2, 'line'),
1065+
(-2, 'return'),
1066+
(1, 'line'),
1067+
(2, 'line'),
1068+
(-8, 'call'),
1069+
(-7, 'line'),
1070+
(-6, 'line'),
1071+
(-5, 'line'),
1072+
(-5, 'exception'),
1073+
(-4, 'line'),
1074+
(-3, 'line'),
1075+
(-2, 'line'),
1076+
(-2, 'return'),
1077+
(1, 'line'),
1078+
(1, 'return')])
10441079

10451080
class SkipLineEventsTraceTestCase(TraceTestCase):
10461081
"""Repeat the trace tests, but with per-line events skipped"""

Python/ceval.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5476,10 +5476,8 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj,
54765476
int lastline = _PyCode_CheckLineNumber(instr_prev*2, &tstate->trace_info.bounds);
54775477
int line = _PyCode_CheckLineNumber(frame->f_lasti*2, &tstate->trace_info.bounds);
54785478
if (line != -1 && frame->f_trace_lines) {
5479-
/* Trace backward edges or first instruction of a new line */
5480-
if (frame->f_lasti < instr_prev ||
5481-
(line != lastline && frame->f_lasti*2 == tstate->trace_info.bounds.ar_start))
5482-
{
5479+
/* Trace backward edges or if line number has changed */
5480+
if (frame->f_lasti < instr_prev || line != lastline) {
54835481
result = call_trace(func, obj, tstate, frame, PyTrace_LINE, Py_None);
54845482
}
54855483
}

0 commit comments

Comments
 (0)
0