Skip to content

Commit 7e21a74

Browse files
committed
Reduce C recursion depth on WASI.
1 parent e8a1bed commit 7e21a74

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

Include/cpython/pystate.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,16 @@ struct _ts {
204204
_PyCFrame root_cframe;
205205
};
206206

207-
#define C_RECURSION_LIMIT 800
207+
/* WASI has limited call stack. Python's recursion limit depends on code
208+
layout, optimization, and WASI runtime. Wasmtime can handle about 700
209+
recursions, sometimes less. 500 is a more conservative limit. */
210+
#ifndef Py_DEFAULT_RECURSION_LIMIT
211+
# ifdef __wasi__
212+
# define C_RECURSION_LIMIT 500
213+
# else
214+
# define C_RECURSION_LIMIT 800
215+
# endif
216+
#endif
208217

209218
/* other API */
210219

Include/internal/pycore_ceval.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,7 @@ extern "C" {
1212
struct pyruntimestate;
1313
struct _ceval_runtime_state;
1414

15-
/* WASI has limited call stack. Python's recursion limit depends on code
16-
layout, optimization, and WASI runtime. Wasmtime can handle about 700-750
17-
recursions, sometimes less. 600 is a more conservative limit. */
18-
#ifndef Py_DEFAULT_RECURSION_LIMIT
19-
# ifdef __wasi__
20-
# define Py_DEFAULT_RECURSION_LIMIT 600
21-
# else
22-
# define Py_DEFAULT_RECURSION_LIMIT 1000
23-
# endif
24-
#endif
15+
#define Py_DEFAULT_RECURSION_LIMIT 1000
2516

2617
#include "pycore_interp.h" // PyInterpreterState.eval_frame
2718
#include "pycore_pystate.h" // _PyThreadState_GET()

0 commit comments

Comments
 (0)