[Python-checkins] GH-96864: Check for error between line and opcode events (GH-96880)

miss-islington webhook-mailer at python.org
Tue Sep 20 13:49:26 EDT 2022


https://github.com/python/cpython/commit/32d80decbf0ab07b8083467c9222dffb7790c08e
commit: 32d80decbf0ab07b8083467c9222dffb7790c08e
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-09-20T10:49:01-07:00
summary:

GH-96864: Check for error between line and opcode events (GH-96880)

(cherry picked from commit c10e33ac119d96c4d88d5ae8b59e65a76ae0ad3c)

Co-authored-by: Brandt Bucher <brandtbucher at microsoft.com>

files:
A Misc/NEWS.d/next/Core and Builtins/2022-09-16-12-36-13.gh-issue-96864.PLU3i8.rst
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 9f1aa81dbcd2..aa61f8b18588 100644
--- a/Lib/test/test_sys_settrace.py
+++ b/Lib/test/test_sys_settrace.py
@@ -1721,6 +1721,20 @@ def g(frame, event, arg):
         finally:
             sys.settrace(existing)
 
+    def test_line_event_raises_before_opcode_event(self):
+        exception = ValueError("BOOM!")
+        def trace(frame, event, arg):
+            if event == "line":
+                raise exception
+            frame.f_trace_opcodes = True
+            return trace
+        def f():
+            pass
+        with self.assertRaises(ValueError) as caught:
+            sys.settrace(trace)
+            f()
+        self.assertIs(caught.exception, exception)
+
 
 # 'Jump' tests: assigning to frame.f_lineno within a trace function
 # moves the execution position - it's how debuggers implement a Jump
diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-09-16-12-36-13.gh-issue-96864.PLU3i8.rst b/Misc/NEWS.d/next/Core and Builtins/2022-09-16-12-36-13.gh-issue-96864.PLU3i8.rst
new file mode 100644
index 000000000000..c0d41ae7d21e
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2022-09-16-12-36-13.gh-issue-96864.PLU3i8.rst	
@@ -0,0 +1,2 @@
+Fix a possible assertion failure, fatal error, or :exc:`SystemError` if a
+line tracing event raises an exception while opcode tracing is enabled.
diff --git a/Python/ceval.c b/Python/ceval.c
index a5dfacf4f5ca..f95e95c0589c 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -6933,7 +6933,7 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj,
         }
     }
     /* Always emit an opcode event if we're tracing all opcodes. */
-    if (f->f_trace_opcodes) {
+    if (f->f_trace_opcodes && result == 0) {
         result = call_trace(func, obj, tstate, frame, PyTrace_OPCODE, Py_None);
     }
     return result;



More information about the Python-checkins mailing list