mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
bpo-31857: Make the behavior of USE_STACKCHECK deterministic (#4098)
This commit is contained in:
parent
32318930da
commit
1896793520
6 changed files with 15 additions and 11 deletions
|
|
@ -93,21 +93,19 @@ PyAPI_FUNC(int) Py_GetRecursionLimit(void);
|
|||
PyThreadState_GET()->overflowed = 0; \
|
||||
} while(0)
|
||||
PyAPI_FUNC(int) _Py_CheckRecursiveCall(const char *where);
|
||||
/* XXX _Py_CheckRecursionLimit should be changed to
|
||||
_PyRuntime.ceval.check_recursion_limit. However, due to the macros
|
||||
in which it's used, _Py_CheckRecursionLimit is stuck in the stable
|
||||
ABI. It should be removed therefrom when possible.
|
||||
|
||||
/* Due to the macros in which it's used, _Py_CheckRecursionLimit is in
|
||||
the stable ABI. It should be removed therefrom when possible.
|
||||
*/
|
||||
PyAPI_DATA(int) _Py_CheckRecursionLimit;
|
||||
|
||||
#ifdef USE_STACKCHECK
|
||||
/* With USE_STACKCHECK, we artificially decrement the recursion limit in order
|
||||
to trigger regular stack checks in _Py_CheckRecursiveCall(), except if
|
||||
the "overflowed" flag is set, in which case we need the true value
|
||||
of _Py_CheckRecursionLimit for _Py_MakeEndRecCheck() to function properly.
|
||||
/* With USE_STACKCHECK, trigger stack checks in _Py_CheckRecursiveCall()
|
||||
on every 64th call to Py_EnterRecursiveCall.
|
||||
*/
|
||||
# define _Py_MakeRecCheck(x) \
|
||||
(++(x) > (_Py_CheckRecursionLimit += PyThreadState_GET()->overflowed - 1))
|
||||
(++(x) > _Py_CheckRecursionLimit || \
|
||||
++(PyThreadState_GET()->stackcheck_counter) > 64)
|
||||
#else
|
||||
# define _Py_MakeRecCheck(x) (++(x) > _Py_CheckRecursionLimit)
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue