diff options
| author | Petr Viktorin <encukou@gmail.com> | 2025-02-24 10:16:08 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-24 10:16:08 (GMT) |
| commit | ef29104f7d7ad7864f5f153cd7391af73d7cef63 (patch) | |
| tree | 38c76b08e114a9e6e993081b828b64978bfefa2e /Include/cpython | |
| parent | 0ff16115741aeaaaf7f963f68d5c575efb960277 (diff) | |
| download | cpython-ef29104f7d7ad7864f5f153cd7391af73d7cef63.zip cpython-ef29104f7d7ad7864f5f153cd7391af73d7cef63.tar.gz cpython-ef29104f7d7ad7864f5f153cd7391af73d7cef63.tar.bz2 | |
GH-91079: Revert "GH-91079: Implement C stack limits using addresses, not counters. (GH-130007)" for now (GH130413)
Revert "GH-91079: Implement C stack limits using addresses, not counters. (GH-130007)" for now
Unfortunatlely, the change broke some buildbots.
This reverts commit 2498c22fa0a2b560491bc503fa676585c1a603d0.
Diffstat (limited to 'Include/cpython')
| -rw-r--r-- | Include/cpython/object.h | 11 | ||||
| -rw-r--r-- | Include/cpython/pystate.h | 34 |
2 files changed, 37 insertions, 8 deletions
diff --git a/Include/cpython/object.h b/Include/cpython/object.h index 260b90d..71bd018 100644 --- a/Include/cpython/object.h +++ b/Include/cpython/object.h @@ -487,19 +487,18 @@ PyAPI_FUNC(void) _PyTrash_thread_destroy_chain(PyThreadState *tstate); * we have headroom above the trigger limit */ #define Py_TRASHCAN_HEADROOM 50 -/* Helper function for Py_TRASHCAN_BEGIN */ -PyAPI_FUNC(int) _Py_ReachedRecursionLimitWithMargin(PyThreadState *tstate, int margin_count); - #define Py_TRASHCAN_BEGIN(op, dealloc) \ do { \ PyThreadState *tstate = PyThreadState_Get(); \ - if (_Py_ReachedRecursionLimitWithMargin(tstate, 1) && Py_TYPE(op)->tp_dealloc == (destructor)dealloc) { \ + if (tstate->c_recursion_remaining <= Py_TRASHCAN_HEADROOM && Py_TYPE(op)->tp_dealloc == (destructor)dealloc) { \ _PyTrash_thread_deposit_object(tstate, (PyObject *)op); \ break; \ - } + } \ + tstate->c_recursion_remaining--; /* The body of the deallocator is here. */ #define Py_TRASHCAN_END \ - if (tstate->delete_later && !_Py_ReachedRecursionLimitWithMargin(tstate, 2)) { \ + tstate->c_recursion_remaining++; \ + if (tstate->delete_later && tstate->c_recursion_remaining > (Py_TRASHCAN_HEADROOM*2)) { \ _PyTrash_thread_destroy_chain(tstate); \ } \ } while (0); diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h index e0d2ac9..cd6d958 100644 --- a/Include/cpython/pystate.h +++ b/Include/cpython/pystate.h @@ -112,7 +112,7 @@ struct _ts { int py_recursion_remaining; int py_recursion_limit; - int c_recursion_remaining; /* Retained for backwards compatibility. Do not use */ + int c_recursion_remaining; int recursion_headroom; /* Allow 50 more calls to handle any errors. */ /* 'tracing' keeps track of the execution depth when tracing/profiling. @@ -202,7 +202,36 @@ struct _ts { PyObject *threading_local_sentinel; }; -# define Py_C_RECURSION_LIMIT 5000 +#ifdef Py_DEBUG + // A debug build is likely built with low optimization level which implies + // higher stack memory usage than a release build: use a lower limit. +# define Py_C_RECURSION_LIMIT 500 +#elif defined(__s390x__) +# define Py_C_RECURSION_LIMIT 800 +#elif defined(_WIN32) && defined(_M_ARM64) +# define Py_C_RECURSION_LIMIT 1000 +#elif defined(_WIN32) +# define Py_C_RECURSION_LIMIT 3000 +#elif defined(__ANDROID__) + // On an ARM64 emulator, API level 34 was OK with 10000, but API level 21 + // crashed in test_compiler_recursion_limit. +# define Py_C_RECURSION_LIMIT 3000 +#elif defined(_Py_ADDRESS_SANITIZER) +# define Py_C_RECURSION_LIMIT 4000 +#elif defined(__sparc__) + // test_descr crashed on sparc64 with >7000 but let's keep a margin of error. +# define Py_C_RECURSION_LIMIT 4000 +#elif defined(__wasi__) + // Based on wasmtime 16. +# define Py_C_RECURSION_LIMIT 5000 +#elif defined(__hppa__) || defined(__powerpc64__) + // test_descr crashed with >8000 but let's keep a margin of error. +# define Py_C_RECURSION_LIMIT 5000 +#else + // This value is duplicated in Lib/test/support/__init__.py +# define Py_C_RECURSION_LIMIT 10000 +#endif + /* other API */ @@ -217,6 +246,7 @@ _PyThreadState_UncheckedGet(void) return PyThreadState_GetUnchecked(); } + // Disable tracing and profiling. PyAPI_FUNC(void) PyThreadState_EnterTracing(PyThreadState *tstate); |
