[pypy-commit] pypy translation-cleanup: Don't call superclass method from FlowObjSpace.exception_match()

rlamy noreply at buildbot.pypy.org
Wed Sep 26 22:33:06 CEST 2012


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: translation-cleanup
Changeset: r57617:fa4e329098dc
Date: 2012-09-25 17:09 +0100
http://bitbucket.org/pypy/pypy/changeset/fa4e329098dc/

Log:	Don't call superclass method from FlowObjSpace.exception_match()

diff --git a/pypy/objspace/flow/objspace.py b/pypy/objspace/flow/objspace.py
--- a/pypy/objspace/flow/objspace.py
+++ b/pypy/objspace/flow/objspace.py
@@ -3,7 +3,7 @@
 import sys
 import operator
 import types
-from pypy.interpreter.baseobjspace import ObjSpace, Wrappable
+from pypy.interpreter.baseobjspace import ObjSpace
 from pypy.interpreter import pyframe, argument
 from pypy.objspace.flow.model import *
 from pypy.objspace.flow import operation
@@ -170,7 +170,23 @@
     def getexecutioncontext(self):
         return self.frame
 
+    def _exception_match(self, w_exc_type, w_check_class):
+        """Helper for exception_match
+
+        Handles the base case where w_check_class is a constant exception
+        type.
+        """
+        if self.is_w(w_exc_type, w_check_class):
+            return True   # fast path (also here to handle string exceptions)
+        try:
+            return self.exception_issubclass_w(w_exc_type, w_check_class)
+        except FSException, e:
+            if e.match(self, self.w_TypeError):   # string exceptions maybe
+                return False
+            raise
+
     def exception_match(self, w_exc_type, w_check_class):
+        """Checks if the given exception type matches 'w_check_class'."""
         try:
             check_class = self.unwrap(w_check_class)
         except UnwrapException:
@@ -180,11 +196,11 @@
                 "Catching %s is not valid in RPython" % check_class.__name__)
         if not isinstance(check_class, tuple):
             # the simple case
-            return ObjSpace.exception_match(self, w_exc_type, w_check_class)
+            return self._exception_match(w_exc_type, w_check_class)
         # special case for StackOverflow (see rlib/rstackovf.py)
         if check_class == rstackovf.StackOverflow:
             w_real_class = self.wrap(rstackovf._StackOverflow)
-            return ObjSpace.exception_match(self, w_exc_type, w_real_class)
+            return self._exception_match(w_exc_type, w_real_class)
         # checking a tuple of classes
         for w_klass in self.fixedview(w_check_class):
             if self.exception_match(w_exc_type, w_klass):


More information about the pypy-commit mailing list