[pypy-commit] cffi default: Push and pull at the mess

arigo pypy.commits at gmail.com
Sat Oct 7 09:09:54 EDT 2017


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r3044:1b28d5d027ed
Date: 2017-10-05 08:16 +0200
http://bitbucket.org/cffi/cffi/changeset/1b28d5d027ed/

Log:	Push and pull at the mess

diff --git a/c/misc_thread_common.h b/c/misc_thread_common.h
--- a/c/misc_thread_common.h
+++ b/c/misc_thread_common.h
@@ -62,33 +62,35 @@
 #endif
 
 
-/* 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.  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
+/* MESS.  We can't use PyThreadState_GET(), because that calls
+   PyThreadState_Get() which fails an assert if the result is NULL.
+   
+   * in Python 2.7 and <= 3.4, the variable _PyThreadState_Current
+     is directly available, so use that.
+
+   * in Python 3.5, the variable is available too, but it might be
+     the case that the headers don't define it (this changed in 3.5.1).
+     In case we're compiling with 3.5.x with x >= 1, we need to
+     manually define this variable.
+
+   * in Python >= 3.6 there is _PyThreadState_UncheckedGet().
+     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 >= 0x03050100 && PY_VERSION_HEX < 0x03060000
+PyAPI_DATA(void *volatile) _PyThreadState_Current;
+#endif
+
 static PyThreadState *get_current_ts(void)
 {
+#if PY_VERSION_HEX >= 0x03060000
     return _PyThreadState_UncheckedGet();
+#elif defined(_Py_atomic_load_relaxed)
+    return (PyThreadState*)_Py_atomic_load_relaxed(&_PyThreadState_Current);
+#else
+    return (PyThreadState*)_PyThreadState_Current;  /* assume atomic read */
+#endif
 }
-#else
-#  if PY_MAJOR_VERSION >= 3 && !defined(_Py_atomic_load_relaxed)
-                             /* this was abruptly un-defined in 3.5.1 */
-extern void *volatile _PyThreadState_Current;
-   /* XXX simple volatile access is assumed atomic */
-#    define _Py_atomic_load_relaxed(pp)  (*(pp))
-#  endif
-static PyThreadState *get_current_ts(void)
-{
-#  if defined(_Py_atomic_load_relaxed)
-    return (PyThreadState*)_Py_atomic_load_relaxed(&_PyThreadState_Current);
-#  else
-    return _PyThreadState_Current;
-#  endif
-}
-#endif
 
 static PyGILState_STATE gil_ensure(void)
 {


More information about the pypy-commit mailing list