@@ -193,12 +193,18 @@ extern void _PyEval_DeactivateOpCache(void);
193193
194194/* --- _Py_EnterRecursiveCall() ----------------------------------------- */ 
195195
196+ #ifdef  USE_STACKCHECK 
197+ /* With USE_STACKCHECK macro defined, trigger stack checks in 
198+    _Py_CheckRecursiveCall() on every 64th call to _Py_EnterRecursiveCall. */ 
196199static  inline  int  _Py_MakeRecCheck (PyThreadState  * tstate )  {
197-     char  here ;
198-     uintptr_t  here_addr  =  (uintptr_t )& here ;
199-     _PyThreadStateImpl  * _tstate  =  (_PyThreadStateImpl  * )tstate ;
200-     return  here_addr  <  _tstate -> c_stack_soft_limit ;
200+     return  (tstate -> c_recursion_remaining --  <  0 
201+             ||  (tstate -> c_recursion_remaining  &  63 ) ==  0 );
201202}
203+ #else 
204+ static  inline  int  _Py_MakeRecCheck (PyThreadState  * tstate ) {
205+     return  tstate -> c_recursion_remaining --  <  0 ;
206+ }
207+ #endif 
202208
203209// Export for '_json' shared extension, used via _Py_EnterRecursiveCall() 
204210// static inline function. 
@@ -214,31 +220,23 @@ static inline int _Py_EnterRecursiveCallTstate(PyThreadState *tstate,
214220    return  (_Py_MakeRecCheck (tstate ) &&  _Py_CheckRecursiveCall (tstate , where ));
215221}
216222
223+ static  inline  void  _Py_EnterRecursiveCallTstateUnchecked (PyThreadState  * tstate )  {
224+     assert (tstate -> c_recursion_remaining  >  0 );
225+     tstate -> c_recursion_remaining -- ;
226+ }
227+ 
217228static  inline  int  _Py_EnterRecursiveCall (const  char  * where ) {
218229    PyThreadState  * tstate  =  _PyThreadState_GET ();
219230    return  _Py_EnterRecursiveCallTstate (tstate , where );
220231}
221232
222- static  inline  void  _Py_LeaveRecursiveCallTstate (PyThreadState  * tstate ) {
223-     (void )tstate ;
224- }
225- 
226- PyAPI_FUNC (void ) _Py_InitializeRecursionLimits (PyThreadState  * tstate );
227- 
228- static  inline  int  _Py_ReachedRecursionLimit (PyThreadState  * tstate )  {
229-     char  here ;
230-     uintptr_t  here_addr  =  (uintptr_t )& here ;
231-     _PyThreadStateImpl  * _tstate  =  (_PyThreadStateImpl  * )tstate ;
232-     if  (here_addr  >  _tstate -> c_stack_soft_limit ) {
233-         return  0 ;
234-     }
235-     if  (_tstate -> c_stack_hard_limit  ==  0 ) {
236-         _Py_InitializeRecursionLimits (tstate );
237-     }
238-     return  here_addr  <= _tstate -> c_stack_soft_limit ;
233+ static  inline  void  _Py_LeaveRecursiveCallTstate (PyThreadState  * tstate )  {
234+     tstate -> c_recursion_remaining ++ ;
239235}
240236
241237static  inline  void  _Py_LeaveRecursiveCall (void )  {
238+     PyThreadState  * tstate  =  _PyThreadState_GET ();
239+     _Py_LeaveRecursiveCallTstate (tstate );
242240}
243241
244242extern  struct  _PyInterpreterFrame *  _PyEval_GetFrame (void );
@@ -329,6 +327,7 @@ void _Py_unset_eval_breaker_bit_all(PyInterpreterState *interp, uintptr_t bit);
329327
330328PyAPI_FUNC (PyObject  * ) _PyFloat_FromDouble_ConsumeInputs (_PyStackRef  left , _PyStackRef  right , double  value );
331329
330+ 
332331#ifdef  __cplusplus 
333332}
334333#endif 
0 commit comments