aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/ast_opt.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/ast_opt.c')
-rw-r--r--Python/ast_opt.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/Python/ast_opt.c b/Python/ast_opt.c
index f6506cef035..356f60e2d53 100644
--- a/Python/ast_opt.c
+++ b/Python/ast_opt.c
@@ -1098,8 +1098,9 @@ _PyAST_Optimize(mod_ty mod, PyArena *arena, _PyASTOptimizeState *state)
return 0;
}
/* Be careful here to prevent overflow. */
- starting_recursion_depth = (tstate->recursion_depth < INT_MAX / COMPILER_STACK_FRAME_SCALE) ?
- tstate->recursion_depth * COMPILER_STACK_FRAME_SCALE : tstate->recursion_depth;
+ 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;
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;