mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
bpo-42500: Fix recursion in or after except (GH-23568)
* Use counter, rather boolean state when handling soft overflows.
This commit is contained in:
parent
93a0ef7647
commit
4e7a69bdb6
9 changed files with 76 additions and 72 deletions
|
|
@ -54,8 +54,7 @@ struct _ts {
|
|||
/* Borrowed reference to the current frame (it can be NULL) */
|
||||
PyFrameObject *frame;
|
||||
int recursion_depth;
|
||||
char overflowed; /* The stack has overflowed. Allow 50 more calls
|
||||
to handle the runtime error. */
|
||||
int recursion_headroom; /* Allow 50 more calls to handle any errors. */
|
||||
int stackcheck_counter;
|
||||
|
||||
/* 'tracing' keeps track of the execution depth when tracing/profiling.
|
||||
|
|
|
|||
|
|
@ -92,24 +92,8 @@ static inline int _Py_EnterRecursiveCall_inline(const char *where) {
|
|||
|
||||
#define Py_EnterRecursiveCall(where) _Py_EnterRecursiveCall_inline(where)
|
||||
|
||||
/* Compute the "lower-water mark" for a recursion limit. When
|
||||
* Py_LeaveRecursiveCall() is called with a recursion depth below this mark,
|
||||
* the overflowed flag is reset to 0. */
|
||||
static inline int _Py_RecursionLimitLowerWaterMark(int limit) {
|
||||
if (limit > 200) {
|
||||
return (limit - 50);
|
||||
}
|
||||
else {
|
||||
return (3 * (limit >> 2));
|
||||
}
|
||||
}
|
||||
|
||||
static inline void _Py_LeaveRecursiveCall(PyThreadState *tstate) {
|
||||
tstate->recursion_depth--;
|
||||
int limit = tstate->interp->ceval.recursion_limit;
|
||||
if (tstate->recursion_depth < _Py_RecursionLimitLowerWaterMark(limit)) {
|
||||
tstate->overflowed = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void _Py_LeaveRecursiveCall_inline(void) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue