summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2023-08-09 08:30:50 (GMT)
committerGitHub <noreply@github.com>2023-08-09 08:30:50 (GMT)
commit52fbcf61b5a70993c2d32332ff0ad9f369d968d3 (patch)
tree1b6112302fb001276acbffc7d29644b3f2611810
parent2fb484e62518d15fc9a19565c2ab096bd741219a (diff)
downloadcpython-52fbcf61b5a70993c2d32332ff0ad9f369d968d3.zip
cpython-52fbcf61b5a70993c2d32332ff0ad9f369d968d3.tar.gz
cpython-52fbcf61b5a70993c2d32332ff0ad9f369d968d3.tar.bz2
GH-107724: Fix the signature of `PY_THROW` callback functions. (GH-107725)
-rw-r--r--Include/internal/pycore_instruments.h4
-rw-r--r--Lib/test/test_monitoring.py32
-rw-r--r--Misc/NEWS.d/next/Core and Builtins/2023-08-04-21-25-26.gh-issue-107724.EbBXMr.rst3
-rw-r--r--Python/ceval.c2
-rw-r--r--Python/instrumentation.c10
-rw-r--r--Python/legacy_tracing.c6
6 files changed, 39 insertions, 18 deletions
diff --git a/Include/internal/pycore_instruments.h b/Include/internal/pycore_instruments.h
index ccccd54..56de9f8 100644
--- a/Include/internal/pycore_instruments.h
+++ b/Include/internal/pycore_instruments.h
@@ -91,10 +91,6 @@ _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);
diff --git a/Lib/test/test_monitoring.py b/Lib/test/test_monitoring.py
index b36382c..845185b 100644
--- a/Lib/test/test_monitoring.py
+++ b/Lib/test/test_monitoring.py
@@ -743,6 +743,13 @@ class ExceptionHandledRecorder(ExceptionRecorder):
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):
@@ -888,6 +895,31 @@ 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
diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-08-04-21-25-26.gh-issue-107724.EbBXMr.rst b/Misc/NEWS.d/next/Core and Builtins/2023-08-04-21-25-26.gh-issue-107724.EbBXMr.rst
new file mode 100644
index 0000000..6e853cf
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2023-08-04-21-25-26.gh-issue-107724.EbBXMr.rst
@@ -0,0 +1,3 @@
+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.
diff --git a/Python/ceval.c b/Python/ceval.c
index 1dc4fd8..b966399 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -2039,7 +2039,7 @@ monitor_throw(PyThreadState *tstate,
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
diff --git a/Python/instrumentation.c b/Python/instrumentation.c
index 123c20d..65ea790 100644
--- a/Python/instrumentation.c
+++ b/Python/instrumentation.c
@@ -1082,16 +1082,6 @@ call_instrumentation_vector_protected(
}
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,
_PyInterpreterFrame *frame, _Py_CODEUNIT *instr, PyObject *arg0, PyObject *arg1)
diff --git a/Python/legacy_tracing.c b/Python/legacy_tracing.c
index 48db517..7774d10 100644
--- a/Python/legacy_tracing.c
+++ b/Python/legacy_tracing.c
@@ -163,7 +163,7 @@ sys_trace_func2(
}
static PyObject *
-sys_trace_unwind(
+sys_trace_func3(
_PyLegacyEventHandler *self, PyObject *const *args,
size_t nargsf, PyObject *kwnames
) {
@@ -445,7 +445,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_CALL,
+ (vectorcallfunc)sys_trace_func3, PyTrace_CALL,
PY_MONITORING_EVENT_PY_THROW, -1)) {
return -1;
}
@@ -470,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_unwind, PyTrace_RETURN,
+ (vectorcallfunc)sys_trace_func3, PyTrace_RETURN,
PY_MONITORING_EVENT_PY_UNWIND, -1)) {
return -1;
}