]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-114456: lower the recursion limit under WASI for debug builds (GH-114457)
authorBrett Cannon <brett@python.org>
Tue, 23 Jan 2024 23:48:14 +0000 (15:48 -0800)
committerGitHub <noreply@github.com>
Tue, 23 Jan 2024 23:48:14 +0000 (15:48 -0800)
Testing under wasmtime 16.0.0 w/ code from https://github.com/python/cpython/issues/114413 is how the value was found.

Include/cpython/pystate.h
Lib/test/test_dynamic.py
Lib/test/test_pickle.py
Misc/NEWS.d/next/Core and Builtins/2024-01-22-15-10-01.gh-issue-114456.fBFEJF.rst [new file with mode: 0644]

index 60b056bdcc2f1f28c93720e702d561e9d0841b2c..1dbf97660f382fdf52cba1375fb917da3e06fc3f 100644 (file)
@@ -217,11 +217,14 @@ struct _ts {
 #ifdef Py_DEBUG
    // A debug build is likely built with low optimization level which implies
    // higher stack memory usage than a release build: use a lower limit.
-#  define Py_C_RECURSION_LIMIT 500
+#  if defined(__wasi__)
+     // Based on wasmtime 16.
+#    define Py_C_RECURSION_LIMIT 150
+#  else
+#    define Py_C_RECURSION_LIMIT 500
+#  endif
 #elif defined(__wasi__)
-   // WASI has limited call stack. Python's recursion limit depends on code
-   // layout, optimization, and WASI runtime. Wasmtime can handle about 700
-   // recursions, sometimes less. 500 is a more conservative limit.
+   // Based on wasmtime 16.
 #  define Py_C_RECURSION_LIMIT 500
 #elif defined(__s390x__)
 #  define Py_C_RECURSION_LIMIT 800
index 0aa3be6a1bde6ae6b050ee1daccb49d8bd663897..3928bbab4423c22480da0ad3cf344a8420bcf186 100644 (file)
@@ -4,7 +4,7 @@ import builtins
 import sys
 import unittest
 
-from test.support import swap_item, swap_attr
+from test.support import is_wasi, Py_DEBUG, swap_item, swap_attr
 
 
 class RebindBuiltinsTests(unittest.TestCase):
@@ -134,6 +134,7 @@ class RebindBuiltinsTests(unittest.TestCase):
 
         self.assertEqual(foo(), 7)
 
+    @unittest.skipIf(is_wasi and Py_DEBUG, "stack depth too shallow in pydebug WASI")
     def test_load_global_specialization_failure_keeps_oparg(self):
         # https://github.com/python/cpython/issues/91625
         class MyGlobals(dict):
index f6405d6dd44ef6f8dd19662949663249346edd7f..b2245ddf72f7085eaad98debb876f3143fa78d9d 100644 (file)
@@ -402,7 +402,9 @@ if has_c_implementation:
             check_unpickler(recurse(1), 32, 20)
             check_unpickler(recurse(20), 32, 20)
             check_unpickler(recurse(50), 64, 60)
-            check_unpickler(recurse(100), 128, 140)
+            if not (support.is_wasi and support.Py_DEBUG):
+                # stack depth too shallow in pydebug WASI.
+                check_unpickler(recurse(100), 128, 140)
 
             u = unpickler(io.BytesIO(pickle.dumps('a', 0)),
                           encoding='ASCII', errors='strict')
diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-01-22-15-10-01.gh-issue-114456.fBFEJF.rst b/Misc/NEWS.d/next/Core and Builtins/2024-01-22-15-10-01.gh-issue-114456.fBFEJF.rst
new file mode 100644 (file)
index 0000000..2b30ad9
--- /dev/null
@@ -0,0 +1 @@
+Lower the recursion limit under a debug build of WASI.