https://github.com/python/cpython/commit/6c83352bfe78a7d567c8d76257df6eb91d5a7245
commit: 6c83352bfe78a7d567c8d76257df6eb91d5a7245
branch: main
author: Ken Jin <[email protected]>
committer: Fidget-Spinner <[email protected]>
date: 2024-03-24T06:19:17+08:00
summary:

gh-117180: Complete call sequence when trace stack overflow (GH-117184)


---------

Co-authored-by: Peter Lazorchak <[email protected]>
Co-authored-by: Guido van Rossum <[email protected]>
Co-authored-by: Guido van Rossum <[email protected]>

files:
M Lib/test/test_capi/test_opt.py
M Python/optimizer.c

diff --git a/Lib/test/test_capi/test_opt.py b/Lib/test/test_capi/test_opt.py
index b0859a382de523..a1dc03dd3b651b 100644
--- a/Lib/test/test_capi/test_opt.py
+++ b/Lib/test/test_capi/test_opt.py
@@ -955,6 +955,32 @@ def testfunc(n):
         _, 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()
diff --git a/Python/optimizer.c b/Python/optimizer.c
index 177ad343618c37..f8c1390a061650 100644
--- a/Python/optimizer.c
+++ b/Python/optimizer.c
@@ -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; \
     } \

_______________________________________________
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