https://github.com/python/cpython/commit/8332e85b2f079e8b9334666084d1f8495cff25c1
commit: 8332e85b2f079e8b9334666084d1f8495cff25c1
branch: main
author: Tian Gao <[email protected]>
committer: markshannon <[email protected]>
date: 2024-03-13T08:28:01Z
summary:
gh-116626: Emit `CALL` events for all `INSTRUMENTED_CALL_FUNCTION_EX`
(GH-116627)
files:
A Misc/NEWS.d/next/Core and
Builtins/2024-03-11-22-05-56.gh-issue-116626.GsyczB.rst
M Lib/test/test_monitoring.py
M Python/bytecodes.c
M Python/generated_cases.c.h
diff --git a/Lib/test/test_monitoring.py b/Lib/test/test_monitoring.py
index 1e77eb6a2eea4c..11fb2d87f6c995 100644
--- a/Lib/test/test_monitoring.py
+++ b/Lib/test/test_monitoring.py
@@ -1807,6 +1807,21 @@ def test_gh108976(self):
sys.monitoring.set_events(0, E.LINE | E.INSTRUCTION)
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):
diff --git a/Misc/NEWS.d/next/Core and
Builtins/2024-03-11-22-05-56.gh-issue-116626.GsyczB.rst b/Misc/NEWS.d/next/Core
and Builtins/2024-03-11-22-05-56.gh-issue-116626.GsyczB.rst
new file mode 100644
index 00000000000000..5b18d04cca64b5
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and
Builtins/2024-03-11-22-05-56.gh-issue-116626.GsyczB.rst
@@ -0,0 +1 @@
+Ensure ``INSTRUMENTED_CALL_FUNCTION_EX`` always emits :monitoring-event:`CALL`
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index 03e5f4e330bdd8..ec05e40bd23fcb 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -3729,9 +3729,7 @@ dummy_func(
}
assert(PyTuple_CheckExact(callargs));
EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_FUNCTION_EX, func);
- if (opcode == INSTRUMENTED_CALL_FUNCTION_EX &&
- !PyFunction_Check(func) && !PyMethod_Check(func)
- ) {
+ if (opcode == INSTRUMENTED_CALL_FUNCTION_EX) {
PyObject *arg = PyTuple_GET_SIZE(callargs) > 0 ?
PyTuple_GET_ITEM(callargs, 0) : Py_None;
int err = _Py_call_instrumentation_2args(
@@ -3739,17 +3737,20 @@ dummy_func(
frame, this_instr, func, arg);
if (err) GOTO_ERROR(error);
result = PyObject_Call(func, callargs, kwargs);
- if (result == NULL) {
- _Py_call_instrumentation_exc2(
- tstate, PY_MONITORING_EVENT_C_RAISE,
- frame, this_instr, func, arg);
- }
- else {
- int err = _Py_call_instrumentation_2args(
- tstate, PY_MONITORING_EVENT_C_RETURN,
- frame, this_instr, func, arg);
- if (err < 0) {
- Py_CLEAR(result);
+
+ if (!PyFunction_Check(func) && !PyMethod_Check(func)) {
+ if (result == NULL) {
+ _Py_call_instrumentation_exc2(
+ tstate, PY_MONITORING_EVENT_C_RAISE,
+ frame, this_instr, func, arg);
+ }
+ else {
+ int err = _Py_call_instrumentation_2args(
+ tstate, PY_MONITORING_EVENT_C_RETURN,
+ frame, this_instr, func, arg);
+ if (err < 0) {
+ Py_CLEAR(result);
+ }
}
}
}
diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h
index 53c0211be2fe6c..72892725fb25d8 100644
--- a/Python/generated_cases.c.h
+++ b/Python/generated_cases.c.h
@@ -1205,9 +1205,7 @@
}
assert(PyTuple_CheckExact(callargs));
EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_FUNCTION_EX, func);
- if (opcode == INSTRUMENTED_CALL_FUNCTION_EX &&
- !PyFunction_Check(func) && !PyMethod_Check(func)
- ) {
+ if (opcode == INSTRUMENTED_CALL_FUNCTION_EX) {
PyObject *arg = PyTuple_GET_SIZE(callargs) > 0 ?
PyTuple_GET_ITEM(callargs, 0) : Py_None;
int err = _Py_call_instrumentation_2args(
@@ -1215,17 +1213,19 @@
frame, this_instr, func, arg);
if (err) GOTO_ERROR(error);
result = PyObject_Call(func, callargs, kwargs);
- if (result == NULL) {
- _Py_call_instrumentation_exc2(
- tstate, PY_MONITORING_EVENT_C_RAISE,
- frame, this_instr, func, arg);
- }
- else {
- int err = _Py_call_instrumentation_2args(
- tstate, PY_MONITORING_EVENT_C_RETURN,
- frame, this_instr, func, arg);
- if (err < 0) {
- Py_CLEAR(result);
+ if (!PyFunction_Check(func) && !PyMethod_Check(func)) {
+ if (result == NULL) {
+ _Py_call_instrumentation_exc2(
+ tstate, PY_MONITORING_EVENT_C_RAISE,
+ frame, this_instr, func, arg);
+ }
+ else {
+ int err = _Py_call_instrumentation_2args(
+ tstate, PY_MONITORING_EVENT_C_RETURN,
+ frame, this_instr, func, arg);
+ if (err < 0) {
+ Py_CLEAR(result);
+ }
}
}
}
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]