[pypy-svn] r46481 - in pypy/dist/pypy/translator: . cli cli/test jvm/test oosupport oosupport/test_template

antocuni at codespeak.net antocuni at codespeak.net
Tue Sep 11 19:35:19 CEST 2007


Author: antocuni
Date: Tue Sep 11 19:35:19 2007
New Revision: 46481

Added:
   pypy/dist/pypy/translator/oosupport/support.py   (contents, props changed)
Modified:
   pypy/dist/pypy/translator/cli/support.py
   pypy/dist/pypy/translator/cli/test/runtest.py
   pypy/dist/pypy/translator/driver.py
   pypy/dist/pypy/translator/jvm/test/runtest.py
   pypy/dist/pypy/translator/jvm/test/test_builtin.py
   pypy/dist/pypy/translator/oosupport/test_template/builtin.py
Log:
use the NT os flags also for genjvm; move the patching code to oosupport/



Modified: pypy/dist/pypy/translator/cli/support.py
==============================================================================
--- pypy/dist/pypy/translator/cli/support.py	(original)
+++ pypy/dist/pypy/translator/cli/support.py	Tue Sep 11 19:35:19 2007
@@ -66,40 +66,3 @@
             f.write('%s: %d\n' % (label, self.counters[key]))
         f.close()
 
-NT_OS = dict(
-    O_RDONLY = 0x0000,
-    O_WRONLY = 0x0001,
-    O_RDWR   = 0x0002,
-    O_APPEND = 0x0008,
-    O_CREAT  = 0x0100,
-    O_TRUNC  = 0x0200,
-    O_TEXT   = 0x4000,
-    O_BINARY = 0x8000
-    )
-
-def _patch_os(defs=None):
-    """
-    Modify the value of some attributes of the os module to be sure
-    they are the same on every platform pypy is compiled on. Returns a
-    dictionary containing the original values that can be passed to
-    patch_os to rollback to the original values.
-    """
-    
-    import os
-    if defs is None:
-        defs = NT_OS
-    olddefs = {}
-    for name, value in defs.iteritems():
-        try:
-            olddefs[name] = getattr(os, name)
-        except AttributeError:
-            pass
-        setattr(os, name, value)
-    return olddefs
-
-def patch():
-    olddefs = _patch_os()
-    return olddefs,
-
-def unpatch(olddefs):
-    _patch_os(olddefs)

Modified: pypy/dist/pypy/translator/cli/test/runtest.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/runtest.py	(original)
+++ pypy/dist/pypy/translator/cli/test/runtest.py	Tue Sep 11 19:35:19 2007
@@ -21,7 +21,7 @@
 from pypy.translator.cli.database import LowLevelDatabase
 from pypy.translator.cli.sdk import SDK
 from pypy.translator.cli.entrypoint import BaseEntryPoint
-from pypy.translator.cli.support import patch, unpatch
+from pypy.translator.oosupport.support import patch_os, unpatch_os
 
 FLOAT_PRECISION = 8
 
@@ -132,11 +132,11 @@
 
 def compile_function(func, annotation=[], graph=None, backendopt=True,
                      auto_raise_exc=False, exctrans=False):
-    olddefs = patch()
+    olddefs = patch_os()
     gen = _build_gen(func, annotation, graph, backendopt, exctrans)
     gen.generate_source()
     exe_name = gen.build_exe()
-    unpatch(*olddefs) # restore original values
+    unpatch_os(olddefs) # restore original values
     return CliFunctionWrapper(exe_name, func.__name__, auto_raise_exc)
 
 def _build_gen(func, annotation, graph=None, backendopt=True, exctrans=False):

Modified: pypy/dist/pypy/translator/driver.py
==============================================================================
--- pypy/dist/pypy/translator/driver.py	(original)
+++ pypy/dist/pypy/translator/driver.py	Tue Sep 11 19:35:19 2007
@@ -647,13 +647,13 @@
                              'Generating CLI source')
 
     def task_compile_cli(self):
-        from pypy.translator.cli.support import unpatch
+        from pypy.translator.oosupport.support import unpatch_os
         from pypy.translator.cli.test.runtest import CliFunctionWrapper
         filename = self.gen.build_exe()
         self.c_entryp = CliFunctionWrapper(filename)
         # restore original os values
         if hasattr(self, 'old_cli_defs'):
-            unpatch(*self.old_cli_defs)
+            unpatch_os(self.old_cli_defs)
         
         self.log.info("Compiled %s" % filename)
         if self.standalone and self.exe_name:
