[pypy-commit] pypy default: Bring back 3b13b7c4c388 through 029ef1dd4a1a; fix slicing when stop > start

gutworth noreply at buildbot.pypy.org
Thu Mar 29 14:47:47 CEST 2012


Author: Benjamin Peterson <benjamin at python.org>
Branch: 
Changeset: r54060:2f888f931838
Date: 2012-03-29 08:40 -0400
http://bitbucket.org/pypy/pypy/changeset/2f888f931838/

Log:	Bring back 3b13b7c4c388 through 029ef1dd4a1a; fix slicing when stop
	> start

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/ootypesystem/rstr.py b/pypy/rpython/ootypesystem/rstr.py
--- a/pypy/rpython/ootypesystem/rstr.py
+++ b/pypy/rpython/ootypesystem/rstr.py
@@ -222,6 +222,8 @@
         length = s.ll_strlen()
         if stop > length:
             stop = length
+        if start > stop:
+            start = stop
         return s.ll_substring(start, stop-start)
 
     def ll_stringslice_minusone(s):
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,11 @@
             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 == const(''))
         res = self.interpret(fn, [0])
         assert res
 


More information about the pypy-commit mailing list