Author: Manuel Jacob <[email protected]>
Branch:
Changeset: r90534:0251b34cb8ee
Date: 2017-03-04 13:30 +0100
http://bitbucket.org/pypy/pypy/changeset/0251b34cb8ee/
Log: Reuse rposix.c_read in these two places instead of redefining an
almost identical llexternal.
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
@@ -1,16 +1,10 @@
-import sys, errno
+import errno
from rpython.rlib import rposix
from rpython.rlib.objectmodel import keepalive_until_here
+from rpython.rlib.rposix import c_read
from rpython.rtyper.lltypesystem import lltype, rffi
from pypy.module._file.interp_file import is_wouldblock_error, signal_checker
-_WIN32 = sys.platform.startswith('win')
-UNDERSCORE_ON_WIN32 = '_' if _WIN32 else ''
-
-os_read = rffi.llexternal(UNDERSCORE_ON_WIN32 + 'read',
- [rffi.INT, rffi.CCHARP, rffi.SIZE_T],
- rffi.SSIZE_T, save_err=rffi.RFFI_SAVE_ERRNO)
-
def direct_readinto(self, w_rwbuffer):
rwbuffer = self.space.writebuf_w(w_rwbuffer)
@@ -56,11 +50,11 @@
target_pos += len(data)
size -= len(data)
- # then call os_read() to get the rest
+ # then call c_read() to get the rest
if size > 0:
stream.flush()
while True:
- got = os_read(fd, rffi.ptradd(target_address, target_pos),
size)
+ got = c_read(fd, rffi.ptradd(target_address, target_pos), size)
got = rffi.cast(lltype.Signed, got)
if got > 0:
target_pos += got
diff --git a/pypy/module/_io/interp_fileio.py b/pypy/module/_io/interp_fileio.py
--- a/pypy/module/_io/interp_fileio.py
+++ b/pypy/module/_io/interp_fileio.py
@@ -4,7 +4,7 @@
OperationError, oefmt, wrap_oserror, wrap_oserror2)
from rpython.rlib.objectmodel import keepalive_until_here
from rpython.rlib.rarithmetic import r_longlong
-from rpython.rlib.rposix import get_saved_errno
+from rpython.rlib.rposix import c_read, get_saved_errno
from rpython.rlib.rstring import StringBuilder
from rpython.rtyper.lltypesystem import lltype, rffi
from os import O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_TRUNC
@@ -116,14 +116,6 @@
return currentsize + SMALLCHUNK
-_WIN32 = sys.platform.startswith('win')
-UNDERSCORE_ON_WIN32 = '_' if _WIN32 else ''
-
-os_read = rffi.llexternal(UNDERSCORE_ON_WIN32 + 'read',
- [rffi.INT, rffi.CCHARP, rffi.SIZE_T],
- rffi.SSIZE_T, save_err=rffi.RFFI_SAVE_ERRNO)
-
-
class W_FileIO(W_RawIOBase):
def __init__(self, space):
W_RawIOBase.__init__(self, space)
@@ -402,7 +394,7 @@
else:
# optimized case: reading more than 64 bytes into a rwbuffer
# with a valid raw address
- got = os_read(self.fd, target_address, length)
+ got = c_read(self.fd, target_address, length)
keepalive_until_here(rwbuffer)
got = rffi.cast(lltype.Signed, got)
if got >= 0:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit