Author: Armin Rigo <[email protected]>
Branch: kill-someobject
Changeset: r57940:b1db1d0acb6c
Date: 2012-10-08 17:02 +0200
http://bitbucket.org/pypy/pypy/changeset/b1db1d0acb6c/

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

diff --git a/pypy/jit/metainterp/test/test_virtualref.py 
b/pypy/jit/metainterp/test/test_virtualref.py
--- a/pypy/jit/metainterp/test/test_virtualref.py
+++ b/pypy/jit/metainterp/test/test_virtualref.py
@@ -1,6 +1,6 @@
 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
@@ -564,7 +564,7 @@
             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'])
diff --git a/pypy/rpython/exceptiondata.py b/pypy/rpython/exceptiondata.py
--- a/pypy/rpython/exceptiondata.py
+++ b/pypy/rpython/exceptiondata.py
@@ -23,6 +23,9 @@
     rstackovf._StackOverflow: True,
     }
 
+class UnknownException(Exception):
+    pass
+
 
 class AbstractExceptionData:
     """Public information for the code generators to help with exceptions."""
@@ -67,6 +70,8 @@
         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(
             exceptionclass)
         return self.get_standard_ll_exc_instance(self.rtyper, clsdef)
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
@@ -4,7 +4,8 @@
 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
@@ -645,3 +646,15 @@
 
     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
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to