Skip to content

Commit bb7bb68

Browse files
committed
Fix error handling for line-tracing events
1 parent dd820a9 commit bb7bb68

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

Python/ceval.c

+14-5
Original file line numberDiff line numberDiff line change
@@ -5683,16 +5683,25 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
56835683
err = maybe_call_line_trace(tstate->c_tracefunc,
56845684
tstate->c_traceobj,
56855685
tstate, frame, instr_prev);
5686+
// Reload possibly changed frame fields:
5687+
stack_pointer = _PyFrame_GetStackPointer(frame);
5688+
frame->stacktop = -1;
5689+
// next_instr is only reloaded if tracing *does not* raise.
5690+
// This is consistent with the behavior of older Python
5691+
// versions. If a trace function sets a new f_lineno and
5692+
// *then* raises, we use the *old* location when searching
5693+
// for an exception handler, displaying the traceback, and
5694+
// so on:
56865695
if (err) {
5687-
/* trace function raised an exception */
5696+
// next_instr wasn't incremented at the start of this
5697+
// instruction. Increment it before handling the error,
5698+
// so that it looks the same as a "normal" instruction:
56885699
next_instr++;
56895700
goto error;
56905701
}
5691-
/* Reload possibly changed frame fields */
5702+
// Reload next_instr. Don't increment it, though, since
5703+
// we're going to re-dispatch to the "true" instruction now:
56925704
next_instr = frame->prev_instr;
5693-
5694-
stack_pointer = _PyFrame_GetStackPointer(frame);
5695-
frame->stacktop = -1;
56965705
}
56975706
}
56985707
}

0 commit comments

Comments
 (0)