https://github.com/python/cpython/commit/59e30f41ed6f2388a99ac0a8aebf0a12f7460a4a
commit: 59e30f41ed6f2388a99ac0a8aebf0a12f7460a4a
branch: main
author: Tian Gao <[email protected]>
committer: markshannon <[email protected]>
date: 2024-03-15T14:46:18Z
summary:

gh-116735: Use `MISSING` for `CALL` event if argument is absent (GH-116737)

files:
A Misc/NEWS.d/next/Core and 
Builtins/2024-03-13-16-55-25.gh-issue-116735.o3w6y8.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 11fb2d87f6c995..58441ef8b82fd0 100644
--- a/Lib/test/test_monitoring.py
+++ b/Lib/test/test_monitoring.py
@@ -1808,9 +1808,10 @@ def test_gh108976(self):
         sys.monitoring.set_events(0, 0)
 
     def test_call_function_ex(self):
-        def f(a, b):
+        def f(a=1, b=2):
             return a + b
         args = (1, 2)
+        empty_args = []
 
         call_data = []
         sys.monitoring.use_tool_id(0, "test")
@@ -1819,8 +1820,10 @@ def f(a, b):
         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)
+        f(*empty_args)
         sys.monitoring.set_events(0, 0)
         self.assertEqual(call_data[0], (f, 1))
+        self.assertEqual(call_data[1], (f, sys.monitoring.MISSING))
 
 
 class TestOptimizer(MonitoringTestBase, unittest.TestCase):
diff --git a/Misc/NEWS.d/next/Core and 
Builtins/2024-03-13-16-55-25.gh-issue-116735.o3w6y8.rst b/Misc/NEWS.d/next/Core 
and Builtins/2024-03-13-16-55-25.gh-issue-116735.o3w6y8.rst
new file mode 100644
index 00000000000000..ca15d484e345db
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and 
Builtins/2024-03-13-16-55-25.gh-issue-116735.o3w6y8.rst 
@@ -0,0 +1 @@
+For ``INSTRUMENTED_CALL_FUNCTION_EX``, set ``arg0`` to 
``sys.monitoring.MISSING`` instead of ``None`` for :monitoring-event:`CALL` 
event.
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index bf7782a65bc5ce..fb66ae583130db 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -3774,7 +3774,7 @@ dummy_func(
             EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_FUNCTION_EX, func);
             if (opcode == INSTRUMENTED_CALL_FUNCTION_EX) {
                 PyObject *arg = PyTuple_GET_SIZE(callargs) > 0 ?
-                    PyTuple_GET_ITEM(callargs, 0) : Py_None;
+                    PyTuple_GET_ITEM(callargs, 0) : 
&_PyInstrumentation_MISSING;
                 int err = _Py_call_instrumentation_2args(
                     tstate, PY_MONITORING_EVENT_CALL,
                     frame, this_instr, func, arg);
diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h
index 2fbd9ed403f5d1..82d7b7621f8b25 100644
--- a/Python/generated_cases.c.h
+++ b/Python/generated_cases.c.h
@@ -1227,7 +1227,7 @@
             EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_FUNCTION_EX, func);
             if (opcode == INSTRUMENTED_CALL_FUNCTION_EX) {
                 PyObject *arg = PyTuple_GET_SIZE(callargs) > 0 ?
-                PyTuple_GET_ITEM(callargs, 0) : Py_None;
+                PyTuple_GET_ITEM(callargs, 0) : &_PyInstrumentation_MISSING;
                 int err = _Py_call_instrumentation_2args(
                     tstate, PY_MONITORING_EVENT_CALL,
                     frame, this_instr, func, arg);

_______________________________________________
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]

Reply via email to