Skip to content

Commit 108ea06

Browse files
Apply Brandt's fix
1 parent d7a2d30 commit 108ea06

File tree

4 files changed

+26
-24
lines changed

4 files changed

+26
-24
lines changed

Include/internal/pycore_ceval.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -249,16 +249,7 @@ static inline void _Py_LeaveRecursiveCallTstate(PyThreadState *tstate) {
249249

250250
PyAPI_FUNC(void) _Py_InitializeRecursionLimits(PyThreadState *tstate);
251251

252-
static inline int _Py_ReachedRecursionLimit(PyThreadState *tstate) {
253-
uintptr_t here_addr = _Py_get_machine_stack_pointer();
254-
_PyThreadStateImpl *_tstate = (_PyThreadStateImpl *)tstate;
255-
assert(_tstate->c_stack_hard_limit != 0);
256-
#if _Py_STACK_GROWS_DOWN
257-
return here_addr <= _tstate->c_stack_soft_limit;
258-
#else
259-
return here_addr >= _tstate->c_stack_soft_limit;
260-
#endif
261-
}
252+
PyAPI_FUNC(int) _Py_ReachedRecursionLimit(PyThreadState *tstate);
262253

263254
// Export for test_peg_generator
264255
PyAPI_FUNC(int) _Py_ReachedRecursionLimitWithMargin(

Include/internal/pycore_pystate.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,18 @@ static uintptr_t return_pointer_as_int(char* p) {
312312
}
313313
#endif
314314

315-
PyAPI_DATA(uintptr_t) _Py_get_machine_stack_pointer(void);
315+
static inline uintptr_t
316+
_Py_get_machine_stack_pointer(void) {
317+
#if _Py__has_builtin(__builtin_frame_address) || defined(__GNUC__)
318+
return (uintptr_t)__builtin_frame_address(0);
319+
#elif defined(_MSC_VER)
320+
return (uintptr_t)_AddressOfReturnAddress();
321+
#else
322+
char here;
323+
/* Avoid compiler warning about returning stack address */
324+
return return_pointer_as_int(&here);
325+
#endif
326+
}
316327

317328
static inline intptr_t
318329
_Py_RecursionLimit_GetMargin(PyThreadState *tstate)

Python/ceval.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,19 @@ _PyEval_GetIter(_PyStackRef iterable, _PyStackRef *index_or_null, int yield_from
12011201
return PyStackRef_FromPyObjectSteal(iter_o);
12021202
}
12031203

1204+
Py_NO_INLINE int
1205+
_Py_ReachedRecursionLimit(PyThreadState *tstate) {
1206+
uintptr_t here_addr = _Py_get_machine_stack_pointer();
1207+
_PyThreadStateImpl *_tstate = (_PyThreadStateImpl *)tstate;
1208+
assert(_tstate->c_stack_hard_limit != 0);
1209+
#if _Py_STACK_GROWS_DOWN
1210+
return here_addr <= _tstate->c_stack_soft_limit;
1211+
#else
1212+
return here_addr >= _tstate->c_stack_soft_limit;
1213+
#endif
1214+
}
1215+
1216+
12041217
#if (defined(__GNUC__) && __GNUC__ >= 10 && !defined(__clang__)) && defined(__x86_64__)
12051218
/*
12061219
* gh-129987: The SLP autovectorizer can cause poor code generation for

Python/pystate.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3286,16 +3286,3 @@ _Py_GetMainConfig(void)
32863286
}
32873287
return _PyInterpreterState_GetConfig(interp);
32883288
}
3289-
3290-
uintptr_t
3291-
_Py_get_machine_stack_pointer(void) {
3292-
#if _Py__has_builtin(__builtin_frame_address) || defined(__GNUC__)
3293-
return (uintptr_t)__builtin_frame_address(0);
3294-
#elif defined(_MSC_VER)
3295-
return (uintptr_t)_AddressOfReturnAddress();
3296-
#else
3297-
char here;
3298-
/* Avoid compiler warning about returning stack address */
3299-
return return_pointer_as_int(&here);
3300-
#endif
3301-
}

0 commit comments

Comments
 (0)