Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3db4007

Browse files
Fix pystate.c.
1 parent 4af0ce7 commit 3db4007

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

Include/internal/pycore_pystate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ _Py_ThreadCanHandlePendingCalls(void)
6565
and interpreter state */
6666

6767
#if defined(HAVE_THREAD_LOCAL) && !defined(Py_BUILD_CORE_MODULE)
68-
extern thread_local PyThreadState *_Py_tss_tstate;
68+
extern _Py_thread_local PyThreadState *_Py_tss_tstate;
6969
#endif
7070
PyAPI_DATA(PyThreadState *) _PyThreadState_GetCurrent(void);
7171

Python/pystate.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,38 +61,55 @@ extern "C" {
6161
*/
6262

6363

64-
thread_local PyThreadState *_Py_tss_tstate = NULL;
65-
66-
PyThreadState *
67-
_PyThreadState_GetCurrent(void)
68-
{
69-
return _Py_tss_tstate;
70-
}
64+
#ifdef HAVE_THREAD_LOCAL
65+
_Py_thread_local PyThreadState *_Py_tss_tstate = NULL;
66+
#endif
7167

7268
static inline PyThreadState *
7369
current_fast_get(_PyRuntimeState *Py_UNUSED(runtime))
7470
{
71+
#ifdef HAVE_THREAD_LOCAL
7572
return _Py_tss_tstate;
73+
#else
74+
// XXX Fall back to the PyThread_tss_*() API.
75+
# error "no supported thread-local variable storage classifier"
76+
#endif
7677
}
7778

7879
static inline void
7980
current_fast_set(_PyRuntimeState *Py_UNUSED(runtime), PyThreadState *tstate)
8081
{
8182
assert(tstate != NULL);
83+
#ifdef HAVE_THREAD_LOCAL
8284
_Py_tss_tstate = tstate;
85+
#else
86+
// XXX Fall back to the PyThread_tss_*() API.
87+
# error "no supported thread-local variable storage classifier"
88+
#endif
8389
}
8490

8591
static inline void
8692
current_fast_clear(_PyRuntimeState *Py_UNUSED(runtime))
8793
{
94+
#ifdef HAVE_THREAD_LOCAL
8895
_Py_tss_tstate = NULL;
96+
#else
97+
// XXX Fall back to the PyThread_tss_*() API.
98+
# error "no supported thread-local variable storage classifier"
99+
#endif
89100
}
90101

91102
#define tstate_verify_not_active(tstate) \
92103
if (tstate == current_fast_get((tstate)->interp->runtime)) { \
93104
_Py_FatalErrorFormat(__func__, "tstate %p is still current", tstate); \
94105
}
95106

107+
PyThreadState *
108+
_PyThreadState_GetCurrent(void)
109+
{
110+
return current_fast_get(&_PyRuntime);
111+
}
112+
96113

97114
//------------------------------------------------
98115
// the thread state bound to the current OS thread

0 commit comments

Comments
 (0)