[pypy-svn] r68923 - in pypy/branch/shrink-multidict/pypy/objspace/std: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Mon Nov 2 18:33:08 CET 2009


Author: cfbolz
Date: Mon Nov  2 18:33:08 2009
New Revision: 68923

Modified:
   pypy/branch/shrink-multidict/pypy/objspace/std/celldict.py
   pypy/branch/shrink-multidict/pypy/objspace/std/dictmultiobject.py
   pypy/branch/shrink-multidict/pypy/objspace/std/inlinedict.py
   pypy/branch/shrink-multidict/pypy/objspace/std/sharingdict.py
   pypy/branch/shrink-multidict/pypy/objspace/std/test/test_inlinedict.py
Log:
A bug found by test_descr.py: setting the dict of an object with a devolved dict
runs into an assertion.


Modified: pypy/branch/shrink-multidict/pypy/objspace/std/celldict.py
==============================================================================
--- pypy/branch/shrink-multidict/pypy/objspace/std/celldict.py	(original)
+++ pypy/branch/shrink-multidict/pypy/objspace/std/celldict.py	Mon Nov  2 18:33:08 2009
@@ -124,9 +124,12 @@
             cell.invalidate()
         for k in self.unshadowed_builtins:
             self.invalidate_unshadowed_builtin(k)
+        self._clear_fields()
+        return self
+
+    def _clear_fields(self):
         self.content = None
         self.unshadowed_builtins = None
-        return self
 
 class ModuleDictIteratorImplementation(IteratorImplementation):
     def __init__(self, space, dictimplementation):

Modified: pypy/branch/shrink-multidict/pypy/objspace/std/dictmultiobject.py
==============================================================================
--- pypy/branch/shrink-multidict/pypy/objspace/std/dictmultiobject.py	(original)
+++ pypy/branch/shrink-multidict/pypy/objspace/std/dictmultiobject.py	Mon Nov  2 18:33:08 2009
@@ -370,9 +370,12 @@
         r_dict_content = self.initialize_as_rdict()
         for k, w_v in self.content.items():
             r_dict_content[self.space.wrap(k)] = w_v
-        self.content = None
+        self._clear_fields()
         return self
 
+    def _clear_fields(self):
+        self.content = None
+
 class StrIteratorImplementation(IteratorImplementation):
     def __init__(self, space, dictimplementation):
         IteratorImplementation.__init__(self, space, dictimplementation)

Modified: pypy/branch/shrink-multidict/pypy/objspace/std/inlinedict.py
==============================================================================
--- pypy/branch/shrink-multidict/pypy/objspace/std/inlinedict.py	(original)
+++ pypy/branch/shrink-multidict/pypy/objspace/std/inlinedict.py	Mon Nov  2 18:33:08 2009
@@ -61,6 +61,8 @@
                                              "init_dictattributes")
     make_rdict = func_with_new_name(dictimplclass._as_rdict.im_func,
                                     "make_rdict")
+    clear_fields = func_with_new_name(dictimplclass._clear_fields.im_func,
+                                      "clear_fields")
 
     class InlineDictMixin(object):
 
@@ -116,7 +118,7 @@
             return True
 
         def setdict(self, space, w_dict):
-            make_rdict(self) # invalidate attributes on self
+            self._clear_fields() # invalidate attributes on self
             self.w__dict__ = check_new_dictionary(space, w_dict)
 
         def _as_rdict(self):
@@ -125,6 +127,8 @@
 
         def initialize_as_rdict(self):
             return self.getdict().initialize_as_rdict()
+        
+        _clear_fields = clear_fields
 
     for methname, _ in implementation_methods:
         implname = "impl_" + methname

Modified: pypy/branch/shrink-multidict/pypy/objspace/std/sharingdict.py
==============================================================================
--- pypy/branch/shrink-multidict/pypy/objspace/std/sharingdict.py	(original)
+++ pypy/branch/shrink-multidict/pypy/objspace/std/sharingdict.py	Mon Nov  2 18:33:08 2009
@@ -163,10 +163,12 @@
         r_dict_content = self.initialize_as_rdict()
         for k, i in self.structure.keys.items():
             r_dict_content[self.space.wrap(k)] = self.entries[i]
-        self.structure = None
-        self.entries = None
+        self._clear_fields()
         return self
 
+    def _clear_fields(self):
+        self.structure = None
+        self.entries = None
 
 class SharedIteratorImplementation(IteratorImplementation):
     def __init__(self, space, dictimplementation):

Modified: pypy/branch/shrink-multidict/pypy/objspace/std/test/test_inlinedict.py
==============================================================================
--- pypy/branch/shrink-multidict/pypy/objspace/std/test/test_inlinedict.py	(original)
+++ pypy/branch/shrink-multidict/pypy/objspace/std/test/test_inlinedict.py	Mon Nov  2 18:33:08 2009
@@ -40,7 +40,7 @@
     def test_getdict(self):
         obj = self.make_obj()
         w_dict = obj.getdict()
-        assert obj.getdict() or w_dict # always get the same dict
+        assert obj.getdict() is w_dict # always get the same dict
         assert obj.w__dict__ is w_dict
 
         assert w_dict.getitem("hello") == 1
@@ -50,6 +50,22 @@
         assert obj.getdictvalue(self.fakespace, "hello") == 4
         assert obj.getdictvalue(self.fakespace, "world") == 5
 
+    def test_setdict(self):
+        obj1 = self.make_obj()
+        w_dict1 = obj1.getdict()
+        obj2 = self.make_obj()
+        w_dict2 = obj2.getdict()
+        w_dict2.setitem(4, 1) # devolve dict
+        w_dict2.setitem(5, 2)
+        obj2.setdict(self.space, w_dict1)
+        assert obj2.getdictvalue(self.fakespace, "hello") == 1
+        assert obj2.getdictvalue(self.fakespace, "world") == 2
+        obj1.setdictvalue(self.fakespace, "hello", 4)
+        obj1.setdictvalue(self.fakespace, "world", 5)
+        assert obj2.getdictvalue(self.fakespace, "hello") == 4
+        assert obj2.getdictvalue(self.fakespace, "world") == 5
+
+
     def test_dict_devolves_via_dict(self):
         obj = self.make_obj()
         w_dict = obj.getdict()



More information about the Pypy-commit mailing list