[pypy-commit] pypy default: fix a regression: space.newdict(instance=True) was returning a StringDict.
cfbolz
noreply at buildbot.pypy.org
Thu Jan 24 15:10:00 CET 2013
Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch:
Changeset: r60420:5e86c989acc1
Date: 2013-01-24 14:57 +0100
http://bitbucket.org/pypy/pypy/changeset/5e86c989acc1/
Log: fix a regression: space.newdict(instance=True) was returning a
StringDict. Write the 10 slightly obscure lines that fix that.
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
@@ -54,6 +54,9 @@
# every module needs its own strategy, because the strategy stores
# the version tag
strategy = ModuleDictStrategy(space)
+ elif space.config.objspace.std.withmapdict and instance:
+ from pypy.objspace.std.mapdict import MapDictStrategy
+ strategy = space.fromcache(MapDictStrategy)
elif instance or strdict or module:
assert w_type is None
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
@@ -593,6 +593,9 @@
# ____________________________________________________________
# dict implementation
+def get_terminator_for_dicts(space):
+ return DictTerminator(space, None)
+
class MapDictStrategy(DictStrategy):
erase, unerase = rerased.new_erasing_pair("map")
@@ -602,13 +605,19 @@
def __init__(self, space):
self.space = space
+ def get_empty_storage(self):
+ w_result = Object()
+ terminator = self.space.fromcache(get_terminator_for_dicts)
+ w_result._init_empty(terminator)
+ return self.erase(w_result)
+
def switch_to_object_strategy(self, w_dict):
w_obj = self.unerase(w_dict.dstorage)
strategy = self.space.fromcache(ObjectDictStrategy)
dict_w = strategy.unerase(strategy.get_empty_storage())
w_dict.strategy = strategy
w_dict.dstorage = strategy.erase(dict_w)
- assert w_obj.getdict(self.space) is w_dict
+ assert w_obj.getdict(self.space) is w_dict or w_obj._get_mapdict_map().terminator.w_cls is None
materialize_r_dict(self.space, w_obj, dict_w)
def getitem(self, w_dict, w_key):
diff --git a/pypy/objspace/std/test/test_dictmultiobject.py b/pypy/objspace/std/test/test_dictmultiobject.py
--- a/pypy/objspace/std/test/test_dictmultiobject.py
+++ b/pypy/objspace/std/test/test_dictmultiobject.py
@@ -954,6 +954,7 @@
withcelldict = False
withmethodcache = False
withidentitydict = False
+ withmapdict = False
FakeSpace.config = Config()
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
@@ -1,7 +1,17 @@
from pypy.objspace.std.test.test_dictmultiobject import FakeSpace, W_DictMultiObject
from pypy.objspace.std.mapdict import *
+class Config:
+ class objspace:
+ class std:
+ withsmalldicts = False
+ withcelldict = False
+ withmethodcache = False
+ withidentitydict = False
+ withmapdict = True
+
space = FakeSpace()
+space.config = Config
class Class(object):
def __init__(self, hasdict=True):
@@ -1061,3 +1071,11 @@
return A()
""")
assert w_dict.user_overridden_class
+
+def test_newdict_instance():
+ w_dict = space.newdict(instance=True)
+ assert type(w_dict.strategy) is MapDictStrategy
+
+class TestMapDictImplementationUsingnewdict(BaseTestRDictImplementation):
+ StrategyClass = MapDictStrategy
+ # NB: the get_impl method is not overwritten here, as opposed to above
More information about the pypy-commit
mailing list