Commits

Samuele Pedroni committed b2d9f53

(cfbolz, pedronis) - add a way to control isolated and DEBUG_DEFINES for the c backend and in theory other backend specific options
- add a shortcut to cleanup isolates on the invokers

Comments (0)

Files changed (4)

pypy/tool/isolate.py

     def __repr__(self):
         return "<invoker for %r . %r>" % (self.isolate.module, self.name)
 
+    def close_isolate(self):
+        self.isolate._close()
+
 class Isolate(object):
     """
     Isolate lets load a module in a different process,

pypy/translator/driver.py

 
 
 class TranslationDriver(SimpleTaskEngine):
+    _backend_extra_options = {}
 
     def __init__(self, setopts=None, default_goal=None,
                  disable=[],
     def set_extra_goals(self, goals):
         self.extra_goals = goals
 
+    def set_backend_extra_options(self, extra_options):
+        self._backend_extra_options = extra_options
+        
     def get_info(self): # XXX more?
         d = {'backend': self.config.translation.backend}
         return d
         translator = self.translator
         cbuilder = self.cbuilder
         database = self.database
-        c_source_filename = cbuilder.generate_source(database)
+        if self._backend_extra_options.get('c_debug_defines', False):
+            defines = cbuilder.DEBUG_DEFINES
+        else:
+            defines = {}
+        c_source_filename = cbuilder.generate_source(database, defines)
         self.log.info("written: %s" % (c_source_filename,))
         if self.config.translation.dump_static_data_info:
             from pypy.translator.tool.staticsizereport import dump_static_data_info
             self.c_entryp = cbuilder.executable_name
             self.create_exe()
         else:
-            self.c_entryp = cbuilder.get_entry_point()
+            isolated = self._backend_extra_options.get('c_isolated', False)
+            self.c_entryp = cbuilder.get_entry_point(isolated=isolated)
     #
     task_compile_c = taskdef(task_compile_c, ['source_c'], "Compiling c source")
 

pypy/translator/interactive.py

     def disable(self, to_disable):
         self.driver.disable(to_disable)
 
+    def set_backend_extra_options(self, **extra_options):
+        for name in extra_options:
+            backend, option = name.split('_', 1)
+            self.ensure_backend(backend)
+        self.driver.set_backend_extra_options(extra_options)
+
     # backend independent
 
     def annotate(self, argtypes=None, **kwds):

pypy/translator/test/test_interactive.py

     res = t_f(2,3)
     assert res == 5
 
+def test_simple_compile_c_isolate():
+    from pypy.tool import isolate
+    
+    def f(x,y):
+        return x+y
+
+    t = Translation(f, [int, int])
+    t.set_backend_extra_options(c_isolated=True)
+    t_f = t.compile()
+
+    assert isinstance(t_f, isolate.IsolateInvoker)
+
+    res = t_f(2,3)
+    assert res == 5
+
+    # cleanup
+    t_f.close_isolate()
+
 def test_simple_rtype_with_type_system():
 
     def f(x,y):