]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-116735: Use `MISSING` for `CALL` event if argument is absent (GH-116737)
authorTian Gao <gaogaotiantian@hotmail.com>
Fri, 15 Mar 2024 14:46:18 +0000 (07:46 -0700)
committerGitHub <noreply@github.com>
Fri, 15 Mar 2024 14:46:18 +0000 (14:46 +0000)
Lib/test/test_monitoring.py
Misc/NEWS.d/next/Core and Builtins/2024-03-13-16-55-25.gh-issue-116735.o3w6y8.rst [new file with mode: 0644]
Python/bytecodes.c
Python/generated_cases.c.h

index 11fb2d87f6c99593e2db74aea320126c749e29ba..58441ef8b82fd05be91a120146573569d9be967e 100644 (file)
@@ -1808,9 +1808,10 @@ class TestRegressions(MonitoringTestBase, unittest.TestCase):
         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 @@ class TestRegressions(MonitoringTestBase, unittest.TestCase):
         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 (file)
index 0000000..ca15d48
--- /dev/null
@@ -0,0 +1 @@
+For ``INSTRUMENTED_CALL_FUNCTION_EX``, set ``arg0`` to ``sys.monitoring.MISSING`` instead of ``None`` for :monitoring-event:`CALL` event.
index bf7782a65bc5ce6da7f0bdf7841dbb0b581f5e99..fb66ae583130db3c26816cc50beb819313d0ce7d 100644 (file)
@@ -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);
index 2fbd9ed403f5d11b5b303775c8800fcf52fcc0b2..82d7b7621f8b255adddf10653f299e2fb71fc237 100644 (file)
             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);