[pypy-svn] r66729 - in pypy/trunk/pypy/translator/c: . test

fijal at codespeak.net fijal at codespeak.net
Mon Aug 3 14:09:47 CEST 2009


Author: fijal
Date: Mon Aug  3 14:09:46 2009
New Revision: 66729

Modified:
   pypy/trunk/pypy/translator/c/dlltool.py
   pypy/trunk/pypy/translator/c/genc.py
   pypy/trunk/pypy/translator/c/test/test_dlltool.py
Log:
A bit of logic that makes targets built using dlltool to be standalone


Modified: pypy/trunk/pypy/translator/c/dlltool.py
==============================================================================
--- pypy/trunk/pypy/translator/c/dlltool.py	(original)
+++ pypy/trunk/pypy/translator/c/dlltool.py	Mon Aug  3 14:09:46 2009
@@ -6,6 +6,7 @@
 
 class CLibraryBuilder(CBuilder):
     standalone = False
+    split = True
 
     def __init__(self, *args, **kwds):
         self.functions = kwds.pop('functions')

Modified: pypy/trunk/pypy/translator/c/genc.py
==============================================================================
--- pypy/trunk/pypy/translator/c/genc.py	(original)
+++ pypy/trunk/pypy/translator/c/genc.py	Mon Aug  3 14:09:46 2009
@@ -101,6 +101,7 @@
     c_source_filename = None
     _compiled = False
     modulename = None
+    split = False
     
     def __init__(self, translator, entrypoint, config, gcpolicy=None):
         self.translator = translator
@@ -231,7 +232,8 @@
             assert not self.config.translation.instrument
             self.eci, cfile, extra = gen_source(db, modulename, targetdir,
                                                 self.eci,
-                                                defines = defines)
+                                                defines = defines,
+                                                split=self.split)
         else:
             pfname = db.get(pf)
             if self.config.translation.instrument:
@@ -428,9 +430,10 @@
         bk = self.translator.annotator.bookkeeper
         return getfunctionptr(bk.getdesc(self.entrypoint).getuniquegraph())
 
-    def cmdexec(self, args=''):
+    def cmdexec(self, args='', env=None):
         assert self._compiled
-        res = self.translator.platform.execute(self.executable_name, args)
+        res = self.translator.platform.execute(self.executable_name, args,
+                                               env=env)
         if res.returncode != 0:
             raise Exception("Returned %d" % (res.returncode,))
         return res.out
@@ -515,7 +518,7 @@
         self.path = None
         self.namespace = NameManager()
 
-    def set_strategy(self, path):
+    def set_strategy(self, path, split=True):
         all_nodes = list(self.database.globalcontainers())
         # split off non-function nodes. We don't try to optimize these, yet.
         funcnodes = []
@@ -526,7 +529,8 @@
             else:
                 othernodes.append(node)
         # for now, only split for stand-alone programs.
-        if self.database.standalone:
+        #if self.database.standalone:
+        if split:
             self.one_source_file = False
         self.funcnodes = funcnodes
         self.othernodes = othernodes
@@ -817,7 +821,7 @@
     files, eci = eci.get_module_files()
     return eci, filename, sg.getextrafiles() + list(files)
 
-def gen_source(database, modulename, targetdir, eci, defines={}):
+def gen_source(database, modulename, targetdir, eci, defines={}, split=False):
     assert not database.standalone
     if isinstance(targetdir, str):
         targetdir = py.path.local(targetdir)
@@ -852,7 +856,9 @@
     # 2) Implementation of functions and global structures and arrays
     #
     sg = SourceGenerator(database, preimplementationlines)
-    sg.set_strategy(targetdir)
+    sg.set_strategy(targetdir, split)
+    if split:
+        database.prepare_inline_helpers()
     sg.gen_readable_parts_of_source(f)
 
     gen_startupcode(f, database)

Modified: pypy/trunk/pypy/translator/c/test/test_dlltool.py
==============================================================================
--- pypy/trunk/pypy/translator/c/test/test_dlltool.py	(original)
+++ pypy/trunk/pypy/translator/c/test/test_dlltool.py	Mon Aug  3 14:09:46 2009
@@ -1,6 +1,7 @@
 
 from pypy.translator.c.dlltool import DLLDef
 from ctypes import CDLL
+import py
 
 class TestDLLTool(object):
     def test_basic(self):
@@ -15,3 +16,14 @@
         dll = CDLL(str(so))
         assert dll.f(3) == 3
         assert dll.b(10) == 12
+
+    def test_split_criteria(self):
+        def f(x):
+            return x
+
+        def b(x):
+            return x + 2
+
+        d = DLLDef('lib', [(f, [int]), (b, [int])])
+        so = d.compile()
+        assert py.path.local(so).dirpath().join('implement.c').check()



More information about the Pypy-commit mailing list