summaryrefslogtreecommitdiffstats
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2020-12-02 13:30:55 (GMT)
committerGitHub <noreply@github.com>2020-12-02 13:30:55 (GMT)
commit4e7a69bdb63a104587759d7784124492dcdd496e (patch)
tree5477c7077970d9100d089286b75ce2ff408ac613 /Python/ceval.c
parent93a0ef76473683aa3ad215e11df18f7839488c4e (diff)
downloadcpython-4e7a69bdb63a104587759d7784124492dcdd496e.zip
cpython-4e7a69bdb63a104587759d7784124492dcdd496e.tar.gz
cpython-4e7a69bdb63a104587759d7784124492dcdd496e.tar.bz2
bpo-42500: Fix recursion in or after except (GH-23568)
* Use counter, rather boolean state when handling soft overflows.
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 693852e..9de9257 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -857,20 +857,22 @@ _Py_CheckRecursiveCall(PyThreadState *tstate, const char *where)
return -1;
}
#endif
- if (tstate->overflowed) {
+ if (tstate->recursion_headroom) {
if (tstate->recursion_depth > recursion_limit + 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->recursion_headroom++;
+ _PyErr_Format(tstate, PyExc_RecursionError,
+ "maximum recursion depth exceeded%s",
+ where);
+ tstate->recursion_headroom--;
+ --tstate->recursion_depth;
+ return -1;
+ }
}
return 0;
}