@@ -49,20 +49,6 @@ _Py_ReachedRecursionLimitWithMargin(PyThreadState *tstate, int margin_count)
4949#endif
5050}
5151
52- void
53- _Py_EnterRecursiveCallUnchecked (PyThreadState * tstate )
54- {
55- uintptr_t here_addr = _Py_get_machine_stack_pointer ();
56- _PyThreadStateImpl * _tstate = (_PyThreadStateImpl * )tstate ;
57- #if _Py_STACK_GROWS_DOWN
58- if (here_addr < _tstate -> c_stack_hard_limit ) {
59- #else
60- if (here_addr > _tstate -> c_stack_hard_limit ) {
61- #endif
62- Py_FatalError ("Unchecked stack overflow." );
63- }
64- }
65-
6652#if defined(__s390x__ )
6753# define Py_C_STACK_SIZE 320000
6854#elif defined(_WIN32 )
@@ -278,7 +264,7 @@ PyUnstable_ThreadState_ResetStackProtection(PyThreadState *tstate)
278264
279265
280266/* The function _Py_EnterRecursiveCallTstate() only calls _Py_CheckRecursiveCall()
281- if the stack pointer is between the stack base and c_stack_hard_limit . */
267+ if the stack pointer is beyond c_stack_soft_limit . */
282268int
283269_Py_CheckRecursiveCall (PyThreadState * tstate , const char * where )
284270{
@@ -287,16 +273,21 @@ _Py_CheckRecursiveCall(PyThreadState *tstate, const char *where)
287273 assert (_tstate -> c_stack_soft_limit != 0 );
288274 assert (_tstate -> c_stack_hard_limit != 0 );
289275#if _Py_STACK_GROWS_DOWN
290- assert (here_addr >= _tstate -> c_stack_hard_limit - _PyOS_STACK_MARGIN_BYTES );
291276 if (here_addr < _tstate -> c_stack_hard_limit ) {
292- /* Overflowing while handling an overflow. Give up. */
277+ if (here_addr < _tstate -> c_stack_hard_limit - _PyOS_STACK_MARGIN_BYTES ) {
278+ // Far out of bounds -- Assume stack switching has occurred
279+ return 0 ;
280+ }
293281 int kbytes_used = (int )(_tstate -> c_stack_top - here_addr )/1024 ;
294282#else
295- assert (here_addr <= _tstate -> c_stack_hard_limit + _PyOS_STACK_MARGIN_BYTES );
296283 if (here_addr > _tstate -> c_stack_hard_limit ) {
297- /* Overflowing while handling an overflow. Give up. */
284+ if (here_addr > _tstate -> c_stack_hard_limit + _PyOS_STACK_MARGIN_BYTES ) {
285+ // Far out of bounds -- Assume stack switching has occurred
286+ return 0 ;
287+ }
298288 int kbytes_used = (int )(here_addr - _tstate -> c_stack_top )/1024 ;
299289#endif
290+ /* Too much stack used to safely raise an exception. Give up. */
300291 char buffer [80 ];
301292 snprintf (buffer , 80 , "Unrecoverable stack overflow (used %d kB)%s" , kbytes_used , where );
302293 Py_FatalError (buffer );
@@ -1201,19 +1192,6 @@ _PyEval_GetIter(_PyStackRef iterable, _PyStackRef *index_or_null, int yield_from
12011192 return PyStackRef_FromPyObjectSteal (iter_o );
12021193}
12031194
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-
12171195#if (defined(__GNUC__ ) && __GNUC__ >= 10 && !defined(__clang__ )) && defined(__x86_64__ )
12181196/*
12191197 * gh-129987: The SLP autovectorizer can cause poor code generation for
0 commit comments