diff options
author | Mark Shannon <mark@hotpy.org> | 2021-03-02 10:36:38 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-02 10:36:38 (GMT) |
commit | 8b795ab5541d8a4e69be4137dfdc207714270b77 (patch) | |
tree | d7fcc96f3243d082ea024964a643a32a004a5fbd /Python/ceval.c | |
parent | f836e5f2194857b24ec03adfcfcce05375868f88 (diff) | |
download | cpython-8b795ab5541d8a4e69be4137dfdc207714270b77.zip cpython-8b795ab5541d8a4e69be4137dfdc207714270b77.tar.gz cpython-8b795ab5541d8a4e69be4137dfdc207714270b77.tar.bz2 |
bpo-42500: Fix recursion in or after except (GH-23568) (#24501)
* Use counter, rather boolean state when handling soft overflows.
(cherry picked from commit 4e7a69bdb63a104587759d7784124492dcdd496e)
Diffstat (limited to 'Python/ceval.c')
-rw-r--r-- | Python/ceval.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index 91e879e..b7176dc 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -793,23 +793,22 @@ _Py_CheckRecursiveCall(PyThreadState *tstate, const char *where) _Py_CheckRecursionLimit = recursion_limit; } #endif - if (tstate->recursion_critical) - /* Somebody asked that we don't check for recursion. */ - return 0; - 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; } |