Author: Armin Rigo <[email protected]>
Branch:
Changeset: r80344:21e8a29ec071
Date: 2015-10-20 09:11 +0200
http://bitbucket.org/pypy/pypy/changeset/21e8a29ec071/
Log: Issue #2166: the 'read' function in C returns a ssize_t. Checking
if '(size_t)-1' is positive will say True!
diff --git a/pypy/module/_file/readinto.py b/pypy/module/_file/readinto.py
--- a/pypy/module/_file/readinto.py
+++ b/pypy/module/_file/readinto.py
@@ -9,7 +9,7 @@
os_read = rffi.llexternal(UNDERSCORE_ON_WIN32 + 'read',
[rffi.INT, rffi.CCHARP, rffi.SIZE_T],
- rffi.SIZE_T, save_err=rffi.RFFI_SAVE_ERRNO)
+ rffi.SSIZE_T, save_err=rffi.RFFI_SAVE_ERRNO)
def direct_readinto(self, w_rwbuffer):
@@ -61,6 +61,7 @@
stream.flush()
while True:
got = os_read(fd, rffi.ptradd(target_address, target_pos),
size)
+ got = rffi.cast(lltype.Signed, got)
if got > 0:
target_pos += got
size -= got
diff --git a/pypy/module/_file/test/test_file_extra.py
b/pypy/module/_file/test/test_file_extra.py
--- a/pypy/module/_file/test/test_file_extra.py
+++ b/pypy/module/_file/test/test_file_extra.py
@@ -572,6 +572,17 @@
assert len(a) == 10
assert a.tostring() == 'foobar6789'
+ @py.test.mark.skipif("os.name != 'posix'")
+ def test_readinto_error(self):
+ import _socket, posix, array
+ s = _socket.socket()
+ buff = array.array("c", "X" * 65)
+ fh = posix.fdopen(posix.dup(s.fileno()), 'rb')
+ # "Transport endpoint is not connected"
+ raises(IOError, fh.readinto, buff)
+ fh.close()
+ s.close()
+
def test_weakref(self):
"""Files are weakrefable."""
import weakref
diff --git a/rpython/rtyper/module/ll_os.py b/rpython/rtyper/module/ll_os.py
--- a/rpython/rtyper/module/ll_os.py
+++ b/rpython/rtyper/module/ll_os.py
@@ -1022,7 +1022,7 @@
def register_os_read(self):
os_read = self.llexternal(UNDERSCORE_ON_WIN32 + 'read',
[rffi.INT, rffi.VOIDP, rffi.SIZE_T],
- rffi.SIZE_T, save_err=rffi.RFFI_SAVE_ERRNO)
+ rffi.SSIZE_T, save_err=rffi.RFFI_SAVE_ERRNO)
def os_read_llimpl(fd, count):
if count < 0:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit