[pypy-commit] pypy default: Handle weird indices here, don't try to pass length = -1 down to append_charpsize
alex_gaynor
noreply at buildbot.pypy.org
Wed Nov 6 07:31:42 CET 2013
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch:
Changeset: r67862:cab5c44a5677
Date: 2013-11-05 22:31 -0800
http://bitbucket.org/pypy/pypy/changeset/cab5c44a5677/
Log: Handle weird indices here, don't try to pass length = -1 down to
append_charpsize
diff --git a/pypy/module/mmap/interp_mmap.py b/pypy/module/mmap/interp_mmap.py
--- a/pypy/module/mmap/interp_mmap.py
+++ b/pypy/module/mmap/interp_mmap.py
@@ -163,6 +163,8 @@
if step == 0: # index only
return space.wrap(self.mmap.getitem(start))
elif step == 1:
+ if stop - start < 0:
+ return space.wrap("")
return space.wrap(self.mmap.getslice(start, stop - start))
else:
res = "".join([self.mmap.getitem(i)
diff --git a/pypy/module/mmap/test/test_mmap.py b/pypy/module/mmap/test/test_mmap.py
--- a/pypy/module/mmap/test/test_mmap.py
+++ b/pypy/module/mmap/test/test_mmap.py
@@ -525,6 +525,8 @@
m = mmap(f.fileno(), 6)
assert m[-3:7] == "bar"
+ assert m[1:0:1] == ""
+
f.close()
def test_sequence_type(self):
diff --git a/rpython/rlib/rstring.py b/rpython/rlib/rstring.py
--- a/rpython/rlib/rstring.py
+++ b/rpython/rlib/rstring.py
@@ -371,6 +371,7 @@
self._grow(times)
def append_charpsize(self, s, size):
+ assert size >= 0
l = []
for i in xrange(size):
l.append(s[i])
More information about the pypy-commit
mailing list