@@ -112,7 +112,8 @@ struct _ts {
112112 int py_recursion_remaining ;
113113 int py_recursion_limit ;
114114
115- int c_recursion_remaining ;
115+ char * c_stack_soft_limit ;
116+ char * c_stack_hard_limit ;
116117 int recursion_headroom ; /* Allow 50 more calls to handle any errors. */
117118
118119 /* 'tracing' keeps track of the execution depth when tracing/profiling.
@@ -202,34 +203,45 @@ struct _ts {
202203 PyObject * threading_local_sentinel ;
203204};
204205
205- #ifdef Py_DEBUG
206- // A debug build is likely built with low optimization level which implies
207- // higher stack memory usage than a release build: use a lower limit.
208- # define Py_C_RECURSION_LIMIT 500
209- #elif defined(__s390x__ )
210- # define Py_C_RECURSION_LIMIT 800
206+
207+ #if defined(__s390x__ )
208+ # define Py_C_STACK_SIZE 320000
211209#elif defined(_WIN32 ) && defined(_M_ARM64 )
212- # define Py_C_RECURSION_LIMIT 1000
210+ # define Py_C_STACK_SIZE 400000
213211#elif defined(_WIN32 )
214- # define Py_C_RECURSION_LIMIT 3000
212+ # define Py_C_STACK_SIZE 1200000
215213#elif defined(__ANDROID__ )
216214 // On an ARM64 emulator, API level 34 was OK with 10000, but API level 21
217215 // crashed in test_compiler_recursion_limit.
218- # define Py_C_RECURSION_LIMIT 3000
219- #elif defined(_Py_ADDRESS_SANITIZER )
220- # define Py_C_RECURSION_LIMIT 4000
216+ # define Py_C_STACK_SIZE 1200000
221217#elif defined(__sparc__ )
222218 // test_descr crashed on sparc64 with >7000 but let's keep a margin of error.
223- # define Py_C_RECURSION_LIMIT 4000
219+ # define Py_C_STACK_SIZE 1600000
224220#elif defined(__wasi__ )
225221 // Based on wasmtime 16.
226- # define Py_C_RECURSION_LIMIT 5000
222+ # define Py_C_STACK_SIZE 2000000
227223#elif defined(__hppa__ ) || defined(__powerpc64__ )
228224 // test_descr crashed with >8000 but let's keep a margin of error.
229- # define Py_C_RECURSION_LIMIT 5000
225+ # define Py_C_STACK_SIZE 2000000
230226#else
231227 // This value is duplicated in Lib/test/support/__init__.py
232- # define Py_C_RECURSION_LIMIT 10000
228+ # define Py_C_STACK_SIZE 5000000
229+ #endif
230+
231+
232+ #ifdef Py_DEBUG
233+ // A debug build is likely built with low optimization level which implies
234+ // higher stack memory usage than a release build: use a lower limit.
235+ # if defined(__has_feature ) /* Clang */
236+ // Clang debug builds use a lot of stack space
237+ # define Py_C_RECURSION_LIMIT (Py_C_STACK_SIZE / 2000)
238+ # else
239+ # define Py_C_RECURSION_LIMIT (Py_C_STACK_SIZE / 1000)
240+ # endif
241+ #elif defined(_Py_ADDRESS_SANITIZER )
242+ # define Py_C_STACK_SIZE (Py_C_STACK_SIZE / 600)
243+ #else
244+ # define Py_C_RECURSION_LIMIT (Py_C_STACK_SIZE / 300)
233245#endif
234246
235247
0 commit comments