[pypy-commit] pypy typed-cells: make mutboxes on the first write

cfbolz noreply at buildbot.pypy.org
Fri Jan 23 10:42:20 CET 2015


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: typed-cells
Changeset: r75498:e458fdc1f2e4
Date: 2015-01-23 10:36 +0100
http://bitbucket.org/pypy/pypy/changeset/e458fdc1f2e4/

Log:	make mutboxes on the first write

diff --git a/pypy/objspace/std/mapdict.py b/pypy/objspace/std/mapdict.py
--- a/pypy/objspace/std/mapdict.py
+++ b/pypy/objspace/std/mapdict.py
@@ -39,11 +39,9 @@
             not attr.ever_mutated
         ):
             result = self._pure_mapdict_read_storage(obj, attr.storageindex)
-            assert not isinstance(result, MutableCell)
         else:
-            result = attr._read_cell(
-                obj._mapdict_read_storage(attr.storageindex))
-        return result
+            result = obj._mapdict_read_storage(attr.storageindex)
+        return attr._read_cell(result)
 
     @jit.elidable
     def _pure_mapdict_read_storage(self, obj, storageindex):
@@ -55,8 +53,6 @@
             return self.terminator._write_terminator(obj, selector, w_value)
         if not attr.ever_mutated:
             attr.ever_mutated = True
-        # introduce cells only on the second write, to make immutability for
-        # int fields still work
         cell = obj._mapdict_read_storage(attr.storageindex)
         w_value = attr._write_cell(cell, w_value)
         if w_value is not None:
@@ -161,6 +157,7 @@
     def add_attr(self, obj, selector, w_value):
         # grumble, jit needs this
         attr = self._get_new_attr(selector[0], selector[1])
+        w_value = attr._write_cell(None, w_value)
         oldattr = obj._get_mapdict_map()
         if not jit.we_are_jitted():
             size_est = (oldattr._size_estimate + attr.size_estimate()
diff --git a/pypy/objspace/std/test/test_mapdict.py b/pypy/objspace/std/test/test_mapdict.py
--- a/pypy/objspace/std/test/test_mapdict.py
+++ b/pypy/objspace/std/test/test_mapdict.py
@@ -159,14 +159,16 @@
     cls = Class()
     obj = cls.instantiate()
     obj.setdictvalue(space, "a", W_IntObject(5))
-    assert obj.getdictvalue(space, "a").intval == 5
-    w_val = obj._mapdict_read_storage(0)
-    assert w_val.intval == 5 # still a W_IntObject
+    # not wrapped because of the FakeSpace :-(
+    assert obj.getdictvalue(space, "a") == 5
+    mutcell = obj._mapdict_read_storage(0)
+    assert mutcell.intvalue == 5
 
     obj.setdictvalue(space, "a", W_IntObject(6))
-    assert obj.getdictvalue(space, "a") == 6 # because of the FakeSpace :-(
+    assert obj.getdictvalue(space, "a") == 6 # FakeSpace again
     mutcell1 = obj._mapdict_read_storage(0)
     assert mutcell1.intvalue == 6
+    assert mutcell is mutcell1
 
     obj.setdictvalue(space, "a", W_IntObject(7))
     assert obj.getdictvalue(space, "a") == 7 # FakeSpace again


More information about the pypy-commit mailing list