[pypy-commit] pypy list-strategies: Fixed setting slice of EmptyList (getitems of ObjectList doesn't copy anymore)
l.diekmann
noreply at buildbot.pypy.org
Fri Sep 23 13:13:02 CEST 2011
Author: Lukas Diekmann <lukas.diekmann at uni-duesseldorf.de>
Branch: list-strategies
Changeset: r47493:abbd13b48791
Date: 2011-03-30 15:21 +0200
http://bitbucket.org/pypy/pypy/changeset/abbd13b48791/
Log: Fixed setting slice of EmptyList (getitems of ObjectList doesn't
copy anymore)
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
@@ -261,9 +261,11 @@
raise IndexError
def setslice(self, w_list, start, step, slicelength, w_other):
- #XXX now we have wrapping/unwrapping here!
- #XXX BUT: shouldn't we use from_strage_and_strategy here anyway?
- w_list.__init__(self.space, w_other.getitems())
+ items = w_other.getitems_copy()
+ strategy = w_other.strategy
+ storage = strategy.cast_to_void_star(items)
+ w_list.strategy = strategy
+ w_list.lstorage = storage
def insert(self, w_list, index, w_item):
assert index == 0
diff --git a/pypy/objspace/std/test/test_liststrategies.py b/pypy/objspace/std/test/test_liststrategies.py
--- a/pypy/objspace/std/test/test_liststrategies.py
+++ b/pypy/objspace/std/test/test_liststrategies.py
@@ -167,6 +167,14 @@
keep_other_strategy(l, 0, 1, l.length(), other)
assert l.strategy is self.space.fromcache(EmptyListStrategy)
+ def test_empty_setslice_with_objectlist(self):
+ l = W_ListObject(self.space, [])
+ o = W_ListObject(self.space, [self.space.wrap(1), self.space.wrap("2"), self.space.wrap(3)])
+ l.setslice(0, 1, o.length(), o)
+ assert l.getitems() == o.getitems()
+ l.append(self.space.wrap(17))
+ assert l.getitems() != o.getitems()
+
def test_extend(self):
l = W_ListObject(self.space, [])
assert isinstance(l.strategy, EmptyListStrategy)
More information about the pypy-commit
mailing list