[Python-checkins] bpo-44570: Fix line tracing for forwards jumps to duplicated tails (GH-27068)

pablogsal webhook-mailer at python.org
Thu Jul 8 14:21:17 EDT 2021


https://github.com/python/cpython/commit/da6414f0acf5ec9ea3b07e4b3907bc49c2a61e2f
commit: da6414f0acf5ec9ea3b07e4b3907bc49c2a61e2f
branch: main
author: Mark Shannon <mark at hotpy.org>
committer: pablogsal <Pablogsal at gmail.com>
date: 2021-07-08T19:21:09+01:00
summary:

bpo-44570: Fix line tracing for forwards jumps to duplicated tails (GH-27068)

files:
M Lib/test/test_sys_settrace.py
M Python/ceval.c

diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py
index 5f2b908d87acb..c42c69d0c807b 100644
--- a/Lib/test/test_sys_settrace.py
+++ b/Lib/test/test_sys_settrace.py
@@ -1041,6 +1041,41 @@ def func_return():
              (-8, 'return'),
              (1, 'return')])
 
+    def test_flow_converges_on_same_line(self):
+
+        def foo(x):
+            if x:
+                try:
+                    1/(x - 1)
+                except ZeroDivisionError:
+                    pass
+            return x
+
+        def func():
+            for i in range(2):
+                foo(i)
+
+        self.run_and_compare(func,
+            [(0, 'call'),
+             (1, 'line'),
+             (2, 'line'),
+             (-8, 'call'),
+             (-7, 'line'),
+             (-2, 'line'),
+             (-2, 'return'),
+             (1, 'line'),
+             (2, 'line'),
+             (-8, 'call'),
+             (-7, 'line'),
+             (-6, 'line'),
+             (-5, 'line'),
+             (-5, 'exception'),
+             (-4, 'line'),
+             (-3, 'line'),
+             (-2, 'line'),
+             (-2, 'return'),
+             (1, 'line'),
+             (1, 'return')])
 
 class SkipLineEventsTraceTestCase(TraceTestCase):
     """Repeat the trace tests, but with per-line events skipped"""
diff --git a/Python/ceval.c b/Python/ceval.c
index 611a39de75d1a..22184058af2d4 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -5476,10 +5476,8 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj,
     int lastline = _PyCode_CheckLineNumber(instr_prev*2, &tstate->trace_info.bounds);
     int line = _PyCode_CheckLineNumber(frame->f_lasti*2, &tstate->trace_info.bounds);
     if (line != -1 && frame->f_trace_lines) {
-        /* Trace backward edges or first instruction of a new line */
-        if (frame->f_lasti < instr_prev ||
-            (line != lastline && frame->f_lasti*2 == tstate->trace_info.bounds.ar_start))
-        {
+        /* Trace backward edges or if line number has changed */
+        if (frame->f_lasti < instr_prev || line != lastline) {
             result = call_trace(func, obj, tstate, frame, PyTrace_LINE, Py_None);
         }
     }



More information about the Python-checkins mailing list