8000 [3.12] GH-107724: Fix the signature of `PY_THROW` callback functions.… · python/cpython@ddca261 · GitHub
[go: up one dir, main page]

Skip to content

Commit ddca261

Browse files
[3.12] GH-107724: Fix the signature of PY_THROW callback functions. (GH-107725) (#107802)
GH-107724: Fix the signature of `PY_THROW` callback functions. (GH-107725) (cherry picked from commit 52fbcf6) Co-authored-by: Mark Shannon <mark@hotpy.org>
1 parent 7853c76 commit ddca261

File tree

6 files changed

+39
-18
lines changed

6 files changed

+39
-18
lines changed

Include/internal/pycore_instruments.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@ extern int
9090
_Py_call_instrumentation_2args(PyThreadState *tstate, int event,
9191
_PyInterpreterFrame *frame, _Py_CODEUNIT *instr, PyObject *arg0, PyObject *arg1);
9292

93-
extern void
94-
_Py_call_instrumentation_exc0(PyThreadState *tstate, int event,
95-
_PyInterpreterFrame *frame, _Py_CODEUNIT *instr);
96-
9793
extern void
9894
_Py_call_instrumentation_exc2(PyThreadState *tstate, int event,
9995
_PyInterpreterFrame *frame, _Py_CODEUNIT *instr, PyObject *arg0, PyObject *arg1);

Lib/test/test_monitoring.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,13 @@ class ExceptionHandledRecorder(ExceptionRecorder):
743743
def __call__(self, code, offset, exc):
744744
self.events.append(("handled", type(exc)))
745745

746+
class ThrowRecorder(ExceptionRecorder):
747+
748+
event_type = E.PY_THROW
749+
750+
def __call__(self, code, offset, exc):
751+
self.events.append(("throw", type(exc)))
752+
746753
class ExceptionMonitoringTest(CheckEvents):
747754

748755

@@ -888,6 +895,31 @@ async def async_loop():
888895
func,
889896
recorders = self.exception_recorders)
890897

898+
def test_throw(self):
899+
900+
def gen():
901+
yield 1
902+
yield 2
903+
904+
def func():
905+
try:
906+
g = gen()
907+
next(g)
908+
g.throw(IndexError)
909+
except IndexError:
910+
pass
911+
912+
self.check_balanced(
913+
func,
914+
recorders = self.exception_recorders)
915+
916+
events = self.get_events(
917+
func,
918+
TEST_TOOL,
919+
self.exception_recorders + (ThrowRecorder,)
920+
)
921+
self.assertEqual(events[0], ("throw", IndexError))
922+
891923
class LineRecorder:
892924

893925
event_type = E.LINE
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
In pre-release versions of 3.12, up to rc1, the sys.monitoring callback
2+
function for the ``PY_THROW`` event was missing the third, exception
3+
argument. That is now fixed.

Python/ceval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2099,7 +2099,7 @@ monitor_throw(PyThreadState *tstate,
20992099
if (no_tools_for_event(tstate, frame, PY_MONITORING_EVENT_PY_THROW)) {
21002100
return;
21012101
}
2102-
_Py_call_instrumentation_exc0(tstate, PY_MONITORING_EVENT_PY_THROW, frame, instr);
2102+
do_monitor_exc(tstate, frame, instr, PY_MONITORING_EVENT_PY_THROW);
21032103
}
21042104

21052105
void

Python/instrumentation.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,16 +1070,6 @@ call_instrumentation_vector_protected(
10701070
assert(_PyErr_Occurred(tstate));
10711071
}
10721072

1073-
void
1074-
_Py_call_instrumentation_exc0(
1075-
PyThreadState *tstate, int event,
1076-
_PyInterpreterFrame *frame, _Py_CODEUNIT *instr)
1077-
{
1078-
assert(_PyErr_Occurred(tstate));
1079-
PyObject *args[3] = { NULL, NULL, NULL };
1080-
call_instrumentation_vector_protected(tstate, event, frame, instr, 2, args);
1081-
}
1082-
10831073
void
10841074
_Py_call_instrumentation_exc2(
10851075
PyThreadState *tstate, int event,

Python/legacy_tracing.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ sys_trace_func2(
163163
}
164164

165165
static PyObject *
166-
sys_trace_unwind(
166+
sys_trace_func3(
167167
_PyLegacyEventHandler *self, PyObject *const *args,
168168
size_t nargsf, PyObject *kwnames
169169
) {
@@ -446,7 +446,7 @@ _PyEval_SetTrace(PyThreadState *tstate, Py_tracefunc func, PyObject *arg)
446446
return -1;
447447
}
448448
if (set_callbacks(PY_MONITORING_SYS_TRACE_ID,
449-
(vectorcallfunc)sys_trace_func2, PyTrace_CALL,
449+
(vectorcallfunc)sys_trace_func3, PyTrace_CALL,
450450
PY_MONITORING_EVENT_PY_THROW, -1)) {
451451
return -1;
452452
}
@@ -471,7 +471,7 @@ _PyEval_SetTrace(PyThreadState *tstate, Py_tracefunc func, PyObject *arg)
471471
return -1;
472472
}
473473
if (set_callbacks(PY_MONITORING_SYS_TRACE_ID,
474-
(vectorcallfunc)sys_trace_unwind, PyTrace_RETURN,
474+
(vectorcallfunc)sys_trace_func3, PyTrace_RETURN,
475475
PY_MONITORING_EVENT_PY_UNWIND, -1)) {
476476
return -1;
477477
}

0 commit comments

Comments
 (0)
0