Author: Philip Jenvey <[email protected]>
Branch: 
Changeset: r57395:efca15c9d78e
Date: 2012-09-19 10:27 -0700
http://bitbucket.org/pypy/pypy/changeset/efca15c9d78e/

Log:    issue1266: fix RangeListStrategy append to be more careful when
        empty

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
@@ -589,12 +589,14 @@
     def append(self, w_list, w_item):
         if is_W_IntObject(w_item):
             l = self.unerase(w_list.lstorage)
-            step = l[1]
-            last_in_range = self._getitem_unwrapped(w_list, -1)
-            if self.unwrap(w_item) - step == last_in_range:
-                new = self.erase((l[0], l[1], l[2] + 1))
-                w_list.lstorage = new
-                return
+            length = l[2]
+            if length:
+                last_in_range = self._getitem_unwrapped(w_list, -1)
+                step = l[1]
+                if self.unwrap(w_item) - step == last_in_range:
+                    new = self.erase((l[0], step, length + 1))
+                    w_list.lstorage = new
+                    return
 
             self.switch_to_integer_strategy(w_list)
         else:
diff --git a/pypy/objspace/std/test/test_listobject.py 
b/pypy/objspace/std/test/test_listobject.py
--- a/pypy/objspace/std/test/test_listobject.py
+++ b/pypy/objspace/std/test/test_listobject.py
@@ -1345,6 +1345,13 @@
         l.reverse()
         assert l == [2,1,0]
 
+    def test_issue1266(self):
+        l = range(1)
+        l.pop()
+        # would previously crash
+        l.append(1)
+        assert l == [1]
+
 class AppTestWithoutStrategies(object):
 
     def setup_class(cls):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to