Skip to content

Commit 81b7217

Browse files
committed
Move _Py_thread_local to pycore_pystate.h
This fixes extensions that define Py_BUILD_CORE after including Python.h, but before including pycore_pystate.h, such as mypyc.
1 parent 977e50a commit 81b7217

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

Include/internal/pycore_pystate.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,21 @@ _Py_ThreadCanHandleSignals(PyInterpreterState *interp)
8585
return (_Py_IsMainThread() && _Py_IsMainInterpreter(interp));
8686
}
8787

88+
/* Definition of the _Py_thread_local macro. In reality, this should really be
89+
* in pyport.h, but some extensions define Py_BUILD_CORE after including that.
90+
* So, instead of breaking things, we just put this here for now. */
91+
92+
#ifdef thread_local
93+
# define _Py_thread_local thread_local
94+
#elif __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__)
95+
# define _Py_thread_local _Thread_local
96+
#elif defined(_MSC_VER) /* AKA NT_THREADS */
97+
# define _Py_thread_local __declspec(thread)
98+
#elif defined(__GNUC__) /* includes clang */
99+
# define _Py_thread_local __thread
100+
#else
101+
# error "no supported thread-local variable storage classifier"
102+
#endif
88103

89104
/* Variable and static inline functions for in-line access to current thread
90105
and interpreter state */

Include/pyport.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -512,17 +512,6 @@ extern "C" {
512512
# ifdef Py_BUILD_CORE
513513
// HAVE_THREAD_LOCAL is just defined here for compatibility's sake
514514
# define HAVE_THREAD_LOCAL 1
515-
# ifdef thread_local
516-
# define _Py_thread_local thread_local
517-
# elif __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__)
518-
# define _Py_thread_local _Thread_local
519-
# elif defined(_MSC_VER) /* AKA NT_THREADS */
520-
# define _Py_thread_local __declspec(thread)
521-
# elif defined(__GNUC__) /* includes clang */
522-
# define _Py_thread_local __thread
523-
# else
524-
# error "no supported thread-local variable storage classifier"
525-
# endif
526515
# endif
527516
#endif
528517

0 commit comments

Comments
 (0)