From b2dde90f79579ac44b1fc6b2a19e01897a644f98 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Tue, 28 Oct 2025 08:33:37 -0400 Subject: [PATCH 1/2] Remove _Py_thread_local macro definition --- Include/internal/pycore_pystate.h | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/Include/internal/pycore_pystate.h b/Include/internal/pycore_pystate.h index f4b71fd4fb60f4..bde0b9b9713c84 100644 --- a/Include/internal/pycore_pystate.h +++ b/Include/internal/pycore_pystate.h @@ -85,22 +85,6 @@ _Py_ThreadCanHandleSignals(PyInterpreterState *interp) return (_Py_IsMainThread() && _Py_IsMainInterpreter(interp)); } -/* Definition of the _Py_thread_local macro. In reality, this should really be - * in pyport.h, but some extensions define Py_BUILD_CORE after including that. - * So, instead of breaking things, we just put this here for now. */ - -#ifdef thread_local -# define _Py_thread_local thread_local -#elif __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__) -# define _Py_thread_local _Thread_local -#elif defined(_MSC_VER) /* AKA NT_THREADS */ -# define _Py_thread_local __declspec(thread) -#elif defined(__GNUC__) /* includes clang */ -# define _Py_thread_local __thread -#else -# error "no supported thread-local variable storage classifier" -#endif - /* Variable and static inline functions for in-line access to current thread and interpreter state */ From bb61072927e329268dec28c8c943b9d3a1e09924 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Tue, 28 Oct 2025 08:35:40 -0400 Subject: [PATCH 2/2] Move back to pyport.h --- Include/pyport.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Include/pyport.h b/Include/pyport.h index a1ad943aa09094..e77b39026a59c1 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -511,6 +511,17 @@ extern "C" { #ifdef WITH_THREAD // HAVE_THREAD_LOCAL is just defined here for compatibility's sake # define HAVE_THREAD_LOCAL 1 +# ifdef thread_local +# define _Py_thread_local thread_local +# elif __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__) +# define _Py_thread_local _Thread_local +# elif defined(_MSC_VER) /* AKA NT_THREADS */ +# define _Py_thread_local __declspec(thread) +# elif defined(__GNUC__) /* includes clang */ +# define _Py_thread_local __thread +# else +# error "no supported thread-local variable storage classifier" +# endif #endif #if defined(__ANDROID__) || defined(__VXWORKS__)