Author: Jasper.Schulz <jasper.b.sch...@gmail.com> Branch: reorder-map-attributes Changeset: r82193:a64e20eaa1db Date: 2016-02-12 21:34 +0000 http://bitbucket.org/pypy/pypy/changeset/a64e20eaa1db/
Log: fixed always adding last attribute to map cache 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 @@ -219,19 +219,19 @@ current = current.back else: attr._switch_map_and_write_storage(obj, w_value) - stack_index = localstack_index - + if not localstack_index: + return + if not stack_index: - return - - # add the first attribute of the stack without reordering - # to prevent an endless loop - stack_index += -1 - next_map = stack_maps[stack_index] - w_value = stack_values[stack_index] - obj._get_mapdict_map()._add_attr_without_reordering( - obj, next_map.name, next_map.index, w_value) + # add the first attribute of the stack without reordering + # to prevent an endless loop + localstack_index += -1 + next_map = stack_maps[localstack_index] + w_value = stack_values[localstack_index] + obj._get_mapdict_map()._add_attr_without_reordering( + obj, next_map.name, next_map.index, w_value) + stack_index = localstack_index break if not stack_index: 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 @@ -188,6 +188,29 @@ assert obj.map is obj2.map +def test_insert_different_orders_5(): + cls = Class() + obj = cls.instantiate() + obj2 = cls.instantiate() + + obj.setdictvalue(space, "a", 10) + obj.setdictvalue(space, "b", 20) + obj.setdictvalue(space, "c", 30) + obj.setdictvalue(space, "d", 40) + + obj2.setdictvalue(space, "d", 50) + obj2.setdictvalue(space, "c", 50) + obj2.setdictvalue(space, "b", 50) + obj2.setdictvalue(space, "a", 50) + + obj3 = cls.instantiate() + obj3.setdictvalue(space, "d", 50) + obj3.setdictvalue(space, "c", 50) + obj3.setdictvalue(space, "b", 50) + obj3.setdictvalue(space, "a", 50) + + assert obj.map is obj3.map + def test_bug_stack_overflow_insert_attributes(): cls = Class() obj = cls.instantiate() _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit