Author: Carl Friedrich Bolz-Tereick <[email protected]>
Branch:
Changeset: r96711:e19e79b1385f
Date: 2019-05-28 12:22 +0200
http://bitbucket.org/pypy/pypy/changeset/e19e79b1385f/
Log: fix bug: when a newdict(instance=True) was switching its strategy,
it lost its content
diff --git a/pypy/objspace/std/dictmultiobject.py
b/pypy/objspace/std/dictmultiobject.py
--- a/pypy/objspace/std/dictmultiobject.py
+++ b/pypy/objspace/std/dictmultiobject.py
@@ -78,8 +78,9 @@
W_ModuleDictObject.__init__(w_obj, space, strategy, storage)
return w_obj
elif instance:
- from pypy.objspace.std.mapdict import MapDictStrategy
- strategy = space.fromcache(MapDictStrategy)
+ from pypy.objspace.std.mapdict import make_instance_dict
+ assert w_type is None
+ return make_instance_dict(space)
elif strdict or module:
assert w_type is None
strategy = space.fromcache(BytesDictStrategy)
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
@@ -753,6 +753,7 @@
self.space = space
def get_empty_storage(self):
+ # mainly used for tests
w_result = Object()
terminator = self.space.fromcache(get_terminator_for_dicts)
w_result._mapdict_init_empty(terminator)
@@ -865,6 +866,11 @@
def iteritems(self, w_dict):
return MapDictIteratorItems(self.space, self, w_dict)
+def make_instance_dict(space):
+ w_fake_object = Object()
+ terminator = space.fromcache(get_terminator_for_dicts)
+ w_fake_object._mapdict_init_empty(terminator)
+ return w_fake_object.getdict(space)
def materialize_r_dict(space, obj, dict_w):
map = obj._get_mapdict_map()
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
@@ -897,6 +897,17 @@
d = x.__dict__
assert list(__pypy__.reversed_dict(d)) == d.keys()[::-1]
+ def test_bug_materialize_huge_dict(self):
+ import __pypy__
+ d = __pypy__.newdict("instance")
+ for i in range(100):
+ d[str(i)] = i
+ assert len(d) == 100
+
+ for key in d:
+ assert d[key] == int(key)
+
+
class AppTestWithMapDictAndCounters(object):
spaceconfig = {"objspace.std.withmethodcachecounter": True}
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit