[pypy-svn] r57082 - in pypy/branch/isinstance-refactor/pypy: interpreter objspace/flow objspace/flow/test

arigo at codespeak.net arigo at codespeak.net
Thu Aug 7 19:47:42 CEST 2008


Author: arigo
Date: Thu Aug  7 19:47:41 2008
New Revision: 57082

Modified:
   pypy/branch/isinstance-refactor/pypy/interpreter/baseobjspace.py
   pypy/branch/isinstance-refactor/pypy/objspace/flow/objspace.py
   pypy/branch/isinstance-refactor/pypy/objspace/flow/test/test_objspace.py
Log:
Delicate fixes.


Modified: pypy/branch/isinstance-refactor/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/branch/isinstance-refactor/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/branch/isinstance-refactor/pypy/interpreter/baseobjspace.py	Thu Aug  7 19:47:41 2008
@@ -654,8 +654,13 @@
     def exception_match(self, w_exc_type, w_check_class):
         """Checks if the given exception type matches 'w_check_class'."""
         if self.is_w(w_exc_type, w_check_class):
-            return True
-        return self.abstract_issubclass_w(w_exc_type, w_check_class)
+            return True   # fast path (also here to handle string exceptions)
+        try:
+            return self.abstract_issubclass_w(w_exc_type, w_check_class)
+        except OperationError, e:
+            if e.match(self, self.w_TypeError):   # string exceptions maybe
+                return False
+            raise
 
     def call(self, w_callable, w_args, w_kwds=None):
         args = Arguments.frompacked(self, w_args, w_kwds)

Modified: pypy/branch/isinstance-refactor/pypy/objspace/flow/objspace.py
==============================================================================
--- pypy/branch/isinstance-refactor/pypy/objspace/flow/objspace.py	(original)
+++ pypy/branch/isinstance-refactor/pypy/objspace/flow/objspace.py	Thu Aug  7 19:47:41 2008
@@ -194,6 +194,20 @@
         from pypy.objspace.flow import specialcase
         specialcase.setup(self)
 
+    def exception_match(self, w_exc_type, w_check_class):
+        try:
+            check_class = self.unwrap(w_check_class)
+        except UnwrapException:
+            raise Exception, "non-constant except guard"
+        if not isinstance(check_class, tuple):
+            # the simple case
+            return ObjSpace.exception_match(self, w_exc_type, w_check_class)
+        # checking a tuple of classes
+        for w_klass in self.unpacktuple(w_check_class):
+            if ObjSpace.exception_match(self, w_exc_type, w_klass):
+                return True
+        return False
+
     def getconstclass(space, w_cls):
         try:
             ecls = space.unwrap(w_cls)

Modified: pypy/branch/isinstance-refactor/pypy/objspace/flow/test/test_objspace.py
==============================================================================
--- pypy/branch/isinstance-refactor/pypy/objspace/flow/test/test_objspace.py	(original)
+++ pypy/branch/isinstance-refactor/pypy/objspace/flow/test/test_objspace.py	Thu Aug  7 19:47:41 2008
@@ -1,7 +1,7 @@
 import new
 import py
 from pypy.objspace.flow.model import Constant, Block, Link, Variable, traverse
-from pypy.objspace.flow.model import flatten
+from pypy.objspace.flow.model import flatten, mkentrymap
 from pypy.interpreter.argument import Arguments
 from pypy.translator.simplify import simplify_graph
 from pypy.objspace.flow.objspace import FlowObjSpace 
@@ -416,6 +416,27 @@
         x = self.codetest(self.catch_simple_call)
 
     #__________________________________________________________
+    def multiple_catch_simple_call():
+        try:
+            user_defined_function()
+        except (IndexError, OSError):
+            return -1
+        return 0
+    
+    def test_multiple_catch_simple_call(self):
+        graph = self.codetest(self.multiple_catch_simple_call)
+        simplify_graph(graph)
+        assert self.all_operations(graph) == {'simple_call': 1}
+        entrymap = mkentrymap(graph)
+        links = entrymap[graph.returnblock]
+        assert len(links) == 3
+        assert (dict.fromkeys([link.exitcase for link in links]) ==
+                dict.fromkeys([None, IndexError, OSError]))
+        links = entrymap[graph.exceptblock]
+        assert len(links) == 1
+        assert links[0].exitcase is Exception
+
+    #__________________________________________________________
     def dellocal():
         x = 1
         del x



More information about the Pypy-commit mailing list