[pypy-commit] pypy list-strategies: Fixed getslice bug in RangeListStrategy

l.diekmann noreply at buildbot.pypy.org
Fri Sep 23 13:13:13 CEST 2011


Author: Lukas Diekmann <lukas.diekmann at uni-duesseldorf.de>
Branch: list-strategies
Changeset: r47499:8b2722432eef
Date: 2011-04-20 14:19 +0200
http://bitbucket.org/pypy/pypy/changeset/8b2722432eef/

Log:	Fixed getslice bug in RangeListStrategy

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
@@ -514,6 +514,7 @@
             return W_ListObject.from_storage_and_strategy(self.space, storage, self)
         else:
             subitems_w = [None] * length
+            # XXX wrap/unwrap
             for i in range(length):
                 subitems_w[i] = w_list.getitem(start)
                 start += step
@@ -806,6 +807,13 @@
 def getslice__List_ANY_ANY(space, w_list, w_start, w_stop):
     length = w_list.length()
     start, stop = normalize_simple_slice(space, length, w_start, w_stop)
+
+    slicelength = stop - start
+    if slicelength == 0:
+        strategy = space.fromcache(EmptyListStrategy)
+        storage = strategy.cast_to_void_star(None)
+        return W_ListObject.from_storage_and_strategy(space, storage, strategy)
+
     return w_list.getslice(start, stop, 1, stop - start)
 
 def setslice__List_ANY_ANY_List(space, w_list, w_start, w_stop, w_other):
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
@@ -325,3 +325,8 @@
         l1.setitem(0, self.space.wrap(5))
         assert not self.space.eq_w(l1, l2)
 
+    def test_weird_rangelist_bug(self):
+        l = make_range_list(self.space, 1, 1, 3)
+        from pypy.objspace.std.listobject import getslice__List_ANY_ANY
+        # should not raise
+        assert getslice__List_ANY_ANY(self.space, l, self.space.wrap(15), self.space.wrap(2222)).strategy == self.space.fromcache(EmptyListStrategy)


More information about the pypy-commit mailing list