mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
[3.12] GH-106898: Add the exception as an argument to the PY_UNWIND
event callback function. (GH-107347) (GH-107382)
This commit is contained in:
parent
0902afbae2
commit
3f167de440
4 changed files with 29 additions and 6 deletions
|
@ -715,7 +715,7 @@ class CheckEvents(MonitoringTestBase, unittest.TestCase):
|
||||||
self.assertIn(r0, ("raise", "reraise"))
|
self.assertIn(r0, ("raise", "reraise"))
|
||||||
h0 = h[0]
|
h0 = h[0]
|
||||||
self.assertIn(h0, ("handled", "unwind"))
|
self.assertIn(h0, ("handled", "unwind"))
|
||||||
|
self.assertEqual(r[1], h[1])
|
||||||
|
|
||||||
|
|
||||||
class StopiterationRecorder(ExceptionRecorder):
|
class StopiterationRecorder(ExceptionRecorder):
|
||||||
|
@ -733,8 +733,8 @@ class UnwindRecorder(ExceptionRecorder):
|
||||||
|
|
||||||
event_type = E.PY_UNWIND
|
event_type = E.PY_UNWIND
|
||||||
|
|
||||||
def __call__(self, *args):
|
def __call__(self, code, offset, exc):
|
||||||
self.events.append(("unwind", None))
|
self.events.append(("unwind", type(exc)))
|
||||||
|
|
||||||
class ExceptionHandledRecorder(ExceptionRecorder):
|
class ExceptionHandledRecorder(ExceptionRecorder):
|
||||||
|
|
||||||
|
|
|
@ -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.
|
|
@ -2070,7 +2070,7 @@ monitor_unwind(PyThreadState *tstate,
|
||||||
if (no_tools_for_event(tstate, frame, PY_MONITORING_EVENT_PY_UNWIND)) {
|
if (no_tools_for_event(tstate, frame, PY_MONITORING_EVENT_PY_UNWIND)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_Py_call_instrumentation_exc0(tstate, PY_MONITORING_EVENT_PY_UNWIND, frame, instr);
|
do_monitor_exc(tstate, frame, instr, PY_MONITORING_EVENT_PY_UNWIND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,16 @@ sys_profile_func3(
|
||||||
return call_profile_func(self, args[2]);
|
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 *
|
static PyObject *
|
||||||
sys_profile_call_or_return(
|
sys_profile_call_or_return(
|
||||||
_PyLegacyEventHandler *self, PyObject *const *args,
|
_PyLegacyEventHandler *self, PyObject *const *args,
|
||||||
|
@ -152,6 +162,16 @@ sys_trace_func2(
|
||||||
return call_trace_func(self, Py_None);
|
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 *
|
static PyObject *
|
||||||
sys_trace_return(
|
sys_trace_return(
|
||||||
_PyLegacyEventHandler *self, PyObject *const *args,
|
_PyLegacyEventHandler *self, PyObject *const *args,
|
||||||
|
@ -363,7 +383,7 @@ _PyEval_SetProfile(PyThreadState *tstate, Py_tracefunc func, PyObject *arg)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (set_callbacks(PY_MONITORING_SYS_PROFILE_ID,
|
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)) {
|
PY_MONITORING_EVENT_PY_UNWIND, -1)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -451,7 +471,7 @@ _PyEval_SetTrace(PyThreadState *tstate, Py_tracefunc func, PyObject *arg)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (set_callbacks(PY_MONITORING_SYS_TRACE_ID,
|
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)) {
|
PY_MONITORING_EVENT_PY_UNWIND, -1)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue