@@ -193,12 +193,18 @@ extern void _PyEval_DeactivateOpCache(void);
193
193
194
194
/* --- _Py_EnterRecursiveCall() ----------------------------------------- */
195
195
196
+ #ifdef USE_STACKCHECK
197
+ /* With USE_STACKCHECK macro defined, trigger stack checks in
198
+ _Py_CheckRecursiveCall() on every 64th call to _Py_EnterRecursiveCall. */
196
199
static 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 );
201
202
}
203
+ #else
204
+ static inline int _Py_MakeRecCheck (PyThreadState * tstate ) {
205
+ return tstate -> c_recursion_remaining -- < 0 ;
206
+ }
207
+ #endif
202
208
203
209
// Export for '_json' shared extension, used via _Py_EnterRecursiveCall()
204
210
// static inline function.
@@ -214,31 +220,23 @@ static inline int _Py_EnterRecursiveCallTstate(PyThreadState *tstate,
214
220
return (_Py_MakeRecCheck (tstate ) && _Py_CheckRecursiveCall (tstate , where ));
215
221
}
216
222
223
+ static inline void _Py_EnterRecursiveCallTstateUnchecked (PyThreadState * tstate ) {
224
+ assert (tstate -> c_recursion_remaining > 0 );
225
+ tstate -> c_recursion_remaining -- ;
226
+ }
227
+
217
228
static inline int _Py_EnterRecursiveCall (const char * where ) {
218
229
PyThreadState * tstate = _PyThreadState_GET ();
219
230
return _Py_EnterRecursiveCallTstate (tstate , where );
220
231
}
221
232
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 ++ ;
239
235
}
240
236
241
237
static inline void _Py_LeaveRecursiveCall (void ) {
238
+ PyThreadState * tstate = _PyThreadState_GET ();
239
+ _Py_LeaveRecursiveCallTstate (tstate );
242
240
}
243
241
244
242
extern struct _PyInterpreterFrame * _PyEval_GetFrame (void );
@@ -329,6 +327,7 @@ void _Py_unset_eval_breaker_bit_all(PyInterpreterState *interp, uintptr_t bit);
329
327
330
328
PyAPI_FUNC (PyObject * ) _PyFloat_FromDouble_ConsumeInputs (_PyStackRef left , _PyStackRef right , double value );
331
329
330
+
332
331
#ifdef __cplusplus
333
332
}
334
333
#endif
0 commit comments