@@ -724,8 +724,13 @@
                              'Generating JVM source')
 
     def task_compile_jvm(self):
+        from pypy.translator.oosupport.support import unpatch_os
         self.jvmsource.compile()
         self.c_entryp = lambda *args: eval(self.jvmsource.execute(args))
+        # restore original os values
+        if hasattr(self, 'old_cli_defs'):
+            unpatch_os(self.old_cli_defs)
+
         self.log.info("Compiled JVM source")
     task_compile_jvm = taskdef(task_compile_jvm, ['source_jvm'],
                               'Compiling JVM source')
@@ -760,9 +765,9 @@
         # patch some attributes of the os module to make sure they
         # have the same value on every platform.
         backend, ts = driver.get_backend_and_type_system()
-        if backend == 'cli':
-            from pypy.translator.cli.support import patch
-            driver.old_cli_defs = patch()
+        if backend in ('cli', 'jvm'):
+            from pypy.translator.oosupport.support import patch_os
+            driver.old_cli_defs = patch_os()
         
         target = targetspec_dic['target']
         spec = target(driver, args)

Modified: pypy/dist/pypy/translator/jvm/test/runtest.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/test/runtest.py	(original)
+++ pypy/dist/pypy/translator/jvm/test/runtest.py	Tue Sep 11 19:35:19 2007
@@ -9,6 +9,7 @@
 from pypy.rpython.ootypesystem import ootype
 from pypy.annotation.model import lltype_to_annotation
 from pypy.translator.translator import TranslationContext
+from pypy.translator.oosupport.support import patch_os, unpatch_os
 from pypy.translator.jvm.genjvm import \
      generate_source_for_function, JvmError, detect_missing_support_programs
 from pypy.translator.jvm.option import getoption
@@ -91,7 +92,9 @@
         else:
             self._func = fn
             self._ann = ann
+            olddefs = patch_os()
             self._jvm_src = generate_source_for_function(fn, ann)
+            unpatch_os(olddefs)
             if not getoption('noasm'):
                 self._jvm_src.compile()
             return JvmGeneratedSourceWrapper(self._jvm_src)

Modified: pypy/dist/pypy/translator/jvm/test/test_builtin.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/test/test_builtin.py	(original)
+++ pypy/dist/pypy/translator/jvm/test/test_builtin.py	Tue Sep 11 19:35:19 2007
@@ -5,9 +5,6 @@
 
 class TestJavaBuiltin(JvmTest, BaseTestBuiltin):
 
-    def test_os_flags(self):
-        py.test.skip('fixme!')
-
     def test_os_open_write(self):
         py.test.skip("ll_os_open is not currently implemented in the Jvm backed")
 

Added: pypy/dist/pypy/translator/oosupport/support.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/oosupport/support.py	Tue Sep 11 19:35:19 2007
@@ -0,0 +1,36 @@
+NT_OS = dict(
+    O_RDONLY = 0x0000,
+    O_WRONLY = 0x0001,
+    O_RDWR   = 0x0002,
+    O_APPEND = 0x0008,
+    O_CREAT  = 0x0100,
+    O_TRUNC  = 0x0200,
+    O_TEXT   = 0x4000,
+    O_BINARY = 0x8000
+    )
+
+def _patch_os(defs=None):
+    """
+    Modify the value of some attributes of the os module to be sure
+    they are the same on every platform pypy is compiled on. Returns a
+    dictionary containing the original values that can be passed to
+    patch_os to rollback to the original values.
+    """
+    
+    import os
+    if defs is None:
+        defs = NT_OS
+    olddefs = {}
+    for name, value in defs.iteritems():
+        try:
+            olddefs[name] = getattr(os, name)
+        except AttributeError:
+            pass
+        setattr(os, name, value)
+    return olddefs
+
+def patch_os():
+    return _patch_os()
+
+def unpatch_os(olddefs):
+    _patch_os(olddefs)

Modified: pypy/dist/pypy/translator/oosupport/test_template/builtin.py
==============================================================================
--- pypy/dist/pypy/translator/oosupport/test_template/builtin.py	(original)
+++ pypy/dist/pypy/translator/oosupport/test_template/builtin.py	Tue Sep 11 19:35:19 2007
@@ -9,7 +9,7 @@
 class BaseTestBuiltin(BaseTestRbuiltin):
 
     def test_os_flags(self):
-        from pypy.translator.cli.support import NT_OS
+        from pypy.translator.oosupport.support import NT_OS
         def fn():
             return os.O_CREAT
         assert self.interpret(fn, []) == NT_OS['O_CREAT']


More information about the pypy-svn mailing list