]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-116735: Use `MISSING` for `CALL` event if argument is absen… (#116873)
authorTian Gao <gaogaotiantian@hotmail.com>
Tue, 19 Mar 2024 17:00:54 +0000 (10:00 -0700)
committerGitHub <noreply@github.com>
Tue, 19 Mar 2024 17:00:54 +0000 (17:00 +0000)
[3.12] gh-116735: Use `MISSING` for `CALL` event if argument is absent (GH-116737)

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 383bb65a4cec08564bcd9d1b6bc21464b5947895..d5d271fe548528f5d105bd7c073cc4e4de4c1c7c 100644 (file)
@@ -1745,9 +1745,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")
@@ -1756,5 +1757,7 @@ 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))
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 ed8f671f63af1b22d474eae2fb2d4fdfa2d0457c..1c25486c3d4c5f680267e9f8564a198d67b4694f 100644 (file)
@@ -3209,7 +3209,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, next_instr-1, func, arg);
index bb75e9a5ba7ba1add2255378ed20e954229f8359..d5e3ce28ce264bd02e1b3312fe22978196202b52 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, next_instr-1, func, arg);