[pypy-svn] r47536 - in pypy/dist/pypy: rlib rpython/lltypesystem translator/c translator/tool

arigo at codespeak.net arigo at codespeak.net
Thu Oct 18 12:23:41 CEST 2007


Author: arigo
Date: Thu Oct 18 12:23:40 2007
New Revision: 47536

Modified:
   pypy/dist/pypy/rlib/libffi.py
   pypy/dist/pypy/rpython/lltypesystem/rffi.py
   pypy/dist/pypy/translator/c/genc.py
   pypy/dist/pypy/translator/c/node.py
   pypy/dist/pypy/translator/tool/cbuild.py
Log:
* proper library_dirs support in genc
* typos in libffi


Modified: pypy/dist/pypy/rlib/libffi.py
==============================================================================
--- pypy/dist/pypy/rlib/libffi.py	(original)
+++ pypy/dist/pypy/rlib/libffi.py	Thu Oct 18 12:23:40 2007
@@ -18,7 +18,7 @@
 lib_dirs = []
 pot_lib = py.path.local('/usr/lib/libffi')
 if pot_lib.check():
-    include_dirs.append(str(pot_lib))
+    lib_dirs.append(str(pot_lib))
 
 FFI_TYPE_P = lltype.Ptr(lltype.ForwardReference())
 FFI_TYPE_PP = rffi.CArrayPtr(FFI_TYPE_P)
@@ -27,7 +27,7 @@
     _includes_ = includes
     _libraries_ = ['ffi']
     _include_dirs_ = include_dirs
-    _lib_dirs_ = lib_dirs
+    _library_dirs_ = lib_dirs
 
     RTLD_LOCAL = rffi_platform.DefinedConstantInteger('RTLD_LOCAL')
     RTLD_GLOBAL = rffi_platform.DefinedConstantInteger('RTLD_GLOBAL')
@@ -96,7 +96,7 @@
 
 def external(name, args, result, **kwds):
     return rffi.llexternal(name, args, result, includes=includes,
-                           include_dirs=include_dirs,
+                           include_dirs=include_dirs, library_dirs=lib_dirs,
                            libraries=['dl', 'ffi'], **kwds)
 
 c_dlopen = external('dlopen', [rffi.CCHARP, rffi.INT], rffi.VOIDP,

Modified: pypy/dist/pypy/rpython/lltypesystem/rffi.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/rffi.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/rffi.py	Thu Oct 18 12:23:40 2007
@@ -27,9 +27,9 @@
         return self.TP
 
 def llexternal(name, args, result, _callable=None, sources=[], includes=[],
-               libraries=[], include_dirs=[], sandboxsafe=False,
-               canraise=False, _nowrapper=False, calling_conv='c',
-               threadsafe='auto'):
+               libraries=[], include_dirs=[], library_dirs=[],
+               sandboxsafe=False, threadsafe='auto',
+               canraise=False, _nowrapper=False, calling_conv='c'):
     """Build an external function that will invoke the C function 'name'
     with the given 'args' types and 'result' type.
 
@@ -53,6 +53,7 @@
                                  includes=tuple(includes),
                                  libraries=tuple(libraries),
                                  include_dirs=tuple(include_dirs),
+                                 library_dirs=tuple(library_dirs),
                                  _callable=_callable,
                                  _safe_not_sandboxed=sandboxsafe,
                                  _debugexc=True, # on top of llinterp

Modified: pypy/dist/pypy/translator/c/genc.py
==============================================================================
--- pypy/dist/pypy/translator/c/genc.py	(original)
+++ pypy/dist/pypy/translator/c/genc.py	Thu Oct 18 12:23:40 2007
@@ -144,24 +144,26 @@
             from pypy.translator.c.symboltable import SymbolTable
             # XXX fix symboltable
             #self.symboltable = SymbolTable()
-            cfile, extra, extraincludes = gen_source(db, modulename, targetdir,
-                                                defines = defines,
-                                                exports = self.exports,
-                                                symboltable = self.symboltable,
-                                                libraries = self.libraries)
+            cfile, extra, include_dirs, library_dirs = \
+                   gen_source(db, modulename, targetdir,
+                              defines = defines,
+                              exports = self.exports,
+                              symboltable = self.symboltable,
+                              libraries = self.libraries)
         else:
             if self.config.translation.instrument:
                 defines['INSTRUMENT'] = 1
             if CBuilder.have___thread:
                 if not self.config.translation.no__thread:
                     defines['USE___THREAD'] = 1
-            cfile, extra, extraincludes = \
+            cfile, extra, include_dirs, library_dirs = \
                    gen_source_standalone(db, modulename, targetdir,
                                          entrypointname = pfname,
                                          defines = defines)
         self.c_source_filename = py.path.local(cfile)
         self.extrafiles = extra
-        self.extraincludes = extraincludes.keys()
+        self.include_dirs = include_dirs.keys()
+        self.library_dirs = library_dirs.keys()
         if self.standalone:
             self.gen_makefile(targetdir)
         return cfile
@@ -190,10 +192,11 @@
     def compile(self):
         assert self.c_source_filename 
         assert not self._compiled
-        extra_includes = self.extraincludes
+        extra_includes = self.include_dirs
         compile_c_module([self.c_source_filename] + self.extrafiles,
                          self.c_source_filename.purebasename,
                          include_dirs = [autopath.this_dir] + extra_includes,
+                         library_dirs = self.library_dirs,
                          libraries=self.libraries)
         self._compiled = True
 
@@ -251,13 +254,14 @@
             [self.c_source_filename] + self.extrafiles,
             include_dirs = [autopath.this_dir, python_inc] + extra_includes,
             libraries    = self.libraries,
+            library_dirs = self.library_dirs,
             compiler_exe = cc, profbased = profbased)
 
     def compile(self):
         assert self.c_source_filename
         assert not self._compiled
         compiler = self.getccompiler(extra_includes=[str(self.targetdir)] +
-                                     self.extraincludes)
+                                     self.include_dirs)
         if sys.platform == 'darwin':
             compiler.compile_extra.append('-mdynamic-no-pic')
         if self.config.translation.compilerflags:
@@ -623,6 +627,7 @@
     includes = {}
     sources = {}
     include_dirs = {}
+    library_dirs = {}
     for node in database.globalcontainers():
         if hasattr(node, 'includes'):
             for include in node.includes:
@@ -633,9 +638,12 @@
         if hasattr(node, 'include_dirs'):
             for include_dir in node.include_dirs:
                 include_dirs[include_dir] = True
+        if hasattr(node, 'library_dirs'):
+            for library_dir in node.library_dirs:
+                library_dirs[library_dir] = True
     includes = includes.keys()
     includes.sort()
-    return includes, sources, include_dirs
+    return includes, sources, include_dirs, library_dirs
 
 def gen_source_standalone(database, modulename, targetdir, 
                           entrypointname, defines={}): 
@@ -666,7 +674,7 @@
     for line in database.gcpolicy.pre_gc_code():
         print >> fi, line
 
-    includes, sources, include_dirs = extra_information(database)
+    includes, sources, include_dirs, library_dirs = extra_information(database)
     for include in includes:
         print >> fi, '#include <%s>' % (include,)
     fi.close()
@@ -695,7 +703,7 @@
         print >>fi, "#define INSTRUMENT_NCOUNTER %d" % n
         fi.close()
 
-    return filename, sg.getextrafiles(), include_dirs
+    return filename, sg.getextrafiles(), include_dirs, library_dirs
 
 
 def gen_source(database, modulename, targetdir, defines={}, exports={},
@@ -725,7 +733,7 @@
     for line in database.gcpolicy.pre_gc_code():
         print >> fi, line
 
-    includes, sources, include_dirs = extra_information(database)
+    includes, sources, include_dirs, library_dirs = extra_information(database)
     for include in includes:
         print >> fi, '#include <%s>' % (include,)
     fi.close()
@@ -857,7 +865,7 @@
     f.write(SETUP_PY % locals())
     f.close()
 
-    return filename, sg.getextrafiles(), include_dirs
+    return filename, sg.getextrafiles(), include_dirs, library_dirs
 
 
 SETUP_PY = '''
@@ -876,7 +884,8 @@
       ext_modules = [Extension(name = "%(modulename)s",
                             sources = ["%(modulename)s.c"],
                  extra_compile_args = extra_compile_args,
-                       include_dirs = [PYPY_INCLUDE_DIR],
+                       include_dirs = [PYPY_INCLUDE_DIR] + %(include_dirs)r,
+                       library_dirs = %(library_dirs)r,
                           libraries = %(libraries)r)])
 '''
 

Modified: pypy/dist/pypy/translator/c/node.py
==============================================================================
--- pypy/dist/pypy/translator/c/node.py	(original)
+++ pypy/dist/pypy/translator/c/node.py	Thu Oct 18 12:23:40 2007
@@ -705,6 +705,8 @@
             self.libraries = obj.libraries
         if hasattr(obj, 'include_dirs'):
             self.include_dirs = obj.include_dirs
+        if hasattr(obj, 'library_dirs'):
+            self.library_dirs = obj.library_dirs
         self.make_funcgens()
         #self.dependencies = {}
         self.typename = db.gettype(T)  #, who_asks=self)

Modified: pypy/dist/pypy/translator/tool/cbuild.py
==============================================================================
--- pypy/dist/pypy/translator/tool/cbuild.py	(original)
+++ pypy/dist/pypy/translator/tool/cbuild.py	Thu Oct 18 12:23:40 2007
@@ -39,17 +39,16 @@
         opt += '/Op'
     gcv['OPT'] = opt
 
-def compile_c_module(cfiles, modname, include_dirs=None, libraries=[]):
+def compile_c_module(cfiles, modname, include_dirs=[], libraries=[],
+                     library_dirs=[]):
     #try:
     #    from distutils.log import set_threshold
     #    set_threshold(10000)
     #except ImportError:
     #    print "ERROR IMPORTING"
     #    pass
-    if include_dirs is None:
-        include_dirs = []
-
-    library_dirs = []
+    include_dirs = list(include_dirs)
+    library_dirs = list(library_dirs)
     if sys.platform == 'darwin':    # support Fink & Darwinports
         for s in ('/sw/', '/opt/local/'):
             if s + 'include' not in include_dirs and \
@@ -75,6 +74,8 @@
                                                      str(dirpath.join(modname)))
                     for dir in [gcv['INCLUDEPY']] + list(include_dirs):
                         cmd += ' -I%s' % dir
+                    for dir in library_dirs:
+                        cmd += ' -L%s' % dir
                     os.system(cmd)
                 else:
                     from distutils.dist import Distribution



More information about the Pypy-commit mailing list