From 76449350b3467b85bcb565f9e2bf945bd150a66e Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Wed, 5 Oct 2022 01:34:03 +0100 Subject: GH-91079: Decouple C stack overflow checks from Python recursion checks. (GH-96510) --- Include/cpython/pystate.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'Include/cpython') diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h index cc3c3eae94..7722a384cb 100644 --- a/Include/cpython/pystate.h +++ b/Include/cpython/pystate.h @@ -95,8 +95,10 @@ struct _ts { /* Was this thread state statically allocated? */ int _static; - int recursion_remaining; - int recursion_limit; + int py_recursion_remaining; + int py_recursion_limit; + + int c_recursion_remaining; int recursion_headroom; /* Allow 50 more calls to handle any errors. */ /* 'tracing' keeps track of the execution depth when tracing/profiling. @@ -202,6 +204,16 @@ struct _ts { _PyCFrame root_cframe; }; +/* 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. */ +#ifndef C_RECURSION_LIMIT +# ifdef __wasi__ +# define C_RECURSION_LIMIT 500 +# else +# define C_RECURSION_LIMIT 800 +# endif +#endif /* other API */ -- cgit v1.2.1