Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r72398:3dec80f8412a Date: 2014-07-09 17:18 +0200 http://bitbucket.org/pypy/pypy/changeset/3dec80f8412a/
Log: merge heads diff --git a/pypy/module/__pypy__/__init__.py b/pypy/module/__pypy__/__init__.py --- a/pypy/module/__pypy__/__init__.py +++ b/pypy/module/__pypy__/__init__.py @@ -73,13 +73,12 @@ 'builtinify' : 'interp_magic.builtinify', 'lookup_special' : 'interp_magic.lookup_special', 'do_what_I_mean' : 'interp_magic.do_what_I_mean', - 'list_strategy' : 'interp_magic.list_strategy', 'validate_fd' : 'interp_magic.validate_fd', 'resizelist_hint' : 'interp_magic.resizelist_hint', 'newlist_hint' : 'interp_magic.newlist_hint', 'add_memory_pressure' : 'interp_magic.add_memory_pressure', 'newdict' : 'interp_dict.newdict', - 'dictstrategy' : 'interp_dict.dictstrategy', + 'strategy' : 'interp_magic.strategy', # dict,set,list 'set_debug' : 'interp_magic.set_debug', 'locals_to_fast' : 'interp_magic.locals_to_fast', } diff --git a/pypy/module/__pypy__/interp_dict.py b/pypy/module/__pypy__/interp_dict.py --- a/pypy/module/__pypy__/interp_dict.py +++ b/pypy/module/__pypy__/interp_dict.py @@ -1,7 +1,6 @@ from pypy.interpreter.error import OperationError, oefmt from pypy.interpreter.gateway import unwrap_spec -from pypy.objspace.std.dictmultiobject import W_DictMultiObject @unwrap_spec(type=str) def newdict(space, type): @@ -31,13 +30,3 @@ return space.newdict(strdict=True) else: raise oefmt(space.w_TypeError, "unknown type of dict %s", type) - -def dictstrategy(space, w_obj): - """ dictstrategy(dict) - - show the underlaying strategy used by a dict object - """ - if not isinstance(w_obj, W_DictMultiObject): - raise OperationError(space.w_TypeError, - space.wrap("expecting dict object")) - return space.wrap('%r' % (w_obj.strategy,)) diff --git a/pypy/module/__pypy__/interp_magic.py b/pypy/module/__pypy__/interp_magic.py --- a/pypy/module/__pypy__/interp_magic.py +++ b/pypy/module/__pypy__/interp_magic.py @@ -2,7 +2,9 @@ from pypy.interpreter.gateway import unwrap_spec from pypy.interpreter.pyframe import PyFrame from rpython.rlib.objectmodel import we_are_translated +from pypy.objspace.std.dictmultiobject import W_DictMultiObject from pypy.objspace.std.listobject import W_ListObject +from pypy.objspace.std.setobject import W_BaseSetObject from pypy.objspace.std.typeobject import MethodCache from pypy.objspace.std.mapdict import MapAttrCache from rpython.rlib import rposix, rgc @@ -70,12 +72,27 @@ def do_what_I_mean(space): return space.wrap(42) -def list_strategy(space, w_list): - if isinstance(w_list, W_ListObject): - return space.wrap(w_list.strategy._applevel_repr) + +def _nameof(cls): + return cls.__name__ +_nameof._annspecialcase_ = 'specialize:memo' + +def strategy(space, w_obj): + """ strategy(dict or list or set) + + Return the underlying strategy currently used by a dict, list or set object + """ + if isinstance(w_obj, W_DictMultiObject): + name = _nameof(w_obj.strategy.__class__) + elif isinstance(w_obj, W_ListObject): + name = _nameof(w_obj.strategy.__class__) + elif isinstance(w_obj, W_BaseSetObject): + name = _nameof(w_obj.strategy.__class__) else: - w_msg = space.wrap("Can only get the list strategy of a list") - raise OperationError(space.w_TypeError, w_msg) + raise OperationError(space.w_TypeError, + space.wrap("expecting dict or list or set object")) + return space.wrap(name) + @unwrap_spec(fd='c_int') def validate_fd(space, fd): diff --git a/pypy/module/__pypy__/test/test_special.py b/pypy/module/__pypy__/test/test_special.py --- a/pypy/module/__pypy__/test/test_special.py +++ b/pypy/module/__pypy__/test/test_special.py @@ -46,26 +46,42 @@ assert x == 42 def test_list_strategy(self): - from __pypy__ import list_strategy + from __pypy__ import strategy l = [1, 2, 3] - assert list_strategy(l) == "int" + assert strategy(l) == "IntegerListStrategy" l = ["a", "b", "c"] - assert list_strategy(l) == "bytes" + assert strategy(l) == "BytesListStrategy" l = [u"a", u"b", u"c"] - assert list_strategy(l) == "unicode" + assert strategy(l) == "UnicodeListStrategy" l = [1.1, 2.2, 3.3] - assert list_strategy(l) == "float" + assert strategy(l) == "FloatListStrategy" l = range(3) - assert list_strategy(l) == "simple_range" + assert strategy(l) == "SimpleRangeListStrategy" l = range(1, 2) - assert list_strategy(l) == "range" + assert strategy(l) == "RangeListStrategy" l = [1, "b", 3] - assert list_strategy(l) == "object" + assert strategy(l) == "ObjectListStrategy" l = [] - assert list_strategy(l) == "empty" + assert strategy(l) == "EmptyListStrategy" o = 5 - raises(TypeError, list_strategy, 5) + raises(TypeError, strategy, 5) + + def test_dict_strategy(self): + from __pypy__ import strategy + + d = {} + assert strategy(d) == "EmptyDictStrategy" + d = {1: None, 5: None} + assert strategy(d) == "IntDictStrategy" + + def test_set_strategy(self): + from __pypy__ import strategy + + s = set() + assert strategy(s) == "EmptySetStrategy" + s = set([2, 3, 4]) + assert strategy(s) == "IntegerSetStrategy" class AppTestJitFeatures(object): diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py --- a/pypy/objspace/std/listobject.py +++ b/pypy/objspace/std/listobject.py @@ -842,8 +842,6 @@ W_Lists do not switch back to EmptyListStrategy when becoming empty again. """ - _applevel_repr = "empty" - def __init__(self, space): ListStrategy.__init__(self, space) @@ -1102,8 +1100,6 @@ method providing only positive length. The storage is a one element tuple with positive integer storing length.""" - _applevel_repr = "simple_range" - erase, unerase = rerased.new_erasing_pair("simple_range") erase = staticmethod(erase) unerase = staticmethod(unerase) @@ -1176,8 +1172,6 @@ destroying the range (inserting, appending non-ints) the strategy is switched to IntegerListStrategy.""" - _applevel_repr = "range" - erase, unerase = rerased.new_erasing_pair("range") erase = staticmethod(erase) unerase = staticmethod(unerase) @@ -1555,7 +1549,6 @@ import_from_mixin(AbstractUnwrappedStrategy) _none_value = None - _applevel_repr = "object" def unwrap(self, w_obj): return w_obj @@ -1590,7 +1583,6 @@ import_from_mixin(AbstractUnwrappedStrategy) _none_value = 0 - _applevel_repr = "int" def wrap(self, intval): return self.space.wrap(intval) @@ -1644,7 +1636,6 @@ import_from_mixin(AbstractUnwrappedStrategy) _none_value = 0.0 - _applevel_repr = "float" def wrap(self, floatval): return self.space.wrap(floatval) @@ -1677,7 +1668,6 @@ import_from_mixin(AbstractUnwrappedStrategy) _none_value = None - _applevel_repr = "bytes" def wrap(self, stringval): return self.space.wrap(stringval) @@ -1710,7 +1700,6 @@ import_from_mixin(AbstractUnwrappedStrategy) _none_value = None - _applevel_repr = "unicode" def wrap(self, stringval): return self.space.wrap(stringval) diff --git a/rpython/rtyper/test/test_rclass.py b/rpython/rtyper/test/test_rclass.py --- a/rpython/rtyper/test/test_rclass.py +++ b/rpython/rtyper/test/test_rclass.py @@ -440,6 +440,25 @@ res = self.interpret(f, [3]) assert res == ~0x0200 & 0x3ff + def test_class___name__(self): + class ACLS(object): pass + class Bcls(ACLS): pass + class CCls(ACLS): pass + def nameof(cls): + return cls.__name__ + nameof._annspecialcase_ = "specialize:memo" + def f(i): + if i == 1: x = ACLS() + elif i == 2: x = Bcls() + else: x = CCls() + return nameof(x.__class__) + res = self.interpret(f, [1]) + assert ''.join(res.chars) == 'ACLS' + res = self.interpret(f, [2]) + assert ''.join(res.chars) == 'Bcls' + res = self.interpret(f, [3]) + assert ''.join(res.chars) == 'CCls' + def test_hash_preservation(self): from rpython.rlib.objectmodel import current_object_addr_as_int from rpython.rlib.objectmodel import compute_identity_hash _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit