summaryrefslogtreecommitdiffstats
path: root/Python/symtable.c
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2021-11-16 11:01:57 (GMT)
committerGitHub <noreply@github.com>2021-11-16 11:01:57 (GMT)
commitb9310773756f40f77e075f221a90dd41e6964efc (patch)
tree43674ba9f42f2ff81dfd3025956b0ce8e12251f9 /Python/symtable.c
parent9bf2cbc4c498812e14f20d86acb61c53928a5a57 (diff)
downloadcpython-b9310773756f40f77e075f221a90dd41e6964efc.zip
cpython-b9310773756f40f77e075f221a90dd41e6964efc.tar.gz
cpython-b9310773756f40f77e075f221a90dd41e6964efc.tar.bz2
bpo-45753: Make recursion checks more efficient. (GH-29524)
* Uses recursion remaining, instead of recursion depth to speed up check against recursion limit.
Diffstat (limited to 'Python/symtable.c')
-rw-r--r--Python/symtable.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/Python/symtable.c b/Python/symtable.c
index 64c1635..dc5426c 100644
--- a/Python/symtable.c
+++ b/Python/symtable.c
@@ -298,8 +298,9 @@ _PySymtable_Build(mod_ty mod, PyObject *filename, PyFutureFeatures *future)
return NULL;
}
/* 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;
st->recursion_depth = starting_recursion_depth;
st->recursion_limit = (recursion_limit < INT_MAX / COMPILER_STACK_FRAME_SCALE) ?
recursion_limit * COMPILER_STACK_FRAME_SCALE : recursion_limit;