GH-91079: Revert "GH-91079: Implement C stack limits using addresses, not counters. (GH-130007)" for now by encukou · Pull Request #130413 · python/cpython
/* --- _Py_EnterRecursiveCall() ----------------------------------------- */
#ifdef USE_STACKCHECK /* 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) { char here; uintptr_t here_addr = (uintptr_t)&here; _PyThreadStateImpl *_tstate = (_PyThreadStateImpl *)tstate; return here_addr < _tstate->c_stack_soft_limit; return (tstate->c_recursion_remaining-- < 0 || (tstate->c_recursion_remaining & 63) == 0); } #else static inline int _Py_MakeRecCheck(PyThreadState *tstate) { return tstate->c_recursion_remaining-- < 0; } #endif
// Export for '_json' shared extension, used via _Py_EnterRecursiveCall() // static inline function.
static inline void _Py_EnterRecursiveCallTstateUnchecked(PyThreadState *tstate) { assert(tstate->c_recursion_remaining > 0); tstate->c_recursion_remaining--; }
static inline int _Py_EnterRecursiveCall(const char *where) { PyThreadState *tstate = _PyThreadState_GET(); return _Py_EnterRecursiveCallTstate(tstate, where); }
static inline void _Py_LeaveRecursiveCallTstate(PyThreadState *tstate) { (void)tstate; }
PyAPI_FUNC(void) _Py_InitializeRecursionLimits(PyThreadState *tstate);
static inline int _Py_ReachedRecursionLimit(PyThreadState *tstate) { char here; uintptr_t here_addr = (uintptr_t)&here; _PyThreadStateImpl *_tstate = (_PyThreadStateImpl *)tstate; if (here_addr > _tstate->c_stack_soft_limit) { return 0; } if (_tstate->c_stack_hard_limit == 0) { _Py_InitializeRecursionLimits(tstate); } return here_addr <= _tstate->c_stack_soft_limit; static inline void _Py_LeaveRecursiveCallTstate(PyThreadState *tstate) { tstate->c_recursion_remaining++; }
static inline void _Py_LeaveRecursiveCall(void) { PyThreadState *tstate = _PyThreadState_GET(); _Py_LeaveRecursiveCallTstate(tstate); }
extern struct _PyInterpreterFrame* _PyEval_GetFrame(void);
PyAPI_FUNC(PyObject *) _PyFloat_FromDouble_ConsumeInputs(_PyStackRef left, _PyStackRef right, double value);
#ifdef __cplusplus } #endif