[pypy-svn] r31750 - in pypy/dist/pypy/rpython: . test

arigo at codespeak.net arigo at codespeak.net
Sun Aug 27 20:02:54 CEST 2006


Author: arigo
Date: Sun Aug 27 20:02:52 2006
New Revision: 31750

Modified:
   pypy/dist/pypy/rpython/rpbc.py
   pypy/dist/pypy/rpython/test/test_rpbc.py
Log:
Bug and fix for exception-guarded calls to classes with no constructor.
Thanks fijal.


Modified: pypy/dist/pypy/rpython/rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/rpbc.py	(original)
+++ pypy/dist/pypy/rpython/rpbc.py	Sun Aug 27 20:02:52 2006
@@ -676,6 +676,7 @@
                 # and ignore any arguments passed to the contructor.
                 r_instance = rclass.getinstancerepr(hop.rtyper, classdef)
                 example = r_instance.get_reusable_prebuilt_instance()
+                hop.exception_cannot_occur()
                 return hop.inputconst(r_instance.lowleveltype, example)
 
             v_instance = rclass.rtype_new_instance(hop.rtyper, classdef,
@@ -683,6 +684,7 @@
             if isinstance(v_instance, tuple):
                 v_instance, must_call_init = v_instance
                 if not must_call_init:
+                    hop.exception_cannot_occur()
                     return v_instance
         else:
             # instantiating a class from multiple possible classes
@@ -700,6 +702,7 @@
         if isinstance(s_init, annmodel.SomeImpossibleValue):
             assert hop.nb_args == 1, ("arguments passed to __init__, "
                                       "but no __init__!")
+            hop.exception_cannot_occur()
         else:
             hop2 = self.replace_class_with_inst_arg(
                     hop, v_instance, s_instance, call_args)

Modified: pypy/dist/pypy/rpython/test/test_rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rpbc.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rpbc.py	Sun Aug 27 20:02:52 2006
@@ -1366,6 +1366,19 @@
         res = self.interpret(f, [])
         assert res == True
 
+    def test_except_class_call(self):
+        class A:
+            pass   # no constructor
+        def f():
+            try:
+                A()
+                IndexError()
+                return 12
+            except ValueError:
+                return 23
+        res = self.interpret(f, [])
+        assert res == 12
+
 
 # We don't care about the following test_hlinvoke tests working on
 # ootype. Maybe later. This kind of thing is only used in rdict



More information about the Pypy-commit mailing list