_Py_call_instrumentation_2args(PyThreadState *tstate, int event,
_PyInterpreterFrame *frame, _Py_CODEUNIT *instr, PyObject *arg0, PyObject *arg1);
-extern void
-_Py_call_instrumentation_exc0(PyThreadState *tstate, int event,
- _PyInterpreterFrame *frame, _Py_CODEUNIT *instr);
-
extern void
_Py_call_instrumentation_exc2(PyThreadState *tstate, int event,
_PyInterpreterFrame *frame, _Py_CODEUNIT *instr, PyObject *arg0, PyObject *arg1);
def __call__(self, code, offset, exc):
self.events.append(("handled", type(exc)))
+class ThrowRecorder(ExceptionRecorder):
+
+ event_type = E.PY_THROW
+
+ def __call__(self, code, offset, exc):
+ self.events.append(("throw", type(exc)))
+
class ExceptionMonitoringTest(CheckEvents):
func,
recorders = self.exception_recorders)
+ def test_throw(self):
+
+ def gen():
+ yield 1
+ yield 2
+
+ def func():
+ try:
+ g = gen()
+ next(g)
+ g.throw(IndexError)
+ except IndexError:
+ pass
+
+ self.check_balanced(
+ func,
+ recorders = self.exception_recorders)
+
+ events = self.get_events(
+ func,
+ TEST_TOOL,
+ self.exception_recorders + (ThrowRecorder,)
+ )
+ self.assertEqual(events[0], ("throw", IndexError))
+
class LineRecorder:
event_type = E.LINE
--- /dev/null
+In pre-release versions of 3.12, up to rc1, the sys.monitoring callback
+function for the ``PY_THROW`` event was missing the third, exception
+argument. That is now fixed.
if (no_tools_for_event(tstate, frame, PY_MONITORING_EVENT_PY_THROW)) {
return;
}
- _Py_call_instrumentation_exc0(tstate, PY_MONITORING_EVENT_PY_THROW, frame, instr);
+ do_monitor_exc(tstate, frame, instr, PY_MONITORING_EVENT_PY_THROW);
}
void
assert(_PyErr_Occurred(tstate));
}
-void
-_Py_call_instrumentation_exc0(
- PyThreadState *tstate, int event,
- _PyInterpreterFrame *frame, _Py_CODEUNIT *instr)
-{
- assert(_PyErr_Occurred(tstate));
- PyObject *args[3] = { NULL, NULL, NULL };
- call_instrumentation_vector_protected(tstate, event, frame, instr, 2, args);
-}
-
void
_Py_call_instrumentation_exc2(
PyThreadState *tstate, int event,
}
static PyObject *
-sys_trace_unwind(
+sys_trace_func3(
_PyLegacyEventHandler *self, PyObject *const *args,
size_t nargsf, PyObject *kwnames
) {
return -1;
}
if (set_callbacks(PY_MONITORING_SYS_TRACE_ID,
- (vectorcallfunc)sys_trace_func2, PyTrace_CALL,
+ (vectorcallfunc)sys_trace_func3, PyTrace_CALL,
PY_MONITORING_EVENT_PY_THROW, -1)) {
return -1;
}
return -1;
}
if (set_callbacks(PY_MONITORING_SYS_TRACE_ID,
- (vectorcallfunc)sys_trace_unwind, PyTrace_RETURN,
+ (vectorcallfunc)sys_trace_func3, PyTrace_RETURN,
PY_MONITORING_EVENT_PY_UNWIND, -1)) {
return -1;
}