mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-40513: Per-interpreter recursion_limit (GH-19929)
Move recursion_limit member from _PyRuntimeState.ceval to PyInterpreterState.ceval. * Py_SetRecursionLimit() now only sets _Py_CheckRecursionLimit of ceval.c if the current Python thread is part of the main interpreter. * Inline _Py_MakeEndRecCheck() into _Py_LeaveRecursiveCall(). * Convert _Py_RecursionLimitLowerWaterMark() macro into a static inline function.
This commit is contained in:
parent
627f701235
commit
4e30ed3af0
4 changed files with 28 additions and 22 deletions
|
@ -65,12 +65,12 @@ PyAPI_DATA(int) _Py_CheckRecursionLimit;
|
|||
/* With USE_STACKCHECK macro defined, trigger stack checks in
|
||||
_Py_CheckRecursiveCall() on every 64th call to Py_EnterRecursiveCall. */
|
||||
static inline int _Py_MakeRecCheck(PyThreadState *tstate) {
|
||||
return (++tstate->recursion_depth > _Py_CheckRecursionLimit
|
||||
return (++tstate->recursion_depth > tstate->interp->ceval.recursion_limit
|
||||
|| ++tstate->stackcheck_counter > 64);
|
||||
}
|
||||
#else
|
||||
static inline int _Py_MakeRecCheck(PyThreadState *tstate) {
|
||||
return (++tstate->recursion_depth > _Py_CheckRecursionLimit);
|
||||
return (++tstate->recursion_depth > tstate->interp->ceval.recursion_limit);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -90,20 +90,22 @@ 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. */
|
||||
#define _Py_RecursionLimitLowerWaterMark(limit) \
|
||||
(((limit) > 200) \
|
||||
? ((limit) - 50) \
|
||||
: (3 * ((limit) >> 2)))
|
||||
|
||||
#define _Py_MakeEndRecCheck(x) \
|
||||
(--(x) < _Py_RecursionLimitLowerWaterMark(_Py_CheckRecursionLimit))
|
||||
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) {
|
||||
if (_Py_MakeEndRecCheck(tstate->recursion_depth)) {
|
||||
tstate->recursion_depth--;
|
||||
int limit = tstate->interp->ceval.recursion_limit;
|
||||
if (tstate->recursion_depth < _Py_RecursionLimitLowerWaterMark(limit)) {
|
||||
tstate->overflowed = 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue