mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
gh-116626: Emit CALL
events for all INSTRUMENTED_CALL_FUNCTION_EX
(GH-116627)
This commit is contained in:
parent
ba82a241ac
commit
8332e85b2f
4 changed files with 45 additions and 28 deletions
|
@ -1807,6 +1807,21 @@ class TestRegressions(MonitoringTestBase, unittest.TestCase):
|
||||||
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))
|
||||||
|
|
||||||
|
|
||||||
class TestOptimizer(MonitoringTestBase, unittest.TestCase):
|
class TestOptimizer(MonitoringTestBase, unittest.TestCase):
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Ensure ``INSTRUMENTED_CALL_FUNCTION_EX`` always emits :monitoring-event:`CALL`
|
|
@ -3729,9 +3729,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(
|
||||||
|
@ -3739,17 +3737,20 @@ dummy_func(
|
||||||
frame, this_instr, func, arg);
|
frame, this_instr, func, arg);
|
||||||
if (err) GOTO_ERROR(error);
|
if (err) GOTO_ERROR(error);
|
||||||
result = PyObject_Call(func, callargs, kwargs);
|
result = PyObject_Call(func, callargs, kwargs);
|
||||||
if (result == NULL) {
|
|
||||||
_Py_call_instrumentation_exc2(
|
if (!PyFunction_Check(func) && !PyMethod_Check(func)) {
|
||||||
tstate, PY_MONITORING_EVENT_C_RAISE,
|
if (result == NULL) {
|
||||||
frame, this_instr, func, arg);
|
_Py_call_instrumentation_exc2(
|
||||||
}
|
tstate, PY_MONITORING_EVENT_C_RAISE,
|
||||||
else {
|
frame, this_instr, func, arg);
|
||||||
int err = _Py_call_instrumentation_2args(
|
}
|
||||||
tstate, PY_MONITORING_EVENT_C_RETURN,
|
else {
|
||||||
frame, this_instr, func, arg);
|
int err = _Py_call_instrumentation_2args(
|
||||||
if (err < 0) {
|
tstate, PY_MONITORING_EVENT_C_RETURN,
|
||||||
Py_CLEAR(result);
|
frame, this_instr, func, arg);
|
||||||
|
if (err < 0) {
|
||||||
|
Py_CLEAR(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
28
Python/generated_cases.c.h
generated
28
Python/generated_cases.c.h
generated
|
@ -1205,9 +1205,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(
|
||||||
|
@ -1215,17 +1213,19 @@
|
||||||
frame, this_instr, func, arg);
|
frame, this_instr, func, arg);
|
||||||
if (err) GOTO_ERROR(error);
|
if (err) GOTO_ERROR(error);
|
||||||
result = PyObject_Call(func, callargs, kwargs);
|
result = PyObject_Call(func, callargs, kwargs);
|
||||||
if (result == NULL) {
|
if (!PyFunction_Check(func) && !PyMethod_Check(func)) {
|
||||||
_Py_call_instrumentation_exc2(
|
if (result == NULL) {
|
||||||
tstate, PY_MONITORING_EVENT_C_RAISE,
|
_Py_call_instrumentation_exc2(
|
||||||
frame, this_instr, func, arg);
|
tstate, PY_MONITORING_EVENT_C_RAISE,
|
||||||
}
|
frame, this_instr, func, arg);
|
||||||
else {
|
}
|
||||||
int err = _Py_call_instrumentation_2args(
|
else {
|
||||||
tstate, PY_MONITORING_EVENT_C_RETURN,
|
int err = _Py_call_instrumentation_2args(
|
||||||
frame, this_instr, func, arg);
|
tstate, PY_MONITORING_EVENT_C_RETURN,
|
||||||
if (err < 0) {
|
frame, this_instr, func, arg);
|
||||||
Py_CLEAR(result);
|
if (err < 0) {
|
||||||
|
Py_CLEAR(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue