Armin Rigo avatar Armin Rigo committed 447c0de

A redo of pull request 19: dynamically determine if the C compiler
supports "__thread" or not on this platform. Done slightly more
simply in

Comments (0)

Files changed (3)


 #include "malloc_closure.h"
-/* Define USE__THREAD if gcc on your platform supports "__thread"
-   global variables. */
-#if !defined(MS_WIN32) && !defined(X86_DARWIN) && !defined(POWERPC_DARWIN)
-# define USE__THREAD
 # define STR_OR_BYTES "bytes"
 # define PyText_Type PyUnicode_Type
    variable */
 #ifndef MS_WIN32
 # ifdef USE__THREAD
+/* This macro ^^^ is defined by if it finds that it is
+   syntactically valid to use "__thread" with this C compiler. */
 static __thread int cffi_saved_errno = 0;
 static void save_errno(void) { cffi_saved_errno = errno; }
 static void restore_errno(void) { errno = cffi_saved_errno; }


+__thread int some_threadlocal_variable_42;
             resultlist[:] = res
+def ask_supports_thread():
+    import distutils.errors
+    from distutils.ccompiler import new_compiler
+    compiler = new_compiler(force=1)
+    try:
+        compiler.compile(['c/check__thread.c'])
+    except distutils.errors.CompileError:
+        print >> sys.stderr, "will not use '__thread' in the C code"
+    else:
+        define_macros.append(('USE__THREAD', None))
 def use_pkg_config():
     _ask_pkg_config(include_dirs,       '--cflags-only-I', '-I', sysroot=True)
     _ask_pkg_config(extra_compile_args, '--cflags-only-other')
                    for filename in _filenames)
+    ask_supports_thread()
 if __name__ == '__main__':
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.