Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Lib/test/test_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ def check_balanced(self, func, recorders):
self.assertIn(r0, ("raise", "reraise"))
h0 = h[0]
self.assertIn(h0, ("handled", "unwind"))

self.assertEqual(r[1], h[1])


class StopiterationRecorder(ExceptionRecorder):
Expand All @@ -683,8 +683,8 @@ class UnwindRecorder(ExceptionRecorder):

event_type = E.PY_UNWIND

def __call__(self, *args):
self.events.append(("unwind", None))
def __call__(self, code, offset, exc):
self.events.append(("unwind", type(exc)))

class ExceptionHandledRecorder(ExceptionRecorder):

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Add the exception as the third argument to ``PY_UNIND`` callbacks in
``sys.monitoring``. This makes the ``PY_UNWIND`` callback consistent with
the other exception hanlding callbacks.
2 changes: 1 addition & 1 deletion Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -2067,7 +2067,7 @@ monitor_unwind(PyThreadState *tstate,
if (no_tools_for_event(tstate, frame, PY_MONITORING_EVENT_PY_UNWIND)) {
return;
}
_Py_call_instrumentation_exc0(tstate, PY_MONITORING_EVENT_PY_UNWIND, frame, instr);
do_monitor_exc(tstate, frame, instr, PY_MONITORING_EVENT_PY_UNWIND);
}


Expand Down
24 changes: 22 additions & 2 deletions Python/legacy_tracing.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ sys_profile_func3(
return call_profile_func(self, args[2]);
}

static PyObject *
sys_profile_unwind(
_PyLegacyEventHandler *self, PyObject *const *args,
size_t nargsf, PyObject *kwnames
) {
assert(kwnames == NULL);
assert(PyVectorcall_NARGS(nargsf) == 3);
return call_profile_func(self, Py_None);
}

static PyObject *
sys_profile_call_or_return(
_PyLegacyEventHandler *self, PyObject *const *args,
Expand Down Expand Up @@ -152,6 +162,16 @@ sys_trace_func2(
return call_trace_func(self, Py_None);
}

static PyObject *
sys_trace_unwind(
_PyLegacyEventHandler *self, PyObject *const *args,
size_t nargsf, PyObject *kwnames
) {
assert(kwnames == NULL);
assert(PyVectorcall_NARGS(nargsf) == 3);
return call_trace_func(self, Py_None);
}

static PyObject *
sys_trace_return(
_PyLegacyEventHandler *self, PyObject *const *args,
Expand Down Expand Up @@ -363,7 +383,7 @@ _PyEval_SetProfile(PyThreadState *tstate, Py_tracefunc func, PyObject *arg)
return -1;
}
if (set_callbacks(PY_MONITORING_SYS_PROFILE_ID,
(vectorcallfunc)sys_profile_func2, PyTrace_RETURN,
(vectorcallfunc)sys_profile_unwind, PyTrace_RETURN,
PY_MONITORING_EVENT_PY_UNWIND, -1)) {
return -1;
}
Expand Down Expand Up @@ -451,7 +471,7 @@ _PyEval_SetTrace(PyThreadState *tstate, Py_tracefunc func, PyObject *arg)
return -1;
}
if (set_callbacks(PY_MONITORING_SYS_TRACE_ID,
(vectorcallfunc)sys_trace_func2, PyTrace_RETURN,
(vectorcallfunc)sys_trace_unwind, PyTrace_RETURN,
PY_MONITORING_EVENT_PY_UNWIND, -1)) {
return -1;
}
Expand Down