Author: Armin Rigo <[email protected]>
Branch: static-callback-embedding
Changeset: r2564:3a8c3afacaa2
Date: 2016-01-12 17:55 +0100
http://bitbucket.org/cffi/cffi/changeset/3a8c3afacaa2/

Log:    More Windows hacks

diff --git a/cffi/ffiplatform.py b/cffi/ffiplatform.py
--- a/cffi/ffiplatform.py
+++ b/cffi/ffiplatform.py
@@ -21,13 +21,14 @@
         allsources.append(os.path.normpath(src))
     return Extension(name=modname, sources=allsources, **kwds)
 
-def compile(tmpdir, ext, compiler_verbose=0, target_extention='capi'):
+def compile(tmpdir, ext, compiler_verbose=0, target_extention=None,
+            embedding=False):
     """Compile a C extension module using distutils."""
 
     saved_environ = os.environ.copy()
     try:
         outputfilename = _build(tmpdir, ext, compiler_verbose,
-                                target_extention)
+                                target_extention, embedding)
         outputfilename = os.path.abspath(outputfilename)
     finally:
         # workaround for a distutils bugs where some env vars can
@@ -49,7 +50,19 @@
     if value is Ellipsis:
         del config_vars[name]
 
-def _build(tmpdir, ext, compiler_verbose=0, target_extention='capi'):
+def _win32_hack_for_embedding():
+    from distutils.msvc9compiler import MSVCCompiler
+    if not hasattr(MSVCCompiler, '_remove_visual_c_ref_CFFI_BAK'):
+        MSVCCompiler._remove_visual_c_ref_CFFI_BAK = \
+            MSVCCompiler._remove_visual_c_ref
+    MSVCCompiler._remove_visual_c_ref = lambda self,manifest_file: 
manifest_file
+
+def _win32_unhack_for_embedding():
+    MSVCCompiler._remove_visual_c_ref = \
+        MSVCCompiler._remove_visual_c_ref_CFFI_BAK
+
+def _build(tmpdir, ext, compiler_verbose=0, target_extention=None,
+           embedding=False):
     # XXX compact but horrible :-(
     from distutils.core import Distribution
     import distutils.errors, distutils.log
@@ -62,10 +75,17 @@
     options['build_temp'] = ('ffiplatform', tmpdir)
     #
     try:
+        if sys.platform == 'win32' and embedding:
+            _win32_hack_for_embedding()
         old_level = distutils.log.set_threshold(0) or 0
         old_SO = _save_val('SO')
         old_EXT_SUFFIX = _save_val('EXT_SUFFIX')
         try:
+            if target_extention is None:
+                if embedding:
+                    target_extention = 'system'
+                else:
+                    target_extention = 'capi'
             if target_extention == 'capi':
                 pass    # keep the values already in 'SO' and 'EXT_SUFFIX'
             else:
@@ -84,6 +104,8 @@
             distutils.log.set_threshold(old_level)
             _restore_val('SO', old_SO)
             _restore_val('EXT_SUFFIX', old_EXT_SUFFIX)
+            if sys.platform == 'win32' and embedding:
+                _win32_unhack_for_embedding()
     except (distutils.errors.CompileError,
             distutils.errors.LinkError) as e:
         raise VerificationError('%s: %s' % (e.__class__.__name__, e))
diff --git a/cffi/recompiler.py b/cffi/recompiler.py
--- a/cffi/recompiler.py
+++ b/cffi/recompiler.py
@@ -1365,7 +1365,8 @@
     if ffi._windows_unicode:
         ffi._apply_windows_unicode(kwds)
     if preamble is not None:
-        if ffi._embedding is not None:
+        embedding = (ffi._embedding is not None)
+        if embedding:
             ffi._apply_embedding_fix(kwds)
         if c_file is None:
             c_file, parts = _modname_to_file(tmpdir, module_name,
@@ -1378,16 +1379,12 @@
         ext = ffiplatform.get_extension(ext_c_file, module_name, **kwds)
         updated = make_c_source(ffi, module_name, preamble, c_file)
         if call_c_compiler:
-            if target_extention is None:
-                if ffi._embedding is None:
-                    target_extention = 'capi'
-                else:
-                    target_extention = 'system'
             cwd = os.getcwd()
             try:
                 os.chdir(tmpdir)
                 outputfilename = ffiplatform.compile('.', ext, 
compiler_verbose,
-                                                     target_extention)
+                                                     target_extention,
+                                                     embedding=embedding)
             finally:
                 os.chdir(cwd)
             return outputfilename
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to