]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-117180: Complete call sequence when trace stack overflow (GH-117184)
authorKen Jin <kenjin@python.org>
Sat, 23 Mar 2024 22:19:17 +0000 (06:19 +0800)
committerGitHub <noreply@github.com>
Sat, 23 Mar 2024 22:19:17 +0000 (06:19 +0800)
---------

Co-authored-by: Peter Lazorchak <lazorchakp@gmail.com>
Co-authored-by: Guido van Rossum <gvanrossum@users.noreply.github.com>
Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
Lib/test/test_capi/test_opt.py
Python/optimizer.c

index b0859a382de52318df421ca3f98e86412f3684a1..a1dc03dd3b651bbde91ebcd2e6a8e6bffb47ec5f 100644 (file)
@@ -955,6 +955,32 @@ class TestUopsOptimization(unittest.TestCase):
         _, ex = self._run_with_optimizer(testfunc, 16)
         self.assertIsNone(ex)
 
+    def test_many_nested(self):
+        # overflow the trace_stack
+        def dummy_a(x):
+            return x
+        def dummy_b(x):
+            return dummy_a(x)
+        def dummy_c(x):
+            return dummy_b(x)
+        def dummy_d(x):
+            return dummy_c(x)
+        def dummy_e(x):
+            return dummy_d(x)
+        def dummy_f(x):
+            return dummy_e(x)
+        def dummy_g(x):
+            return dummy_f(x)
+        def dummy_h(x):
+            return dummy_g(x)
+        def testfunc(n):
+            a = 0
+            for _ in range(n):
+                a += dummy_h(n)
+            return a
+
+        self._run_with_optimizer(testfunc, 32)
+
 
 if __name__ == "__main__":
     unittest.main()
index 177ad343618c372a4f1086a5e34bfe353b0b97d4..f8c1390a061650fcbe5f3d94cce38adde0f74172 100644 (file)
@@ -476,6 +476,7 @@ BRANCH_TO_GUARD[4][2] = {
     if (trace_stack_depth >= TRACE_STACK_SIZE) { \
         DPRINTF(2, "Trace stack overflow\n"); \
         OPT_STAT_INC(trace_stack_overflow); \
+        ADD_TO_TRACE(uop, oparg, operand, target); \
         ADD_TO_TRACE(_EXIT_TRACE, 0, 0, 0); \
         goto done; \
     } \