Armin Rigo avatar Armin Rigo committed b1db1d0

The llinterp cannot convert random exception classes from random
pure Python runs. When we get one, convert it to UnknownException.

Comments (0)

Files changed (3)


 import py
 from pypy.rpython.lltypesystem import lltype, llmemory, lloperation
-from pypy.rpython.llinterp import LLException
+from pypy.rpython.exceptiondata import UnknownException
 from pypy.rlib.jit import JitDriver, dont_look_inside, vref_None
 from pypy.rlib.jit import virtual_ref, virtual_ref_finish, InvalidVirtualRef
 from pypy.rlib.jit import non_virtual_ref
             return res
         py.test.raises(InvalidVirtualRef, "fn(10)")
-        py.test.raises(LLException, "self.meta_interp(fn, [10])")
+        py.test.raises(UnknownException, "self.meta_interp(fn, [10])")
     def test_call_virtualref_already_forced(self):
         myjitdriver = JitDriver(greens = [], reds = ['n', 'res'])


     rstackovf._StackOverflow: True,
+class UnknownException(Exception):
+    pass
 class AbstractExceptionData:
     """Public information for the code generators to help with exceptions."""
         return example
     def get_standard_ll_exc_instance_by_class(self, exceptionclass):
+        if exceptionclass not in self.standardexceptions:
+            raise UnknownException(exceptionclass)
         clsdef = self.rtyper.annotator.bookkeeper.getuniqueclassdef(
         return self.get_standard_ll_exc_instance(self.rtyper, clsdef)


 from pypy.rpython.lltypesystem.lltype import typeOf, Void, malloc, free
 from pypy.rpython.llinterp import LLInterpreter, LLException
 from pypy.rpython.rmodel import inputconst
-from pypy.rpython.annlowlevel import hlstr
+from pypy.rpython.annlowlevel import hlstr, llhelper
+from pypy.rpython.exceptiondata import UnknownException
 from pypy.translator.translator import TranslationContext, graphof
 from pypy.rpython.lltypesystem import lltype
 from pypy.annotation import model as annmodel
     res = interpret(f, [])
     assert not res
+def test_userdefined_exception():
+    class FooError(Exception):
+        pass
+    def g():
+        raise FooError
+    g_func = llhelper(lltype.Ptr(lltype.FuncType([], lltype.Void)), g)
+    def f():
+        g_func()
+    e = py.test.raises(UnknownException, interpret, f, [])
+    assert e.value.args[0] is FooError
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.