[pypy-commit] pypy default: if start - stop <= 0, return a empty string
gutworth
noreply at buildbot.pypy.org
Thu Mar 29 04:49:12 CEST 2012
Author: Benjamin Peterson <benjamin at python.org>
Branch:
Changeset: r54052:3b13b7c4c388
Date: 2012-03-28 22:48 -0400
http://bitbucket.org/pypy/pypy/changeset/3b13b7c4c388/
Log: if start - stop <= 0, return a empty string
diff --git a/pypy/rpython/lltypesystem/rstr.py b/pypy/rpython/lltypesystem/rstr.py
--- a/pypy/rpython/lltypesystem/rstr.py
+++ b/pypy/rpython/lltypesystem/rstr.py
@@ -765,7 +765,8 @@
def _ll_stringslice(s1, start, stop):
lgt = stop - start
assert start >= 0
- assert lgt >= 0
+ if lgt <= 0:
+ return s1.empty()
newstr = s1.malloc(lgt)
s1.copy_contents(s1, newstr, start, 0, lgt)
return newstr
diff --git a/pypy/rpython/test/test_rstr.py b/pypy/rpython/test/test_rstr.py
--- a/pypy/rpython/test/test_rstr.py
+++ b/pypy/rpython/test/test_rstr.py
@@ -477,7 +477,8 @@
s1 = s[:3]
s2 = s[3:]
s3 = s[3:10]
- return s1+s2 == s and s2+s1 == const('lohel') and s1+s3 == s
+ s4 = s[42:44]
+ return s1+s2 == s and s2+s1 == const('lohel') and s1+s3 == s and s4 == ""
res = self.interpret(fn, [0])
assert res
More information about the pypy-commit
mailing list