[pypy-commit] pypy less-stringly-ops: Intercept FlowingError in FSFrame.record_block() and add frame info there

rlamy noreply at buildbot.pypy.org
Mon Aug 19 23:15:14 CEST 2013


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: less-stringly-ops
Changeset: r66238:9f35203d09ba
Date: 2013-08-09 11:46 +0100
http://bitbucket.org/pypy/pypy/changeset/9f35203d09ba/

Log:	Intercept FlowingError in FSFrame.record_block() and add frame info
	there

diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -18,9 +18,7 @@
 
 class FlowingError(Exception):
     """ Signals invalid RPython in the function being analysed"""
-    def __init__(self, frame, msg):
-        super(FlowingError, self).__init__(msg)
-        self.frame = frame
+    frame = None
 
     def __str__(self):
         msg = ['-+' * 30]
@@ -307,7 +305,7 @@
 
 def unsupportedoperation(OPCODE, msg):
     def UNSUPPORTED(self, *ignored):
-        raise FlowingError(self, "%s is not RPython" % (msg,))
+        raise FlowingError("%s is not RPython" % (msg,))
     UNSUPPORTED.func_name = OPCODE
     return UNSUPPORTED
 
@@ -510,6 +508,11 @@
             link = Link([w_result], self.graph.returnblock)
             self.recorder.crnt_block.closeblock(link)
 
+        except FlowingError as exc:
+            if exc.frame is None:
+                exc.frame = self
+            raise
+
         self.recorder = None
 
     def mergeblock(self, currentblock, currentstate):
@@ -588,7 +591,7 @@
         return Constant(self.pycode.names[index])
 
     def BAD_OPCODE(self, _):
-        raise FlowingError(self, "This operation is not RPython")
+        raise FlowingError("This operation is not RPython")
 
     def BREAK_LOOP(self, oparg):
         return SBreakLoop.singleton.unroll(self)
@@ -836,7 +839,7 @@
     def LOAD_FAST(self, varindex):
         w_value = self.locals_stack_w[varindex]
         if w_value is None:
-            raise FlowingError(self, "Local variable referenced before assignment")
+            raise FlowingError("Local variable referenced before assignment")
         self.pushvalue(w_value)
 
     def LOAD_CONST(self, constindex):
@@ -866,8 +869,8 @@
 
     def STORE_GLOBAL(self, nameindex):
         varname = self.getname_u(nameindex)
-        raise FlowingError(self,
-                "Attempting to modify global variable  %r." % (varname))
+        raise FlowingError(
+            "Attempting to modify global variable  %r." % (varname))
 
     def POP_TOP(self, oparg):
         self.popvalue()
@@ -927,7 +930,7 @@
 
     def call_function(self, oparg, w_star=None, w_starstar=None):
         if w_starstar is not None:
-            raise FlowingError(self, "Dict-unpacking is not RPython")
+            raise FlowingError("Dict-unpacking is not RPython")
         n_arguments = oparg & 0xff
         n_keywords = (oparg >> 8) & 0xff
         keywords = {}
diff --git a/rpython/flowspace/objspace.py b/rpython/flowspace/objspace.py
--- a/rpython/flowspace/objspace.py
+++ b/rpython/flowspace/objspace.py
@@ -119,7 +119,7 @@
 
     def newfunction(self, w_code, w_globals, defaults_w):
         if not all(isinstance(value, Constant) for value in defaults_w):
-            raise FlowingError(self.frame, "Dynamically created function must"
+            raise FlowingError("Dynamically created function must"
                     " have constant default values.")
         code = w_code.value
         globals = w_globals.value
@@ -138,10 +138,10 @@
     def exception_match(self, w_exc_type, w_check_class):
         """Checks if the given exception type matches 'w_check_class'."""
         if not isinstance(w_check_class, Constant):
-            raise FlowingError(self.frame, "Non-constant except guard.")
+            raise FlowingError("Non-constant except guard.")
         check_class = w_check_class.value
         if check_class in (NotImplementedError, AssertionError):
-            raise FlowingError(self.frame,
+            raise FlowingError(
                 "Catching %s is not valid in RPython" % check_class.__name__)
         if not isinstance(check_class, tuple):
             # the simple case
@@ -256,7 +256,7 @@
                 etype = e.__class__
                 msg = "getattr(%s, %s) always raises %s: %s" % (
                     obj, name, etype, e)
-                raise FlowingError(self.frame, msg)
+                raise FlowingError(msg)
             try:
                 return const(result)
             except WrapException:
@@ -351,8 +351,7 @@
             try:
                 value = getattr(__builtin__, varname)
             except AttributeError:
-                message = "global name '%s' is not defined" % varname
-                raise FlowingError(self.frame, const(message))
+                raise FlowingError("global name '%s' is not defined" % varname)
         return const(value)
 
 def make_op(cls):
diff --git a/rpython/flowspace/operation.py b/rpython/flowspace/operation.py
--- a/rpython/flowspace/operation.py
+++ b/rpython/flowspace/operation.py
@@ -58,7 +58,7 @@
                 from rpython.flowspace.flowcontext import FlowingError
                 msg = "%s%r always raises %s: %s" % (
                     self.opname, tuple(args), type(e), e)
-                raise FlowingError(frame, msg)
+                raise FlowingError(msg)
             else:
                 # don't try to constant-fold operations giving a 'long'
                 # result.  The result is probably meant to be sent to


More information about the pypy-commit mailing list