]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-118414: Fix assertion in YIELD_VALUE when tracing lines or instrs (#118683)
authorTian Gao <gaogaotiantian@hotmail.com>
Tue, 7 May 2024 04:22:59 +0000 (21:22 -0700)
committerGitHub <noreply@github.com>
Tue, 7 May 2024 04:22:59 +0000 (21:22 -0700)
Lib/test/test_monitoring.py
Misc/NEWS.d/next/Core and Builtins/2024-05-07-01-39-24.gh-issue-118414.G5GG7l.rst [new file with mode: 0644]
Python/bytecodes.c
Python/executor_cases.c.h
Python/generated_cases.c.h

index eeb3f88a081750d75e0c9117b86b6d72071bf1b0..6974bc5517ae5fb0fad9d690a02ae178b4399cd0 100644 (file)
@@ -656,6 +656,17 @@ class LineMonitoringTest(MonitoringTestBase, unittest.TestCase):
 
         self.check_lines(func2, [1,2,3,4,5,6])
 
+    def test_generator_with_line(self):
+
+        def f():
+            def a():
+                yield
+            def b():
+                yield from a()
+            next(b())
+
+        self.check_lines(f, [1,3,5,4,2,4])
+
 class TestDisable(MonitoringTestBase, unittest.TestCase):
 
     def gen(self, cond):
diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-05-07-01-39-24.gh-issue-118414.G5GG7l.rst b/Misc/NEWS.d/next/Core and Builtins/2024-05-07-01-39-24.gh-issue-118414.G5GG7l.rst
new file mode 100644 (file)
index 0000000..cd54504
--- /dev/null
@@ -0,0 +1 @@
+Add instrumented opcodes to YIELD_VALUE assertion for tracing cases.
index b2ddec98e682f273ea2b3afabc8f1d42d069daca..55eda9711dea1feb38c83586be1ae2b735317540 100644 (file)
@@ -1121,7 +1121,9 @@ dummy_func(
             /* We don't know which of these is relevant here, so keep them equal */
             assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER);
             #if TIER_ONE
-            assert(_PyOpcode_Deopt[frame->instr_ptr->op.code] == SEND ||
+            assert(frame->instr_ptr->op.code == INSTRUMENTED_LINE ||
+                   frame->instr_ptr->op.code == INSTRUMENTED_INSTRUCTION ||
+                   _PyOpcode_Deopt[frame->instr_ptr->op.code] == SEND ||
                    _PyOpcode_Deopt[frame->instr_ptr->op.code] == FOR_ITER ||
                    _PyOpcode_Deopt[frame->instr_ptr->op.code] == INTERPRETER_EXIT ||
                    _PyOpcode_Deopt[frame->instr_ptr->op.code] == ENTER_EXECUTOR);
index 5f15f67324292b6f300109d91e2be609632a9b6d..347a1e677a08325f4192ef55f90541b0fe6e87c9 100644 (file)
             /* We don't know which of these is relevant here, so keep them equal */
             assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER);
             #if TIER_ONE
-            assert(_PyOpcode_Deopt[frame->instr_ptr->op.code] == SEND ||
+            assert(frame->instr_ptr->op.code == INSTRUMENTED_LINE ||
+                   frame->instr_ptr->op.code == INSTRUMENTED_INSTRUCTION ||
+                   _PyOpcode_Deopt[frame->instr_ptr->op.code] == SEND ||
                    _PyOpcode_Deopt[frame->instr_ptr->op.code] == FOR_ITER ||
                    _PyOpcode_Deopt[frame->instr_ptr->op.code] == INTERPRETER_EXIT ||
                    _PyOpcode_Deopt[frame->instr_ptr->op.code] == ENTER_EXECUTOR);
index d3126b0c9807238aa9d0d3607c4bc1216c1c4793..8b8112209cc78a999b6d56e466e5015630259ae4 100644 (file)
             /* We don't know which of these is relevant here, so keep them equal */
             assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER);
             #if TIER_ONE
-            assert(_PyOpcode_Deopt[frame->instr_ptr->op.code] == SEND ||
+            assert(frame->instr_ptr->op.code == INSTRUMENTED_LINE ||
+                   frame->instr_ptr->op.code == INSTRUMENTED_INSTRUCTION ||
+                   _PyOpcode_Deopt[frame->instr_ptr->op.code] == SEND ||
                    _PyOpcode_Deopt[frame->instr_ptr->op.code] == FOR_ITER ||
                    _PyOpcode_Deopt[frame->instr_ptr->op.code] == INTERPRETER_EXIT ||
                    _PyOpcode_Deopt[frame->instr_ptr->op.code] == ENTER_EXECUTOR);