Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 0 additions & 4 deletions Include/internal/pycore_instruments.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@ extern int
_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);
Expand Down
33 changes: 33 additions & 0 deletions Lib/test/test_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ def check_events(self, func, expected, tool=TEST_TOOL, recorders=(ExceptionRecor

def check_balanced(self, func, recorders):
events = self.get_events(func, TEST_TOOL, recorders)
print("----\n", events, "\n------")
self.assertEqual(len(events)%2, 0)
for r, h in zip(events[::2],events[1::2]):
r0 = r[0]
Expand Down Expand Up @@ -743,6 +744,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):


Expand Down Expand Up @@ -888,6 +896,31 @@ async def async_loop():
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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -2017,7 +2017,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
Expand Down
10 changes: 0 additions & 10 deletions Python/instrumentation.c
Original file line number Diff line number Diff line change
Expand Up @@ -1081,16 +1081,6 @@ call_instrumentation_vector_protected(
assert(_PyErr_Occurred(tstate));
}

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,
Expand Down
6 changes: 3 additions & 3 deletions Python/legacy_tracing.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down