[pypy-svn] r15400 - in pypy/dist/pypy/rpython: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Sat Jul 30 11:18:57 CEST 2005
Author: cfbolz
Date: Sat Jul 30 11:18:54 2005
New Revision: 15400
Modified:
pypy/dist/pypy/rpython/rlist.py
pypy/dist/pypy/rpython/rstr.py
pypy/dist/pypy/rpython/test/test_rlist.py
pypy/dist/pypy/rpython/test/test_rstr.py
Log:
(arigo, cfbolz):
changed slicing so that slice stop bigger that the length of the list/string
is possible.
Modified: pypy/dist/pypy/rpython/rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/rlist.py (original)
+++ pypy/dist/pypy/rpython/rlist.py Sat Jul 30 11:18:54 2005
@@ -515,6 +515,8 @@
def ll_listslice(l1, slice):
start = slice.start
stop = slice.stop
+ if stop > len(l1.items):
+ stop = len(l1.items)
newitems = malloc(typeOf(l1).TO.items.TO, stop - start)
j = 0
while start < stop:
@@ -548,6 +550,8 @@
def ll_listdelslice(l1, slice):
start = slice.start
stop = slice.stop
+ if stop > len(l1.items):
+ stop = len(l1.items)
newlength = len(l1.items) - (stop-start)
newitems = malloc(typeOf(l1).TO.items.TO, newlength)
j = 0
Modified: pypy/dist/pypy/rpython/rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/rstr.py (original)
+++ pypy/dist/pypy/rpython/rstr.py Sat Jul 30 11:18:54 2005
@@ -793,6 +793,8 @@
def ll_stringslice(s1, slice):
start = slice.start
stop = slice.stop
+ if stop > len(s1.chars):
+ stop = len(s1.chars)
newstr = malloc(STR, stop - start)
j = 0
while start < stop:
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 Sat Jul 30 11:18:54 2005
@@ -63,7 +63,7 @@
check_list(ll_listslice_startonly(l, 3), [45])
check_list(ll_listslice_startonly(l, 4), [])
for start in range(5):
- for stop in range(start, 5):
+ for stop in range(start, 8):
s = ll_newslice(start, stop)
check_list(ll_listslice(l, s), [42, 43, 44, 45][start:stop])
@@ -74,7 +74,7 @@
ll_listdelslice_startonly(l, 0)
check_list(l, [])
for start in range(5):
- for stop in range(start, 5):
+ for stop in range(start, 8):
l = sample_list()
s = ll_newslice(start, stop)
ll_listdelslice(l, s)
Modified: pypy/dist/pypy/rpython/test/test_rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rstr.py (original)
+++ pypy/dist/pypy/rpython/test/test_rstr.py Sat Jul 30 11:18:54 2005
@@ -303,7 +303,8 @@
s = 'hello'
s1 = s[:3]
s2 = s[3:]
- return s1+s2 == s and s2+s1 == 'lohel'
+ s3 = s[3:10]
+ return s1+s2 == s and s2+s1 == 'lohel' and s1+s3 == s
res = interpret(fn, ())
assert res
More information about the Pypy-commit
mailing list