Author: Richard Plangger <[email protected]>
Branch: py3.5
Changeset: r89263:c7076180efda
Date: 2016-12-29 14:50 +0100
http://bitbucket.org/pypy/pypy/changeset/c7076180efda/
Log: rStringIO assert that during tests the slicing is within bounds,
extend a test to check readline returns empty string if the position
is out of bounds
diff --git a/rpython/rlib/rStringIO.py b/rpython/rlib/rStringIO.py
--- a/rpython/rlib/rStringIO.py
+++ b/rpython/rlib/rStringIO.py
@@ -1,4 +1,5 @@
from rpython.rlib.rstring import StringBuilder
+from rpython.rlib.objectmodel import we_are_translated
AT_END = -1
@@ -154,8 +155,11 @@
assert p >= 0
self.__copy_into_bigbuffer()
end = len(self.__bigbuffer)
- if size >= 0 and size < end - p:
+ count = end - p
+ if size >= 0 and size < count:
end = p + size
+ if count <= 0:
+ return ''
i = p
while i < end:
finished = self.__bigbuffer[i] == '\n'
@@ -163,6 +167,11 @@
if finished:
break
self.__pos = i
+ if not we_are_translated():
+ # assert that we read within the bounds!
+ bl = len(self.__bigbuffer)
+ assert p <= bl
+ assert i <= bl
return ''.join(self.__bigbuffer[p:i])
def truncate(self, size):
diff --git a/rpython/rlib/test/test_rStringIO.py
b/rpython/rlib/test/test_rStringIO.py
--- a/rpython/rlib/test/test_rStringIO.py
+++ b/rpython/rlib/test/test_rStringIO.py
@@ -91,6 +91,10 @@
assert f.readline() == 'baz'
assert f.readline() == ''
+ f.seek(100000, 0)
+ assert f.tell() == 100000
+ assert f.readline() == ''
+
def test_truncate():
f = RStringIO()
f.truncate(20)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit