Commits

Benjamin Peterson committed 2f888f9

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

  • Participants
  • Parent commits 516cbe7

Comments (0)

Files changed (3)

pypy/rpython/lltypesystem/rstr.py

     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

pypy/rpython/ootypesystem/rstr.py

         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):

pypy/rpython/test/test_rstr.py

             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