10000 [3.12] gh-116626: Emit `CALL` events for all `INSTRUMENTED_CALL_FUNCT… · python/cpython@56a3c5f · GitHub
[go: up one dir, main page]

Skip to content

Commit 56a3c5f

Browse files
[3.12] gh-116626: Emit CALL events for all `INSTRUMENTED_CALL_FUNCTION_EX (GH-116732)
Backport of GH-116627
1 parent fc4d5fd commit 56a3c5f

File tree

4 files changed

+44
-28
lines changed

4 files changed

+44
-28
lines changed

Lib/test/test_monitoring.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,3 +1743,18 @@ def test_gh108976(self):
17431743
sys.monitoring.register_callback(0, E.INSTRUCTION, lambda *args: 0)
17441744
sys.monitoring.set_events(0, E.LINE | E.INSTRUCTION)
17451745
sys.monitoring.set_events(0, 0)
1746+
1747+
def test_call_function_ex(self):
1748+
def f(a, b):
1749+
return a + b
1750+
args = (1, 2)
1751+
1752+
call_data = []
1753+
sys.monitoring.use_tool_id(0, "test")
1754+
self.addCleanup(sys.monitoring.free_tool_id, 0)
1755+
sys.monitoring.set_events(0, 0)
1756+
sys.monitoring.register_callback(0, E.CALL, lambda code, offset, callable, arg0: call_data.append((callable, arg0)))
1757+
sys.monitoring.set_events(0, E.CALL)
1758+
f(*args)
1759+
sys.monitoring.set_events(0, 0)
1760+
self.assertEqual(call_data[0], (f, 1))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ensure ``INSTRUMENTED_CALL_FUNCTION_EX`` always emits :monitoring-event:`CALL`

Python/bytecodes.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3207,27 +3207,27 @@ dummy_func(
32073207
}
32083208
assert(PyTuple_CheckExact(callargs));
32093209
EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_FUNCTION_EX, func);
3210-
if (opcode == INSTRUMENTED_CALL_FUNCTION_EX &&
3211-
!PyFunction_Check(func) && !PyMethod_Check(func)
3212-
) {
3210+
if (opcode == INSTRUMENTED_CALL_FUNCTION_EX) {
32133211
PyObject *arg = PyTuple_GET_SIZE(callargs) > 0 ?
32143212
PyTuple_GET_ITEM(callargs, 0) : Py_None;
32153213
int err = _Py_call_instrumentation_2args(
32163214
tstate, PY_MONITORING_EVENT_CALL,
32173215
frame, next_instr-1, func, arg);
32183216
if (err) goto error;
32193217
result = PyObject_Call(func, callargs, kwargs);
3220-
if (result == NULL) {
3221-
_Py_call_instrumentation_exc2(
3222-
tstate, PY_MONITORING_EVENT_C_RAISE,
3223-
frame, next_instr-1, func, arg);
3224-
}
3225-
else {
3226-
int err = _Py_call_instrumentation_2args(
3227-
tstate, PY_MONITORING_EVENT_C_RETURN,
3228-
frame, next_instr-1, func, arg);
3229-
if (err < 0) {
3230-
Py_CLEAR(result);
3218+
if (!PyFunction_Check(func) && !PyMethod_Check(func)) {
3219+
if (result == NULL) {
3220+
_Py_call_instrumentation_exc2(
3221+
tstate, PY_MONITORING_EVENT_C_RAISE,
3222+
frame, next_instr-1, func, arg);
3223+
}
3224+
else {
3225+
int err = _Py_call_instrumentation_2args(
3226+
tstate, PY_MONITORING_EVENT_C_RETURN,
3227+
frame, next_instr-1, func, arg);
3228+
if (err < 0) {
3229+
Py_CLEAR(result);
3230+
}
32313231
}
32323232
}
32333233
}

Python/generated_cases.c.h

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0