[pypy-commit] pypy default: test/fix rfile.read(0)

bdkearns noreply at buildbot.pypy.org
Fri Aug 29 07:20:13 CEST 2014


Author: Brian Kearns <bdkearns at gmail.com>
Branch: 
Changeset: r73150:26d170cd6c24
Date: 2014-08-29 01:01 -0400
http://bitbucket.org/pypy/pypy/changeset/26d170cd6c24/

Log:	test/fix rfile.read(0)

diff --git a/rpython/rlib/rfile.py b/rpython/rlib/rfile.py
--- a/rpython/rlib/rfile.py
+++ b/rpython/rlib/rfile.py
@@ -190,7 +190,9 @@
         # XXX CPython uses a more delicate logic here
         self._check_closed()
         ll_file = self.ll_file
-        if size < 0:
+        if size == 0:
+            return ""
+        elif size < 0:
             # read the entire contents
             buf = lltype.malloc(rffi.CCHARP.TO, BASE_BUF_SIZE, flavor='raw')
             try:
@@ -206,7 +208,7 @@
                     s.append_charpsize(buf, returned_size)
             finally:
                 lltype.free(buf, flavor='raw')
-        else:
+        else:  # size > 0
             with rffi.scoped_alloc_buffer(size) as buf:
                 returned_size = c_fread(buf.raw, 1, size, ll_file)
                 returned_size = intmask(returned_size)  # is between 0 and size
diff --git a/rpython/rlib/test/test_rfile.py b/rpython/rlib/test/test_rfile.py
--- a/rpython/rlib/test/test_rfile.py
+++ b/rpython/rlib/test/test_rfile.py
@@ -60,6 +60,8 @@
             f.write("dupa\x00dupb")
             f.close()
             f2 = open(fname)
+            dupa = f2.read(0)
+            assert dupa == ""
             dupa = f2.read()
             assert dupa == "dupa\x00dupb"
             f2.seek(0)


More information about the pypy-commit mailing list