@@ -49,20 +49,6 @@ _Py_ReachedRecursionLimitWithMargin(PyThreadState *tstate, int margin_count)
4949#endif
5050}
515152-void
53-_Py_EnterRecursiveCallUnchecked(PyThreadState*tstate)
54-{
55-uintptr_there_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# definePy_C_STACK_SIZE 320000
6854#elif defined(_WIN32)
@@ -278,7 +264,7 @@ PyUnstable_ThreadState_ResetStackProtection(PyThreadState *tstate)
278264279265280266/* 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, constchar*where)
284270{
@@ -287,16 +273,21 @@ _Py_CheckRecursiveCall(PyThreadState *tstate, const char *where)
287273assert(_tstate->c_stack_soft_limit!=0);
288274assert(_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);
291276if (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+return0;
280+ }
293281intkbytes_used= (int)(_tstate->c_stack_top-here_addr)/1024;
294282#else
295-assert(here_addr <= _tstate->c_stack_hard_limit+_PyOS_STACK_MARGIN_BYTES);
296283if (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+return0;
287+ }
298288intkbytes_used= (int)(here_addr-_tstate->c_stack_top)/1024;
299289#endif
290+/* Too much stack used to safely raise an exception. Give up. */
300291charbuffer[80];
301292snprintf(buffer, 80, "Unrecoverable stack overflow (used %d kB)%s", kbytes_used, where);
302293Py_FatalError(buffer);
@@ -1201,19 +1192,6 @@ _PyEval_GetIter(_PyStackRef iterable, _PyStackRef *index_or_null, int yield_from
12011192returnPyStackRef_FromPyObjectSteal(iter_o);
12021193}
120311941204-Py_NO_INLINEint
1205-_Py_ReachedRecursionLimit(PyThreadState*tstate) {
1206-uintptr_there_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-returnhere_addr <= _tstate->c_stack_soft_limit;
1211-#else
1212-returnhere_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