[pypy-svn] r19578 - in pypy/dist/pypy/rpython: . test

arigo at codespeak.net arigo at codespeak.net
Sun Nov 6 12:56:15 CET 2005


Author: arigo
Date: Sun Nov  6 12:56:13 2005
New Revision: 19578

Modified:
   pypy/dist/pypy/rpython/rlist.py
   pypy/dist/pypy/rpython/test/test_rlist.py
Log:
rlist.insert() was broken :-(


Modified: pypy/dist/pypy/rpython/rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/rlist.py	(original)
+++ pypy/dist/pypy/rpython/rlist.py	Sun Nov  6 12:56:13 2005
@@ -497,25 +497,23 @@
 def ll_prepend(l, newitem):
     length = l.length
     _ll_list_resize_ge(l, length+1)
-    i = length
     items = l.items
-    i1 = i+1
-    while i >= 0:
-        items[i1] = items[i]
-        i1 = i
-        i -= 1
+    dst = length
+    while dst > 0:
+        src = dst - 1
+        items[dst] = items[src]
+        dst = src
     items[0] = newitem
 
 def ll_insert_nonneg(l, index, newitem):
     length = l.length
     _ll_list_resize_ge(l, length+1)
     items = l.items
-    i = length
-    i1 = i+1
-    while i >= index:
-        items[i1] = items[i]
-        i1 = i
-        i -= 1
+    dst = length
+    while dst > index:
+        src = dst - 1
+        items[dst] = items[src]
+        dst = src
     items[index] = newitem
 
 def dum_checkidx(): pass

Modified: pypy/dist/pypy/rpython/test/test_rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rlist.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rlist.py	Sun Nov  6 12:56:13 2005
@@ -344,6 +344,23 @@
     res = interpret(dummyfn, ())#, view=True)
     assert res == 42
 
+def test_insert_bug():
+    def dummyfn(n):
+        l = [1]
+        l = l[:]
+        l.pop(0)
+        if n < 0:
+            l.insert(0, 42)
+        else:
+            l.insert(n, 42)
+        return l
+    res = interpret(dummyfn, [0])
+    assert res.ll_length() == 1
+    assert res.ll_items()[0] == 42
+    res = interpret(dummyfn, [-1])
+    assert res.ll_length() == 1
+    assert res.ll_items()[0] == 42
+
 def test_inst_pop():
     class A:
         pass



More information about the Pypy-commit mailing list