[pypy-svn] r48863 - in pypy/branch/new-genc-tests-wrapper/pypy/translator: c llsupport llvm/test

cfbolz at codespeak.net cfbolz at codespeak.net
Tue Nov 20 19:24:53 CET 2007


Author: cfbolz
Date: Tue Nov 20 19:24:52 2007
New Revision: 48863

Modified:
   pypy/branch/new-genc-tests-wrapper/pypy/translator/c/genc.py
   pypy/branch/new-genc-tests-wrapper/pypy/translator/llsupport/modwrapper.py
   pypy/branch/new-genc-tests-wrapper/pypy/translator/llvm/test/runtest.py
Log:
(cfbolz, rxe): make the wrapper unwrap tuples recursively, raise exceptions
when they are encountered.


Modified: pypy/branch/new-genc-tests-wrapper/pypy/translator/c/genc.py
==============================================================================
--- pypy/branch/new-genc-tests-wrapper/pypy/translator/c/genc.py	(original)
+++ pypy/branch/new-genc-tests-wrapper/pypy/translator/c/genc.py	Tue Nov 20 19:24:52 2007
@@ -207,9 +207,10 @@
         return self.c_ext_module
         
     def get_entry_point(self):
+        from pypy.translator.llsupport import modwrapper
         assert self.c_ext_module 
-        return getattr(self.c_ext_module, 
-                       self.entrypoint.func_name)
+        return modwrapper.wrapfn(getattr(self.c_ext_module, 
+                                 self.entrypoint.func_name))
 
     def cleanup(self):
         assert self.c_ext_module

Modified: pypy/branch/new-genc-tests-wrapper/pypy/translator/llsupport/modwrapper.py
==============================================================================
--- pypy/branch/new-genc-tests-wrapper/pypy/translator/llsupport/modwrapper.py	(original)
+++ pypy/branch/new-genc-tests-wrapper/pypy/translator/llsupport/modwrapper.py	Tue Nov 20 19:24:52 2007
@@ -3,6 +3,7 @@
 import py
 import ctypes
 from pypy.rpython.lltypesystem import lltype 
+from pypy.rlib.rarithmetic import r_uint, r_longlong, r_ulonglong
 from pypy.rpython.lltypesystem.rstr import STR
 
 class CtypesModule:
@@ -285,6 +286,29 @@
         else:
             return self.TO_CTYPES[T]
 
+
+def unwrap(value):
+    import exceptions
+    if isinstance(value, dict):
+        # these mappings are a simple protocol to work over isolate
+        t = value["type"]
+        v = value["value"]
+        mapping = {
+            "exceptiontypename": ExceptionWrapper,
+            "r_uint": r_uint,
+            "r_longlong": r_longlong,
+            "r_ulonglong": r_ulonglong,
+            }
+        if t == "exceptiontypename":
+            exc_class = getattr(exceptions, v)
+            if exc_class is None:
+                exc_class = ExceptionWrapper(v)
+            raise exc_class()
+        if t == "tuple":
+            return StructTuple([unwrap(element) for element in v])
+        value = mapping[t](v)
+    return value
+
 def wrapfn(fn):
     def wrapped(*args):
         callargs = []
@@ -294,15 +318,20 @@
             else:
                 callargs.append(a)
         res = fn(*callargs)
-        if isinstance(res, dict):
-            # these mappings are a simple protocol to work over isolate
-            mapping = {
-                "exceptiontypename": ExceptionWrapper,
-                "tuple": StructTuple,
-                "r_uint": r_uint,
-                "r_longlong": r_longlong,
-                "r_ulonglong": r_ulonglong,
-                }
-            res = mapping[res["type"]](res["value"])
-        return res
+        return unwrap(res)
     return wrapped
+
+class ExceptionWrapper:
+    def __init__(self, class_name):
+        self.class_name = class_name
+
+    def __repr__(self):
+        return 'ExceptionWrapper(%s)' % repr(self.class_name)
+
+class StructTuple(tuple):
+    def __getattr__(self, name):
+        if name.startswith('item'):
+            i = int(name[len('item'):])
+            return self[i]
+        else:
+            raise AttributeError, name

Modified: pypy/branch/new-genc-tests-wrapper/pypy/translator/llvm/test/runtest.py
==============================================================================
--- pypy/branch/new-genc-tests-wrapper/pypy/translator/llvm/test/runtest.py	(original)
+++ pypy/branch/new-genc-tests-wrapper/pypy/translator/llvm/test/runtest.py	Tue Nov 20 19:24:52 2007
@@ -1,7 +1,6 @@
 import py
 
 from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin
-from pypy.rlib.rarithmetic import r_uint, r_longlong, r_ulonglong
 from pypy.translator.llvm.buildllvm import llvm_is_on_path, llvm_version, gcc_version
 from pypy.translator.llvm.genllvm import GenLLVM
 from pypy.annotation.model import lltype_to_annotation
@@ -79,20 +78,6 @@
 
 #______________________________________________________________________________
 
-class ExceptionWrapper:
-    def __init__(self, class_name):
-        self.class_name = class_name
-
-    def __repr__(self):
-        return 'ExceptionWrapper(%s)' % repr(self.class_name)
-
-class StructTuple(tuple):
-    def __getattr__(self, name):
-        if name.startswith('item'):
-            i = int(name[len('item'):])
-            return self[i]
-        else:
-            raise AttributeError, name
 
 def genllvm_compile(function,
                     annotation,
@@ -203,20 +188,11 @@
 
     def interpret(self, fn, args, annotation=None):
         fn = self._compile(fn, args, annotation)
-        res = fn(*args)
-        if isinstance(res, ExceptionWrapper):
-            raise res
-        return res
+        return fn(*args)
     
     def interpret_raises(self, exception, fn, args):
         import exceptions # needed by eval
-        try:
-            self.interpret(fn, args)
-        except ExceptionWrapper, ex:
-            assert issubclass(eval(ex.class_name), exception)
-            return True
-        else:
-            assert False, 'function did raise no exception at all'
+        return py.test.raises(exception, self.interpret, fn, args)
 
     def float_eq(self, x, y):
         diff = abs(x-y)



More information about the Pypy-commit mailing list