[3.12] gh-116626: Emit CALL events for all `INSTRUMENTED_CALL_FUNCTION_EX (GH-116732)

Backport of GH-116627
This commit is contained in:
Tian Gao 2024-03-14 09:23:15 -07:00 committed by GitHub
parent fc4d5fdffe
commit 56a3c5f767
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 44 additions and 28 deletions

View file

@ -1743,3 +1743,18 @@ class TestRegressions(MonitoringTestBase, unittest.TestCase):
sys.monitoring.register_callback(0, E.INSTRUCTION, lambda *args: 0) sys.monitoring.register_callback(0, E.INSTRUCTION, lambda *args: 0)
sys.monitoring.set_events(0, E.LINE | E.INSTRUCTION) sys.monitoring.set_events(0, E.LINE | E.INSTRUCTION)
sys.monitoring.set_events(0, 0) sys.monitoring.set_events(0, 0)
def test_call_function_ex(self):
def f(a, b):
return a + b
args = (1, 2)
call_data = []
sys.monitoring.use_tool_id(0, "test")
self.addCleanup(sys.monitoring.free_tool_id, 0)
sys.monitoring.set_events(0, 0)
sys.monitoring.register_callback(0, E.CALL, lambda code, offset, callable, arg0: call_data.append((callable, arg0)))
sys.monitoring.set_events(0, E.CALL)
f(*args)
sys.monitoring.set_events(0, 0)
self.assertEqual(call_data[0], (f, 1))

View file

@ -0,0 +1 @@
Ensure ``INSTRUMENTED_CALL_FUNCTION_EX`` always emits :monitoring-event:`CALL`

View file

@ -3207,9 +3207,7 @@ dummy_func(
} }
assert(PyTuple_CheckExact(callargs)); assert(PyTuple_CheckExact(callargs));
EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_FUNCTION_EX, func); EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_FUNCTION_EX, func);
if (opcode == INSTRUMENTED_CALL_FUNCTION_EX && if (opcode == INSTRUMENTED_CALL_FUNCTION_EX) {
!PyFunction_Check(func) && !PyMethod_Check(func)
) {
PyObject *arg = PyTuple_GET_SIZE(callargs) > 0 ? PyObject *arg = PyTuple_GET_SIZE(callargs) > 0 ?
PyTuple_GET_ITEM(callargs, 0) : Py_None; PyTuple_GET_ITEM(callargs, 0) : Py_None;
int err = _Py_call_instrumentation_2args( int err = _Py_call_instrumentation_2args(
@ -3217,6 +3215,7 @@ dummy_func(
frame, next_instr-1, func, arg); frame, next_instr-1, func, arg);
if (err) goto error; if (err) goto error;
result = PyObject_Call(func, callargs, kwargs); result = PyObject_Call(func, callargs, kwargs);
if (!PyFunction_Check(func) && !PyMethod_Check(func)) {
if (result == NULL) { if (result == NULL) {
_Py_call_instrumentation_exc2( _Py_call_instrumentation_exc2(
tstate, PY_MONITORING_EVENT_C_RAISE, tstate, PY_MONITORING_EVENT_C_RAISE,
@ -3231,6 +3230,7 @@ dummy_func(
} }
} }
} }
}
else { else {
if (Py_TYPE(func) == &PyFunction_Type && if (Py_TYPE(func) == &PyFunction_Type &&
tstate->interp->eval_frame == NULL && tstate->interp->eval_frame == NULL &&

View file

@ -4433,9 +4433,7 @@
} }
assert(PyTuple_CheckExact(callargs)); assert(PyTuple_CheckExact(callargs));
EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_FUNCTION_EX, func); EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_FUNCTION_EX, func);
if (opcode == INSTRUMENTED_CALL_FUNCTION_EX && if (opcode == INSTRUMENTED_CALL_FUNCTION_EX) {
!PyFunction_Check(func) && !PyMethod_Check(func)
) {
PyObject *arg = PyTuple_GET_SIZE(callargs) > 0 ? PyObject *arg = PyTuple_GET_SIZE(callargs) > 0 ?
PyTuple_GET_ITEM(callargs, 0) : Py_None; PyTuple_GET_ITEM(callargs, 0) : Py_None;
int err = _Py_call_instrumentation_2args( int err = _Py_call_instrumentation_2args(
@ -4443,6 +4441,7 @@
frame, next_instr-1, func, arg); frame, next_instr-1, func, arg);
if (err) goto error; if (err) goto error;
result = PyObject_Call(func, callargs, kwargs); result = PyObject_Call(func, callargs, kwargs);
if (!PyFunction_Check(func) && !PyMethod_Check(func)) {
if (result == NULL) { if (result == NULL) {
_Py_call_instrumentation_exc2( _Py_call_instrumentation_exc2(
tstate, PY_MONITORING_EVENT_C_RAISE, tstate, PY_MONITORING_EVENT_C_RAISE,
@ -4457,6 +4456,7 @@
} }
} }
} }
}
else { else {
if (Py_TYPE(func) == &PyFunction_Type && if (Py_TYPE(func) == &PyFunction_Type &&
tstate->interp->eval_frame == NULL && tstate->interp->eval_frame == NULL &&