GitHub CopilotWrite better code with AI | MCP RegistryIntegrate external tools | ActionsAutomate any workflow | CodespacesInstant dev environments | IssuesPlan and track work | Code ReviewManage code changes | Code QualityEnforce quality at merge | Why GitHub | Marketplace | View all features | Enterprises | Small and medium teams | Startups | View all use cases | View all industries | View all solutions | AI | Software Development | DevOps | Security | View all topics | Customer stories | Events & webinars | Ebooks & reports | Business insights | Trust center | Partners | View all resources
@@ -193,12 +193,18 @@ extern void _PyEval_DeactivateOpCache(void);
193193194194/* --- _Py_EnterRecursiveCall() ----------------------------------------- */
195195196+#ifdefUSE_STACKCHECK
197+/* With USE_STACKCHECK macro defined, trigger stack checks in
198+ _Py_CheckRecursiveCall() on every 64th call to _Py_EnterRecursiveCall. */
196199staticinlineint_Py_MakeRecCheck(PyThreadState*tstate) {
197-charhere;
198-uintptr_there_addr= (uintptr_t)&here;
199-_PyThreadStateImpl*_tstate= (_PyThreadStateImpl*)tstate;
200-returnhere_addr<_tstate->c_stack_soft_limit;
200+return (tstate->c_recursion_remaining--<0
201+|| (tstate->c_recursion_remaining&63) ==0);
201202}
203+#else
204+staticinlineint_Py_MakeRecCheck(PyThreadState*tstate) {
205+returntstate->c_recursion_remaining--<0;
206+}
207+#endif
202208203209// Export for '_json' shared extension, used via _Py_EnterRecursiveCall()
204210// static inline function.
@@ -214,31 +220,23 @@ static inline int _Py_EnterRecursiveCallTstate(PyThreadState *tstate,
214220return (_Py_MakeRecCheck(tstate) &&_Py_CheckRecursiveCall(tstate, where));
215221}
216222223+staticinlinevoid_Py_EnterRecursiveCallTstateUnchecked(PyThreadState*tstate) {
224+assert(tstate->c_recursion_remaining>0);
225+tstate->c_recursion_remaining--;
226+}
227+217228staticinlineint_Py_EnterRecursiveCall(constchar*where) {
218229PyThreadState*tstate=_PyThreadState_GET();
219230return_Py_EnterRecursiveCallTstate(tstate, where);
220231}
221232222-staticinlinevoid_Py_LeaveRecursiveCallTstate(PyThreadState*tstate) {
223- (void)tstate;
224-}
225-226-PyAPI_FUNC(void) _Py_InitializeRecursionLimits(PyThreadState*tstate);
227-228-staticinlineint_Py_ReachedRecursionLimit(PyThreadState*tstate) {
229-charhere;
230-uintptr_there_addr= (uintptr_t)&here;
231-_PyThreadStateImpl*_tstate= (_PyThreadStateImpl*)tstate;
232-if (here_addr>_tstate->c_stack_soft_limit) {
233-return0;
234- }
235-if (_tstate->c_stack_hard_limit==0) {
236-_Py_InitializeRecursionLimits(tstate);
237- }
238-returnhere_addr <= _tstate->c_stack_soft_limit;
233+staticinlinevoid_Py_LeaveRecursiveCallTstate(PyThreadState*tstate) {
234+tstate->c_recursion_remaining++;
239235}
240236241237staticinlinevoid_Py_LeaveRecursiveCall(void) {
238+PyThreadState*tstate=_PyThreadState_GET();
239+_Py_LeaveRecursiveCallTstate(tstate);
242240}
243241244242externstruct_PyInterpreterFrame*_PyEval_GetFrame(void);
@@ -329,6 +327,7 @@ void _Py_unset_eval_breaker_bit_all(PyInterpreterState *interp, uintptr_t bit);
329327330328PyAPI_FUNC(PyObject*) _PyFloat_FromDouble_ConsumeInputs(_PyStackRefleft, _PyStackRefright, doublevalue);
331329330+332331#ifdef__cplusplus
333332}
334333#endif