Skip to content

Commit 21b5af9

Browse files
authored
[3.10] GH-96864: Check for error between line and opcode events (GH-96969)
(cherry picked from commit c10e33a)
1 parent 96739bc commit 21b5af9

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

Lib/test/test_sys_settrace.py

+14
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,20 @@ def g(frame, event, arg):
13101310
finally:
13111311
sys.settrace(existing)
13121312

1313+
def test_line_event_raises_before_opcode_event(self):
1314+
exception = ValueError("BOOM!")
1315+
def trace(frame, event, arg):
1316+
if event == "line":
1317+
raise exception
1318+
frame.f_trace_opcodes = True
1319+
return trace
1320+
def f():
1321+
pass
1322+
with self.assertRaises(ValueError) as caught:
1323+
sys.settrace(trace)
1324+
f()
1325+
self.assertIs(caught.exception, exception)
1326+
13131327

13141328
# 'Jump' tests: assigning to frame.f_lineno within a trace function
13151329
# moves the execution position - it's how debuggers implement a Jump
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a possible assertion failure, fatal error, or :exc:`SystemError` if a
2+
line tracing event raises an exception while opcode tracing is enabled.

Python/ceval.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -5512,7 +5512,7 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj,
55125512
}
55135513
}
55145514
/* Always emit an opcode event if we're tracing all opcodes. */
5515-
if (frame->f_trace_opcodes) {
5515+
if (frame->f_trace_opcodes && result == 0) {
55165516
result = call_trace(func, obj, tstate, frame, trace_info, PyTrace_OPCODE, Py_None);
55175517
}
55185518
return result;

0 commit comments

Comments
 (0)