Author: Armin Rigo <ar...@tunes.org>
Branch: static-callback-embedding
Changeset: r2547:c3b68c2839d1
Date: 2016-01-07 18:20 +0100
http://bitbucket.org/cffi/cffi/changeset/c3b68c2839d1/

Log:    Fix ffi.compile() to automatically link with the python library

diff --git a/cffi/api.py b/cffi/api.py
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -535,6 +535,20 @@
                                        ('_UNICODE', '1')]
         kwds['define_macros'] = defmacros
 
+    def _apply_embedding_fix(self, kwds):
+        # must include an argument like "-lpython2.7" for the compiler
+        if sys.platform == "win32":
+            template = "python%d%d"
+            if sys.flags.debug:
+                template = template + '_d'
+        else:
+            template = "python%d.%d"
+        pythonlib = (template %
+                (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
+        libraries = kwds.get('libraries', [])
+        if pythonlib not in libraries:
+            kwds['libraries'] = libraries + [pythonlib]
+
     def set_source(self, module_name, source, source_extension='.c', **kwds):
         if hasattr(self, '_assigned_source'):
             raise ValueError("set_source() cannot be called several times "
diff --git a/cffi/recompiler.py b/cffi/recompiler.py
--- a/cffi/recompiler.py
+++ b/cffi/recompiler.py
@@ -1365,6 +1365,8 @@
     if ffi._windows_unicode:
         ffi._apply_windows_unicode(kwds)
     if preamble is not None:
+        if ffi._embedding_init_code is not None:
+            ffi._apply_embedding_fix(kwds)
         if c_file is None:
             c_file, parts = _modname_to_file(tmpdir, module_name,
                                              source_extension)
diff --git a/demo/embedding.py b/demo/embedding.py
--- a/demo/embedding.py
+++ b/demo/embedding.py
@@ -18,12 +18,6 @@
         return x + y
 """)
 
-ffi.set_source("_embedding_cffi", """
-""")
+ffi.set_source("_embedding_cffi", "")
 
-#ffi.compile()   -- should be fixed to do the right thing
-
-ffi.emit_c_code('_embedding_cffi.c')
-# then call the compiler manually with the proper options, like:
-#    gcc -shared -fPIC _embedding_cffi.c -o _embedding_cffi.so -lpython2.7
-#        -I/usr/include/python2.7
+ffi.compile(verbose=True)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to