]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-106898: Add the exception as an argument to the `PY_UNWIND` event callback functio...
authorMark Shannon <mark@hotpy.org>
Thu, 27 Jul 2023 14:47:33 +0000 (15:47 +0100)
committerGitHub <noreply@github.com>
Thu, 27 Jul 2023 14:47:33 +0000 (15:47 +0100)
Lib/test/test_monitoring.py
Misc/NEWS.d/next/Core and Builtins/2023-07-26-21-28-06.gh-issue-106898.8Wjuiv.rst [new file with mode: 0644]
Python/ceval.c
Python/legacy_tracing.c

index 7098f483e0ee7fa6b0c5b0dc4294137978259487..b36382c8d0982d1f054586b5289d8021ecdb099b 100644 (file)
@@ -715,7 +715,7 @@ class CheckEvents(MonitoringTestBase, unittest.TestCase):
             self.assertIn(r0, ("raise", "reraise"))
             h0 = h[0]
             self.assertIn(h0, ("handled", "unwind"))
-
+            self.assertEqual(r[1], h[1])
 
 
 class StopiterationRecorder(ExceptionRecorder):
@@ -733,8 +733,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):
 
diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-07-26-21-28-06.gh-issue-106898.8Wjuiv.rst b/Misc/NEWS.d/next/Core and Builtins/2023-07-26-21-28-06.gh-issue-106898.8Wjuiv.rst
new file mode 100644 (file)
index 0000000..f1b1c4c
--- /dev/null
@@ -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.
index c0b37b328a25fc3825363f818bce77792ac438d0..17818a0d3c17e642d0fe4b610dc091bc30fe4f52 100644 (file)
@@ -1987,7 +1987,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);
 }
 
 
index 9cc48fc9493a05c1198c73b2c5b13bc3e7c3dca4..48db51731cfdb09af026ddd79f4e5da828d4fa60 100644 (file)
@@ -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,
@@ -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,
@@ -362,7 +382,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;
         }
@@ -450,7 +470,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;
         }