Skip to content

Commit

Permalink
Reduce C recursion depth on WASI.
Browse files Browse the repository at this point in the history
  • Loading branch information
markshannon committed Sep 5, 2022
1 parent e8a1bed commit 7e21a74
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
11 changes: 10 additions & 1 deletion Include/cpython/pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,16 @@ struct _ts {
_PyCFrame root_cframe;
};

#define C_RECURSION_LIMIT 800
/* 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 Py_DEFAULT_RECURSION_LIMIT
# ifdef __wasi__
# define C_RECURSION_LIMIT 500
# else
# define C_RECURSION_LIMIT 800
# endif
#endif

/* other API */

Expand Down
11 changes: 1 addition & 10 deletions Include/internal/pycore_ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,7 @@ extern "C" {
struct pyruntimestate;
struct _ceval_runtime_state;

/* WASI has limited call stack. Python's recursion limit depends on code
layout, optimization, and WASI runtime. Wasmtime can handle about 700-750
recursions, sometimes less. 600 is a more conservative limit. */
#ifndef Py_DEFAULT_RECURSION_LIMIT
# ifdef __wasi__
# define Py_DEFAULT_RECURSION_LIMIT 600
# else
# define Py_DEFAULT_RECURSION_LIMIT 1000
# endif
#endif
#define Py_DEFAULT_RECURSION_LIMIT 1000

#include "pycore_interp.h" // PyInterpreterState.eval_frame
#include "pycore_pystate.h" // _PyThreadState_GET()
Expand Down

0 comments on commit 7e21a74

Please sign in to comment.