mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 07:31:38 +00:00 
			
		
		
		
	GH-114456: lower the recursion limit under WASI for debug builds (GH-114457)
Testing under wasmtime 16.0.0 w/ code from https://github.com/python/cpython/issues/114413 is how the value was found.
This commit is contained in:
		
							parent
							
								
									afe8f376c0
								
							
						
					
					
						commit
						f59f90b5bc
					
				
					 4 changed files with 13 additions and 6 deletions
				
			
		| 
						 | 
					@ -217,11 +217,14 @@ struct _ts {
 | 
				
			||||||
#ifdef Py_DEBUG
 | 
					#ifdef Py_DEBUG
 | 
				
			||||||
   // A debug build is likely built with low optimization level which implies
 | 
					   // A debug build is likely built with low optimization level which implies
 | 
				
			||||||
   // higher stack memory usage than a release build: use a lower limit.
 | 
					   // 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__)
 | 
					#elif defined(__wasi__)
 | 
				
			||||||
   // WASI has limited call stack. Python's recursion limit depends on code
 | 
					   // Based on wasmtime 16.
 | 
				
			||||||
   // layout, optimization, and WASI runtime. Wasmtime can handle about 700
 | 
					 | 
				
			||||||
   // recursions, sometimes less. 500 is a more conservative limit.
 | 
					 | 
				
			||||||
#  define Py_C_RECURSION_LIMIT 500
 | 
					#  define Py_C_RECURSION_LIMIT 500
 | 
				
			||||||
#elif defined(__s390x__)
 | 
					#elif defined(__s390x__)
 | 
				
			||||||
#  define Py_C_RECURSION_LIMIT 800
 | 
					#  define Py_C_RECURSION_LIMIT 800
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,7 +4,7 @@
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
import unittest
 | 
					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):
 | 
					class RebindBuiltinsTests(unittest.TestCase):
 | 
				
			||||||
| 
						 | 
					@ -134,6 +134,7 @@ def test_eval_gives_lambda_custom_globals(self):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.assertEqual(foo(), 7)
 | 
					        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):
 | 
					    def test_load_global_specialization_failure_keeps_oparg(self):
 | 
				
			||||||
        # https://github.com/python/cpython/issues/91625
 | 
					        # https://github.com/python/cpython/issues/91625
 | 
				
			||||||
        class MyGlobals(dict):
 | 
					        class MyGlobals(dict):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -402,7 +402,9 @@ def recurse(deep):
 | 
				
			||||||
            check_unpickler(recurse(1), 32, 20)
 | 
					            check_unpickler(recurse(1), 32, 20)
 | 
				
			||||||
            check_unpickler(recurse(20), 32, 20)
 | 
					            check_unpickler(recurse(20), 32, 20)
 | 
				
			||||||
            check_unpickler(recurse(50), 64, 60)
 | 
					            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)),
 | 
					            u = unpickler(io.BytesIO(pickle.dumps('a', 0)),
 | 
				
			||||||
                          encoding='ASCII', errors='strict')
 | 
					                          encoding='ASCII', errors='strict')
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1 @@
 | 
				
			||||||
 | 
					Lower the recursion limit under a debug build of WASI.
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue