[pypy-svn] r49061 - in pypy/branch/rewrite-compilation-logic/pypy: rlib rpython/lltypesystem rpython/lltypesystem/test rpython/module translator/c translator/tool

fijal at codespeak.net fijal at codespeak.net
Sun Nov 25 01:19:36 CET 2007


Author: fijal
Date: Sun Nov 25 01:19:35 2007
New Revision: 49061

Modified:
   pypy/branch/rewrite-compilation-logic/pypy/rlib/rstack.py
   pypy/branch/rewrite-compilation-logic/pypy/rpython/lltypesystem/rffi.py
   pypy/branch/rewrite-compilation-logic/pypy/rpython/lltypesystem/test/test_rffi.py
   pypy/branch/rewrite-compilation-logic/pypy/rpython/module/ll_strtod.py
   pypy/branch/rewrite-compilation-logic/pypy/translator/c/genc.py
   pypy/branch/rewrite-compilation-logic/pypy/translator/c/node.py
   pypy/branch/rewrite-compilation-logic/pypy/translator/tool/cbuild.py
Log:
* Move few modules to use new interface
* Whack c backend until it can cope with ExternalCompilationInfo
* Whack a bit test_rffi, still failures


Modified: pypy/branch/rewrite-compilation-logic/pypy/rlib/rstack.py
==============================================================================
--- pypy/branch/rewrite-compilation-logic/pypy/rlib/rstack.py	(original)
+++ pypy/branch/rewrite-compilation-logic/pypy/rlib/rstack.py	Sun Nov 25 01:19:35 2007
@@ -9,7 +9,7 @@
 from pypy.rpython.extregistry import ExtRegistryEntry
 from pypy.rpython.lltypesystem import rffi, lltype
 from pypy.rpython.controllerentry import Controller, SomeControlledInstance
-
+from pypy.translator.tool.cbuild import ExternalCompilationInfo
 
 def stack_unwind():
     if we_are_translated():
@@ -33,7 +33,11 @@
     else:
         return len(inspect.stack())
 
-stack_too_big = rffi.llexternal('LL_stack_too_big', [], rffi.INT, includes=['src/stack.h'], _callable=lambda: 0)
+compilation_info = ExternalCompilationInfo(includes=['src/stack.h'])
+
+stack_too_big = rffi.llexternal('LL_stack_too_big', [], rffi.INT,
+                                compilation_info=compilation_info,
+                                _callable=lambda: 0)
 
 def stack_check():
     if stack_too_big():

Modified: pypy/branch/rewrite-compilation-logic/pypy/rpython/lltypesystem/rffi.py
==============================================================================
--- pypy/branch/rewrite-compilation-logic/pypy/rpython/lltypesystem/rffi.py	(original)
+++ pypy/branch/rewrite-compilation-logic/pypy/rpython/lltypesystem/rffi.py	Sun Nov 25 01:19:35 2007
@@ -45,6 +45,8 @@
                 don't bother releasing the GIL.  An explicit True or False
                 overrides this logic.
     """
+    if _callable is not None:
+        assert callable(_callable)
     ext_type = lltype.FuncType(args, result)
     if _callable is None:
         _callable = ll2ctypes.LL2CtypesCallable(ext_type, calling_conv)

Modified: pypy/branch/rewrite-compilation-logic/pypy/rpython/lltypesystem/test/test_rffi.py
==============================================================================
--- pypy/branch/rewrite-compilation-logic/pypy/rpython/lltypesystem/test/test_rffi.py	(original)
+++ pypy/branch/rewrite-compilation-logic/pypy/rpython/lltypesystem/test/test_rffi.py	Sun Nov 25 01:19:35 2007
@@ -17,14 +17,15 @@
 
 def test_basic():
     c_source = py.code.Source("""
-    int z(int x)
+    int someexternalfunction(int x)
     {
         return (x + 3);
     }
     """)
 
     eci = ExternalCompilationInfo(separate_module_sources=[c_source])
-    z = llexternal('z', [Signed], Signed, eci)
+    z = llexternal('someexternalfunction', [Signed], Signed,
+                   compilation_info=eci)
 
     def f():
         return z(8)
@@ -33,14 +34,16 @@
     assert xf() == 8+3
 
 def test_hashdefine():
-    c_source = """
+    h_source = """
     #define X(i) (i+3)
     """
 
-    c_file = udir.join("stuff.c")
-    c_file.write(c_source)
+    h_file = udir.join("stuff.h")
+    h_file.write(h_source)
 
-    z = llexternal('X', [Signed], Signed, includes=[str(c_file)])
+    eci = ExternalCompilationInfo(includes=['stuff.h'],
+                                  include_dirs=[udir])
+    z = llexternal('X', [Signed], Signed, compilation_info=eci)
 
     def f():
         return z(8)
@@ -49,7 +52,8 @@
     assert xf() == 8+3
 
 def test_string():
-    z = llexternal('strlen', [CCHARP], Signed, includes=['string.h'])
+    eci = ExternalCompilationInfo(includes=['string.h'])
+    z = llexternal('strlen', [CCHARP], Signed, compilation_info=eci)
 
     def f():
         s = str2charp("xxx")
@@ -72,7 +76,8 @@
         return ret;
     }
     """)
-    z = llexternal('f', [CCHARP], CCHARP, sources=[c_source])
+    eci = ExternalCompilationInfo(separate_module_sources=[c_source])
+    z = llexternal('f', [CCHARP], CCHARP, compilation_info=eci)
 
     def f():
         s = str2charp("xxx")
@@ -99,7 +104,8 @@
         return (l);
     }
     """
-    z = llexternal('f', [CCHARPP], Signed, sources=[c_source])
+    eci = ExternalCompilationInfo(separate_module_sources=[c_source])
+    z = llexternal('f', [CCHARPP], Signed, compilation_info=eci)
 
     def f():
         l = ["xxx", "x", "xxxx"]
@@ -113,16 +119,21 @@
 
 def test_struct():
     h_source = """
+    #ifndef _MY_SOURCE_H
+    #define _MY_SOURCE_H
     struct xx {
        int one;
        char two;
        int three;
     };
+    #endif
     """
     h_file = udir.join("structxx.h")
     h_file.write(h_source)
     
     c_source = """
+    #include <structxx.h>
+    
     int f(struct xx* z)
     {
       return (z->one + z->three);
@@ -130,8 +141,12 @@
     """
     TP = CStructPtr('xx', ('one', INT), ('two', Char), ('three', INT))
 
-    z = llexternal('f', [TP], INT, sources=[c_source],
-                   includes=[str(h_file)], include_dirs=[udir])
+    eci = ExternalCompilationInfo(
+        includes=['structxx.h'],
+        include_dirs=[udir],
+        separate_module_sources=[c_source]
+    )
+    z = llexternal('f', [TP], INT, compilation_info=eci)
 
     def f():
         struct = lltype.malloc(TP.TO, flavor='raw')

Modified: pypy/branch/rewrite-compilation-logic/pypy/rpython/module/ll_strtod.py
==============================================================================
--- pypy/branch/rewrite-compilation-logic/pypy/rpython/module/ll_strtod.py	(original)
+++ pypy/branch/rewrite-compilation-logic/pypy/rpython/module/ll_strtod.py	Sun Nov 25 01:19:35 2007
@@ -3,7 +3,6 @@
 from pypy.rpython.extfunc import BaseLazyRegistering, extdef, registering
 from pypy.rlib import rarithmetic
 from pypy.rpython.lltypesystem import lltype, rffi
-from pypy.translator.tool.cbuild import cache_c_module
 from pypy.tool.autopath import pypydir
 from pypy.rpython.ootypesystem import ootype
 from pypy.rlib import rposix

Modified: pypy/branch/rewrite-compilation-logic/pypy/translator/c/genc.py
==============================================================================
--- pypy/branch/rewrite-compilation-logic/pypy/translator/c/genc.py	(original)
+++ pypy/branch/rewrite-compilation-logic/pypy/translator/c/genc.py	Sun Nov 25 01:19:35 2007
@@ -171,12 +171,9 @@
     def compile(self):
         assert self.c_source_filename 
         assert not self._compiled
-        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.c_source_filename.purebasename, self.eci,
+                         tmpdir=self.c_source_filename.dirpath())
         self._compiled = True
 
     def _make_wrapper_module(self):
@@ -716,11 +713,9 @@
         print >> fi, line
 
     eci.write_c_header(fi)
+    eci = eci.convert_sources_to_files()
     fi.close()
 
-    for source in extra_info.get('sources', []):
-        print >> f, source
-
     if database.translator is None or database.translator.rtyper is None:
         preimplementationlines = []
     else:
@@ -743,10 +738,13 @@
     #
     pypy_include_dir = autopath.this_dir
     f = targetdir.join('setup.py').open('w')
+    include_dirs = eci.include_dirs
+    library_dirs = eci.library_dirs
+    libraries = eci.libraries
     f.write(SETUP_PY % locals())
     f.close()
 
-    return filename, sg.getextrafiles()
+    return filename, sg.getextrafiles() + list(eci.separate_module_files)
 
 
 SETUP_PY = '''

Modified: pypy/branch/rewrite-compilation-logic/pypy/translator/c/node.py
==============================================================================
--- pypy/branch/rewrite-compilation-logic/pypy/translator/c/node.py	(original)
+++ pypy/branch/rewrite-compilation-logic/pypy/translator/c/node.py	Sun Nov 25 01:19:35 2007
@@ -692,8 +692,9 @@
         self.db = db
         self.T = T
         self.obj = obj
-        if hasattr(obj, 'includes') and not db.need_sandboxing(obj):
-            self.includes = obj.includes
+        # XXX # what this obscure code is doing???
+        self.eci = getattr(obj, 'eci', ExternalCompilationInfo())
+        if self.eci.includes and not db.need_sandboxing(obj):
             self.name = forcename or self.basename()
         else:
             self.name = (forcename or
@@ -706,8 +707,6 @@
         self.ptrname = self.name
 
     def make_funcgens(self):
-        if hasattr(self.obj, 'sources'):
-            self.sources = self.obj.sources
         self.funcgens = select_function_code_generators(self.obj, self.db, self.name)
         if self.funcgens:
             argnames = self.funcgens[0].argnames()  #Assume identical for all funcgens
@@ -827,6 +826,7 @@
     elif getattr(fnobj, 'external', None) == 'C':
         if sandbox:
             return sandbox_stub(fnobj, db)
+        # XXX broken
         if hasattr(fnobj, 'includes'):
             return []   # assume no wrapper needed
         else:

Modified: pypy/branch/rewrite-compilation-logic/pypy/translator/tool/cbuild.py
==============================================================================
--- pypy/branch/rewrite-compilation-logic/pypy/translator/tool/cbuild.py	(original)
+++ pypy/branch/rewrite-compilation-logic/pypy/translator/tool/cbuild.py	Sun Nov 25 01:19:35 2007
@@ -179,7 +179,7 @@
         opt += '/Op'
     gcv['OPT'] = opt
 
-def compile_c_module(cfiles, modbasename, eci):
+def compile_c_module(cfiles, modbasename, eci, tmpdir=None):
     #try:
     #    from distutils.log import set_threshold
     #    set_threshold(10000)
@@ -187,7 +187,8 @@
     #    print "ERROR IMPORTING"
     #    pass
     cfiles = [py.path.local(f) for f in cfiles]
-    tmpdir = udir.join("module_cache").ensure(dir=1)
+    if tmpdir is None:
+        tmpdir = udir.join("module_cache").ensure(dir=1)
     num = 0
     cfiles += eci.separate_module_files
     include_dirs = list(eci.include_dirs)



More information about the Pypy-commit mailing list