bpo-42500: Fix recursion in or after except (GH-23568)

* Use counter, rather boolean state when handling soft overflows.
This commit is contained in:
Mark Shannon 2020-12-02 13:30:55 +00:00 committed by GitHub
parent 93a0ef7647
commit 4e7a69bdb6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 76 additions and 72 deletions

View file

@ -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.

View file

@ -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) {