summaryrefslogtreecommitdiffstats
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2021-11-19 18:51:50 (GMT)
committerGitHub <noreply@github.com>2021-11-19 18:51:50 (GMT)
commit4296396db017d782d3aa16100b366748c9ea4a04 (patch)
treea3b5228ac4881bfb74ea10646781bad1b9f15be7 /Python/ceval.c
parentc06c7c489a82b2db023bb947f0c4d21ad93b8308 (diff)
downloadcpython-4296396db017d782d3aa16100b366748c9ea4a04.zip
cpython-4296396db017d782d3aa16100b366748c9ea4a04.tar.gz
cpython-4296396db017d782d3aa16100b366748c9ea4a04.tar.bz2
[3.9] bpo-45806: Fix recovery from stack overflow for 3.9. Again. (GH-29640)
Co-authored-by: Ɓukasz Langa <lukasz@langa.pl>
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 86a5d81..9a61f8a 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -797,19 +797,21 @@ _Py_CheckRecursiveCall(PyThreadState *tstate, const char *where)
/* Somebody asked that we don't check for recursion. */
return 0;
if (tstate->overflowed) {
- if (tstate->recursion_depth > recursion_limit + 50) {
+ if (tstate->recursion_depth > recursion_limit + 50 || tstate->overflowed > 50) {
/* Overflowing while handling an overflow. Give up. */
Py_FatalError("Cannot recover from stack overflow.");
}
- return 0;
}
- if (tstate->recursion_depth > recursion_limit) {
- --tstate->recursion_depth;
- tstate->overflowed = 1;
- _PyErr_Format(tstate, PyExc_RecursionError,
- "maximum recursion depth exceeded%s",
- where);
- return -1;
+ else {
+ if (tstate->recursion_depth > recursion_limit) {
+ tstate->overflowed++;
+ _PyErr_Format(tstate, PyExc_RecursionError,
+ "maximum recursion depth exceeded%s",
+ where);
+ tstate->overflowed--;
+ --tstate->recursion_depth;
+ return -1;
+ }
}
return 0;
}