[pypy-svn] r24520 - in pypy/dist/pypy/rpython: . memory/test test
cfbolz at codespeak.net
cfbolz at codespeak.net
Fri Mar 17 14:53:55 CET 2006
Author: cfbolz
Date: Fri Mar 17 14:53:48 2006
New Revision: 24520
Modified:
pypy/dist/pypy/rpython/llinterp.py
pypy/dist/pypy/rpython/memory/test/test_llinterpsim.py
pypy/dist/pypy/rpython/test/test_llinterp.py
Log:
use the information provided in lltypesystem/lloperation.py to check whether an
operation is expected to raise a certain exception.
Modified: pypy/dist/pypy/rpython/llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/llinterp.py (original)
+++ pypy/dist/pypy/rpython/llinterp.py Fri Mar 17 14:53:48 2006
@@ -1,6 +1,6 @@
from pypy.objspace.flow.model import FunctionGraph, Constant, Variable, c_last_exception
from pypy.rpython.rarithmetic import intmask, r_uint, ovfcheck, r_longlong, r_ulonglong
-from pypy.rpython.lltypesystem import lltype, llmemory
+from pypy.rpython.lltypesystem import lltype, llmemory, lloperation
from pypy.rpython.memory import lladdress
from pypy.rpython.ootypesystem import ootype
@@ -91,6 +91,20 @@
frame = frame.f_back
return roots
+ def find_exception(self, exc):
+ assert isinstance(exc, LLException)
+ import exceptions
+ klass, inst = exc.args[0], exc.args[1]
+ # indirect way to invoke fn_pyexcclass2exc, for memory/test/test_llinterpsim
+ f = self.typer.getexceptiondata().fn_pyexcclass2exc
+ obj = self.typer.type_system.deref(f)
+ ll_pyexcclass2exc_graph = obj.graph
+ for cls in exceptions.__dict__.values():
+ if type(cls) is type(Exception):
+ if self.eval_graph(ll_pyexcclass2exc_graph, [lltype.pyobjectptr(cls)]).typeptr == klass:
+ return cls
+ raise ValueError, "couldn't match exception"
+
# implementations of ops from flow.operation
from pypy.objspace.flow.operation import FunctionByName
@@ -106,6 +120,7 @@
def checkadr(addr):
return lltype.typeOf(addr) == llmemory.Address
+
class LLFrame(object):
def __init__(self, graph, args, llinterpreter, f_back=None):
@@ -258,7 +273,18 @@
vals.insert(0, operation.result.concretetype)
try:
retval = ophandler(*vals)
- except LLException:
+ except LLException, e:
+ # safety check check that the operation is allowed to raise that
+ # exception
+ if operation.opname in lloperation.LL_OPERATIONS:
+ canraise = lloperation.LL_OPERATIONS[operation.opname].canraise
+ if Exception not in canraise:
+ exc = self.llinterpreter.find_exception(e)
+ for canraiseexc in canraise:
+ if issubclass(exc, canraiseexc):
+ break
+ else:
+ raise TypeError("the operation %s is not expected to raise %s" % (operation, exc))
self.handle_cleanup(operation, exception=True)
raise
else:
Modified: pypy/dist/pypy/rpython/memory/test/test_llinterpsim.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/test/test_llinterpsim.py (original)
+++ pypy/dist/pypy/rpython/memory/test/test_llinterpsim.py Fri Mar 17 14:53:48 2006
@@ -11,7 +11,7 @@
from pypy.rpython.memory.lltypesimulation import pyobjectptr
from pypy.rpython.memory import gclltype
-from pypy.rpython.test.test_llinterp import timelog, gengraph, find_exception
+from pypy.rpython.test.test_llinterp import timelog, gengraph
def setup_module(mod):
mod.logstate = py.log._getstate()
@@ -60,7 +60,7 @@
interp, graph = get_interpreter(func, values, view, viewbefore, policy,
someobjects)
info = py.test.raises(LLException, "interp.eval_graph(graph, values)")
- assert find_exception(info.value, interp) is exc, "wrong exception type"
+ assert interp.find_exception(info.value) is exc, "wrong exception type"
#__________________________________________________________________
# tests
Modified: pypy/dist/pypy/rpython/test/test_llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_llinterp.py (original)
+++ pypy/dist/pypy/rpython/test/test_llinterp.py Fri Mar 17 14:53:48 2006
@@ -1,7 +1,7 @@
import py
from pypy.rpython.lltypesystem.lltype import typeOf, pyobjectptr, Ptr, PyObject, Void
-from pypy.rpython.llinterp import LLInterpreter, LLException,log
+from pypy.rpython.llinterp import LLInterpreter, LLException, log
from pypy.rpython.rmodel import inputconst
from pypy.translator.translator import TranslationContext
from pypy.rpython.rlist import *
@@ -20,19 +20,6 @@
def teardown_module(mod):
py.log._setstate(mod.logstate)
-def find_exception(exc, interp):
- assert isinstance(exc, LLException)
- import exceptions
- klass, inst = exc.args[0], exc.args[1]
- # indirect way to invoke fn_pyexcclass2exc, for memory/test/test_llinterpsim
- f = typer.getexceptiondata().fn_pyexcclass2exc
- obj = typer.type_system.deref(f)
- ll_pyexcclass2exc_graph = obj.graph
- for cls in exceptions.__dict__.values():
- if type(cls) is type(Exception):
- if interp.eval_graph(ll_pyexcclass2exc_graph, [pyobjectptr(cls)]).typeptr == klass:
- return cls
- raise ValueError, "couldn't match exception"
def timelog(prefix, call, *args, **kwds):
@@ -109,7 +96,7 @@
interp, graph = get_interpreter(func, values, view, viewbefore, policy,
someobjects, type_system=type_system)
info = py.test.raises(LLException, "interp.eval_graph(graph, values)")
- assert find_exception(info.value, interp) is exc, "wrong exception type"
+ assert interp.find_exception(info.value) is exc, "wrong exception type"
#__________________________________________________________________
# tests
More information about the Pypy-commit
mailing list