[pypy-svn] pypy jit-lsprofile: Define semantics - debug_llinterpcall can raise any exception that will

fijal commits-noreply at bitbucket.org
Fri Mar 25 18:10:39 CET 2011


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: jit-lsprofile
Changeset: r42941:4545107df688
Date: 2011-03-25 11:09 -0600
http://bitbucket.org/pypy/pypy/changeset/4545107df688/

Log:	Define semantics - debug_llinterpcall can raise any exception that
	will be wrapped

diff --git a/pypy/rpython/lltypesystem/lloperation.py b/pypy/rpython/lltypesystem/lloperation.py
--- a/pypy/rpython/lltypesystem/lloperation.py
+++ b/pypy/rpython/lltypesystem/lloperation.py
@@ -553,7 +553,8 @@
     'debug_pdb':            LLOp(),
     'debug_assert':         LLOp(tryfold=True),
     'debug_fatalerror':     LLOp(),
-    'debug_llinterpcall':   LLOp(), # Python func call 'res=arg[0](*arg[1:])'
+    'debug_llinterpcall':   LLOp(canraise=(Exception,)),
+                                    # Python func call 'res=arg[0](*arg[1:])'
                                     # in backends, abort() or whatever is fine
     'debug_start_traceback':   LLOp(),
     'debug_record_traceback':  LLOp(),

diff --git a/pypy/rlib/debug.py b/pypy/rlib/debug.py
--- a/pypy/rlib/debug.py
+++ b/pypy/rlib/debug.py
@@ -175,6 +175,7 @@
         c_pythonfunction = hop.inputconst(lltype.Void, pythonfunction)
         args_v = [hop.inputarg(hop.args_r[i], arg=i)
                   for i in range(2, hop.nb_args)]
+        hop.exception_is_here()
         return hop.genop('debug_llinterpcall', [c_pythonfunction] + args_v,
                          resulttype=RESTYPE)
 

diff --git a/pypy/rpython/test/test_llinterp.py b/pypy/rpython/test/test_llinterp.py
--- a/pypy/rpython/test/test_llinterp.py
+++ b/pypy/rpython/test/test_llinterp.py
@@ -658,3 +658,25 @@
         assert x == -42
 
     res = interpret(f, [])
+
+def test_raising_llimpl():
+    from pypy.rpython.extfunc import register_external
+
+    def external():
+        pass
+    
+    def raising():
+        raise OSError(15, "abcd")
+    
+    ext = register_external(external, [], llimpl=raising, llfakeimpl=raising)
+    
+    def f():
+        # this is a useful llfakeimpl that raises an exception
+        try:
+            external()
+            return True
+        except OSError:
+            return False
+
+    res = interpret(f, [])
+    assert not res

diff --git a/pypy/rpython/llinterp.py b/pypy/rpython/llinterp.py
--- a/pypy/rpython/llinterp.py
+++ b/pypy/rpython/llinterp.py
@@ -532,7 +532,10 @@
             raise LLFatalError(msg, LLException(ll_exc_type, ll_exc))
 
     def op_debug_llinterpcall(self, pythonfunction, *args_ll):
-        return pythonfunction(*args_ll)
+        try:
+            return pythonfunction(*args_ll)
+        except:
+            self.make_llexception()
 
     def op_debug_start_traceback(self, *args):
         pass    # xxx write debugging code here?


More information about the Pypy-commit mailing list