Skip to content

Commit f59f90b

Browse files
authored
GH-114456: lower the recursion limit under WASI for debug builds (GH-114457)
Testing under wasmtime 16.0.0 w/ code from #114413 is how the value was found.
1 parent afe8f37 commit f59f90b

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

Include/cpython/pystate.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,14 @@ struct _ts {
217217
#ifdef Py_DEBUG
218218
// A debug build is likely built with low optimization level which implies
219219
// higher stack memory usage than a release build: use a lower limit.
220-
# define Py_C_RECURSION_LIMIT 500
220+
# if defined(__wasi__)
221+
// Based on wasmtime 16.
222+
# define Py_C_RECURSION_LIMIT 150
223+
# else
224+
# define Py_C_RECURSION_LIMIT 500
225+
# endif
221226
#elif defined(__wasi__)
222-
// WASI has limited call stack. Python's recursion limit depends on code
223-
// layout, optimization, and WASI runtime. Wasmtime can handle about 700
224-
// recursions, sometimes less. 500 is a more conservative limit.
227+
// Based on wasmtime 16.
225228
# define Py_C_RECURSION_LIMIT 500
226229
#elif defined(__s390x__)
227230
# define Py_C_RECURSION_LIMIT 800

Lib/test/test_dynamic.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import sys
55
import unittest
66

7-
from test.support import swap_item, swap_attr
7+
from test.support import is_wasi, Py_DEBUG, swap_item, swap_attr
88

99

1010
class RebindBuiltinsTests(unittest.TestCase):
@@ -134,6 +134,7 @@ def test_eval_gives_lambda_custom_globals(self):
134134

135135
self.assertEqual(foo(), 7)
136136

137+
@unittest.skipIf(is_wasi and Py_DEBUG, "stack depth too shallow in pydebug WASI")
137138
def test_load_global_specialization_failure_keeps_oparg(self):
138139
# https://github.com/python/cpython/issues/91625
139140
class MyGlobals(dict):

Lib/test/test_pickle.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,9 @@ def recurse(deep):
402402
check_unpickler(recurse(1), 32, 20)
403403
check_unpickler(recurse(20), 32, 20)
404404
check_unpickler(recurse(50), 64, 60)
405-
check_unpickler(recurse(100), 128, 140)
405+
if not (support.is_wasi and support.Py_DEBUG):
406+
# stack depth too shallow in pydebug WASI.
407+
check_unpickler(recurse(100), 128, 140)
406408

407409
u = unpickler(io.BytesIO(pickle.dumps('a', 0)),
408410
encoding='ASCII', errors='strict')
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lower the recursion limit under a debug build of WASI.

0 commit comments

Comments
 (0)