[pypy-commit] cffi default: Blindly attempt to detect MinGW (issue #159)

arigo pypy.commits at gmail.com
Fri Oct 7 16:53:02 EDT 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r2781:c10bc64fa183
Date: 2016-10-07 22:52 +0200
http://bitbucket.org/cffi/cffi/changeset/c10bc64fa183/

Log:	Blindly attempt to detect MinGW (issue #159)

diff --git a/c/libffi_msvc/ffi.h b/c/libffi_msvc/ffi.h
--- a/c/libffi_msvc/ffi.h
+++ b/c/libffi_msvc/ffi.h
@@ -231,6 +231,9 @@
 		  void *user_data,
 		  void *codeloc);
 
+/* AR: for cffi we need the following API, and not the _loc version */
+#define ffi_prep_closure(a,b,c,d)  ffi_prep_closure_loc(a,b,c,d,a)
+
 typedef struct {
   char tramp[FFI_TRAMPOLINE_SIZE];
 
diff --git a/c/misc_win32.h b/c/misc_win32.h
--- a/c/misc_win32.h
+++ b/c/misc_win32.h
@@ -234,8 +234,3 @@
     sprintf(buf, "error 0x%x", (unsigned int)dw);
     return buf;
 }
-
-/************************************************************/
-/* obscure */
-
-#define ffi_prep_closure(a,b,c,d)  ffi_prep_closure_loc(a,b,c,d,a)
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -51,12 +51,17 @@
     see http://stackoverflow.com/questions/22313407/ .)\n""")
     sys.exit(1)
 
-def ask_supports_thread():
+def get_config():
     from distutils.core import Distribution
     from distutils.sysconfig import get_config_vars
     get_config_vars()      # workaround for a bug of distutils, e.g. on OS/X
     config = Distribution().get_command_obj('config')
-    ok = config.try_compile('__thread int some_threadlocal_variable_42;')
+    return config
+
+def ask_supports_thread():
+    config = get_config()
+    ok = (sys.platform != 'win32' and
+          config.try_compile('__thread int some_threadlocal_variable_42;'))
     if ok:
         define_macros.append(('USE__THREAD', None))
     else:
@@ -66,6 +71,10 @@
         sys.stderr.write("Note: will not use '__thread' in the C code\n")
         sys.stderr.write("The above error message can be safely ignored\n")
 
+def uses_msvc():
+    config = get_config()
+    return config.try_compile('#ifndef _MSC_VER\n#error "not MSVC"\n#endif')
+
 def use_pkg_config():
     if sys.platform == 'darwin' and os.path.exists('/usr/local/bin/brew'):
         use_homebrew_for_libffi()
@@ -86,7 +95,7 @@
         os.environ.get('PKG_CONFIG_PATH', '') + ':' + pkgconfig)
 
 
-if sys.platform == 'win32':
+if sys.platform == 'win32' and uses_msvc():
     COMPILE_LIBFFI = 'c/libffi_msvc'    # from the CPython distribution
 else:
     COMPILE_LIBFFI = None


More information about the pypy-commit mailing list