diff options
author | Armin Rigo <arigo@tunes.org> | 2017-09-27 13:11:40 +0200 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2017-09-27 13:11:40 +0200 |
commit | e0380677ec468aea1d16510f98a4cf0bfcc19109 (patch) | |
tree | 30f295ebd38e1aa16b62be7e601219d7c83b074d /c/misc_thread_common.h | |
parent | fd5d394a95feb8bedbbe7323a6045f5a9f00e0ec (diff) | |
download | cffi-e0380677ec468aea1d16510f98a4cf0bfcc19109.tar.gz |
More fun with _PyThreadState_Current becoming undefined in 3.7.
Diffstat (limited to 'c/misc_thread_common.h')
-rw-r--r-- | c/misc_thread_common.h | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/c/misc_thread_common.h b/c/misc_thread_common.h index d232e7e..b93bdfe 100644 --- a/c/misc_thread_common.h +++ b/c/misc_thread_common.h @@ -65,22 +65,30 @@ static void restore_errno_only(void) /* Seems that CPython 3.5.1 made our job harder. Did not find out how to do that without these hacks. We can't use PyThreadState_GET(), because that calls PyThreadState_Get() which fails an assert if the - result is NULL. */ -#if PY_MAJOR_VERSION >= 3 && !defined(_Py_atomic_load_relaxed) + result is NULL. We can use _PyThreadState_UncheckedGet() from 3.6, + though. It was added in 3.5.2 but should never be used in 3.5.x + because it is not available in 3.5.0 or 3.5.1. */ +#if PY_VERSION_HEX >= 0x03060000 +static PyThreadState *get_current_ts(void) +{ + return _PyThreadState_UncheckedGet(); +} +#else +# if PY_MAJOR_VERSION >= 3 && !defined(_Py_atomic_load_relaxed) /* this was abruptly un-defined in 3.5.1 */ -void *volatile _PyThreadState_Current; +extern void *volatile _PyThreadState_Current; /* XXX simple volatile access is assumed atomic */ -# define _Py_atomic_load_relaxed(pp) (*(pp)) -#endif - +# define _Py_atomic_load_relaxed(pp) (*(pp)) +# endif static PyThreadState *get_current_ts(void) { -#if defined(_Py_atomic_load_relaxed) +# if defined(_Py_atomic_load_relaxed) return (PyThreadState*)_Py_atomic_load_relaxed(&_PyThreadState_Current); -#else +# else return _PyThreadState_Current; -#endif +# endif } +#endif static PyGILState_STATE gil_ensure(void) { |