Author: Carl Friedrich Bolz <[email protected]>
Branch: detect-immutable-fields
Changeset: r68900:2d7e3e3b5a02
Date: 2014-01-24 12:11 +0100
http://bitbucket.org/pypy/pypy/changeset/2d7e3e3b5a02/
Log: The check for immutability was done on the wrong attribute, leading
to completely bogus immutability assumptions.
tests are important!
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
@@ -34,7 +34,7 @@
attr = self.find_map_attr(selector)
if attr is None:
return self.terminator._read_terminator(obj, selector)
- return obj._mapdict_read_storage(attr.storageindex, pure=not
self.ever_mutated)
+ return obj._mapdict_read_storage(attr.storageindex, pure=not
attr.ever_mutated)
def write(self, obj, selector, w_value):
attr = self.find_map_attr(selector)
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
@@ -107,6 +107,43 @@
assert obj2.getdictvalue(space, "b") == 60
assert obj2.map is obj.map
+def test_attr_immutability():
+ cls = Class()
+ obj = cls.instantiate()
+ obj.setdictvalue(space, "a", 10)
+ obj.setdictvalue(space, "b", 20)
+ obj.setdictvalue(space, "b", 30)
+ assert obj.storage == [10, 30]
+ assert obj.map.ever_mutated == True
+ assert obj.map.back.ever_mutated == False
+
+ def _mapdict_read_storage(index, pure=False):
+ assert index in (0, 1)
+ if index == 0:
+ assert pure == True
+ else:
+ assert pure == False
+ return Object._mapdict_read_storage(obj, index, pure)
+
+ obj._mapdict_read_storage = _mapdict_read_storage
+
+ assert obj.getdictvalue(space, "a") == 10
+ assert obj.getdictvalue(space, "b") == 30
+
+ obj2 = cls.instantiate()
+ obj2.setdictvalue(space, "a", 15)
+ obj2.setdictvalue(space, "b", 25)
+ assert obj2.map is obj.map
+ assert obj2.map.ever_mutated == True
+ assert obj2.map.back.ever_mutated == False
+
+ # mutating obj2 changes the map
+ obj2.setdictvalue(space, "a", 50)
+ assert obj2.map.back.ever_mutated == True
+ assert obj2.map is obj.map
+
+
+
def test_delete():
for i, dattr in enumerate(["a", "b", "c"]):
c = Class()
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit