mirror of
https://github.com/python/cpython.git
synced 2025-08-27 04:05:34 +00:00
bpo-42500: Fix recursion in or after except (GH-23568) (#24501)
* Use counter, rather boolean state when handling soft overflows.
(cherry picked from commit 4e7a69bdb6
)
This commit is contained in:
parent
f836e5f219
commit
8b795ab554
9 changed files with 76 additions and 75 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue