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

arigo at codespeak.net arigo at codespeak.net
Sun Sep 23 17:55:44 CEST 2007


Author: arigo
Date: Sun Sep 23 17:55:44 2007
New Revision: 46842

Modified:
   pypy/dist/pypy/rpython/ootypesystem/rdict.py
   pypy/dist/pypy/rpython/rdict.py
   pypy/dist/pypy/rpython/test/test_rdict.py
Log:
Dict iterators must tell that they could raise RuntimeError
even in the lltypesystem, even though they don't really do so in
the current implementation.  This is needed because the annotator
thinks that they can (see test).


Modified: pypy/dist/pypy/rpython/ootypesystem/rdict.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/rdict.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/rdict.py	Sun Sep 23 17:55:44 2007
@@ -360,10 +360,6 @@
         ITER = ootype.DictItemsIterator(KEYTYPE, VALUETYPE)
         return ootype.Record({"iterator": ITER})
 
-    def _next_implicit_exceptions(self, hop):
-        hop.has_implicit_exception(StopIteration)
-        hop.has_implicit_exception(RuntimeError)
-
 def ll_dictiter(ITER, d):
     iter = ootype.new(ITER)
     iter.iterator = d.ll_get_items_iterator()

Modified: pypy/dist/pypy/rpython/rdict.py
==============================================================================
--- pypy/dist/pypy/rpython/rdict.py	(original)
+++ pypy/dist/pypy/rpython/rdict.py	Sun Sep 23 17:55:44 2007
@@ -89,9 +89,6 @@
         citerptr = hop.inputconst(lltype.Void, self.lowleveltype)
         return hop.gendirectcall(self.ll_dictiter, citerptr, v_dict)
 
-    def _next_implicit_exceptions(self, hop):
-        hop.has_implicit_exception(StopIteration)
-
     def rtype_next(self, hop):
         variant = self.variant
         v_iter, = hop.inputargs(self)
@@ -100,7 +97,9 @@
             c1 = hop.inputconst(lltype.Void, None)
         else:
             c1 = hop.inputconst(lltype.Void, hop.r_result.lowleveltype)
-        self._next_implicit_exceptions(hop) # record that we know about it
+        # record that we know about these two possible exceptions
+        hop.has_implicit_exception(StopIteration)
+        hop.has_implicit_exception(RuntimeError)
         hop.exception_is_here()
         v = hop.gendirectcall(self.ll_dictnext, v_iter, v_func, c1)
         if variant == 'keys':

Modified: pypy/dist/pypy/rpython/test/test_rdict.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rdict.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rdict.py	Sun Sep 23 17:55:44 2007
@@ -686,6 +686,21 @@
         assert lltype.typeOf(res.item1) == lltype.typeOf(res.item2)
         assert lltype.typeOf(res.item1) == lltype.typeOf(res.item3)
 
+    def test_resize_during_iteration(self):
+        def func():
+            d = {5: 1, 6: 2, 7: 3}
+            try:
+                for key, value in d.iteritems():
+                    d[key^16] = value*2
+            except RuntimeError:
+                pass
+            total = 0
+            for key in d:
+                total += key
+            return total
+        res = self.interpret(func, [])
+        assert 5 + 6 + 7 <= res <= 5 + 6 + 7 + (5^16) + (6^16) + (7^16)
+
     # ____________________________________________________________
 
 



More information about the Pypy-commit mailing list