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) --- Python/Python-ast.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index f485af675c..2571e28bc1 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -12315,7 +12315,6 @@ PyObject* PyAST_mod2obj(mod_ty t) return NULL; } - int recursion_limit = Py_GetRecursionLimit(); int starting_recursion_depth; /* Be careful here to prevent overflow. */ int COMPILER_STACK_FRAME_SCALE = 3; @@ -12323,11 +12322,9 @@ PyObject* PyAST_mod2obj(mod_ty t) if (!tstate) { return 0; } - state->recursion_limit = (recursion_limit < INT_MAX / COMPILER_STACK_FRAME_SCALE) ? - recursion_limit * COMPILER_STACK_FRAME_SCALE : recursion_limit; - 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_limit = C_RECURSION_LIMIT * COMPILER_STACK_FRAME_SCALE; + 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; PyObject *result = ast2obj_mod(state, t); -- cgit v1.2.1