diff options
author | Mark Shannon <mark@hotpy.org> | 2022-10-05 00:34:03 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-05 00:34:03 (GMT) |
commit | 76449350b3467b85bcb565f9e2bf945bd150a66e (patch) | |
tree | e4237841cdb9d9984e3249823a8518c79470d73f /Python/ast_opt.c | |
parent | 0ff8fd65838f9f9ed90d7a055d26a2ce9fc0ce85 (diff) | |
download | cpython-76449350b3467b85bcb565f9e2bf945bd150a66e.zip cpython-76449350b3467b85bcb565f9e2bf945bd150a66e.tar.gz cpython-76449350b3467b85bcb565f9e2bf945bd150a66e.tar.bz2 |
GH-91079: Decouple C stack overflow checks from Python recursion checks. (GH-96510)
Diffstat (limited to 'Python/ast_opt.c')
-rw-r--r-- | Python/ast_opt.c | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/Python/ast_opt.c b/Python/ast_opt.c index b1d807b..426c534 100644 --- a/Python/ast_opt.c +++ b/Python/ast_opt.c @@ -1080,7 +1080,6 @@ int _PyAST_Optimize(mod_ty mod, PyArena *arena, _PyASTOptimizeState *state) { PyThreadState *tstate; - int recursion_limit = Py_GetRecursionLimit(); int starting_recursion_depth; /* Setup recursion depth check counters */ @@ -1089,12 +1088,10 @@ _PyAST_Optimize(mod_ty mod, PyArena *arena, _PyASTOptimizeState *state) return 0; } /* Be careful here to prevent overflow. */ - int recursion_depth = tstate->recursion_limit - tstate->recursion_remaining; - starting_recursion_depth = (recursion_depth < INT_MAX / COMPILER_STACK_FRAME_SCALE) ? - recursion_depth * COMPILER_STACK_FRAME_SCALE : recursion_depth; + int recursion_depth = C_RECURSION_LIMIT - tstate->c_recursion_remaining; + starting_recursion_depth = recursion_depth * COMPILER_STACK_FRAME_SCALE; state->recursion_depth = starting_recursion_depth; - state->recursion_limit = (recursion_limit < INT_MAX / COMPILER_STACK_FRAME_SCALE) ? - recursion_limit * COMPILER_STACK_FRAME_SCALE : recursion_limit; + state->recursion_limit = C_RECURSION_LIMIT * COMPILER_STACK_FRAME_SCALE; int ret = astfold_mod(mod, arena, state); assert(ret || PyErr_Occurred()); |