[pypy-commit] pypy default: Backport rposix changes from py3.5 branch

rlamy pypy.commits at gmail.com
Tue May 2 12:48:02 EDT 2017


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: 
Changeset: r91169:02051354da6b
Date: 2017-05-02 17:47 +0100
http://bitbucket.org/pypy/pypy/changeset/02051354da6b/

Log:	Backport rposix changes from py3.5 branch

diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py
--- a/rpython/rlib/rposix.py
+++ b/rpython/rlib/rposix.py
@@ -261,6 +261,8 @@
 
     HAVE_UTIMES = rffi_platform.Has('utimes')
     HAVE_D_TYPE = rffi_platform.Has('DT_UNKNOWN')
+    HAVE_FALLOCATE = rffi_platform.Has('posix_fallocate')
+    HAVE_FADVISE = rffi_platform.Has('posix_fadvise')
     UTIMBUF = rffi_platform.Struct('struct %sutimbuf' % UNDERSCORE_ON_WIN32,
                                    [('actime', rffi.INT),
                                     ('modtime', rffi.INT)])
@@ -449,7 +451,7 @@
 def close(fd):
     validate_fd(fd)
     handle_posix_error('close', c_close(fd))
-
+    
 c_lseek = external('_lseeki64' if _WIN32 else 'lseek',
                    [rffi.INT, rffi.LONGLONG, rffi.INT], rffi.LONGLONG,
                    macro=_MACRO_ON_POSIX, save_err=rffi.RFFI_SAVE_ERRNO)
@@ -490,6 +492,41 @@
         with rffi.scoped_nonmovingbuffer(data) as buf:
             return handle_posix_error('pwrite', c_pwrite(fd, buf, count, offset))
 
+    if HAVE_FALLOCATE:
+        c_posix_fallocate = external('posix_fallocate',
+                                     [rffi.INT, OFF_T, OFF_T], rffi.INT,
+                                     save_err=rffi.RFFI_SAVE_ERRNO)
+
+        @enforceargs(int, None, None)
+        def posix_fallocate(fd, offset, length):
+            validate_fd(fd)
+            return handle_posix_error('posix_fallocate', c_posix_fallocate(fd, offset, length))
+
+    if HAVE_FADVISE:
+        class CConfig:
+            _compilation_info_ = eci
+            POSIX_FADV_WILLNEED = rffi_platform.DefinedConstantInteger('POSIX_FADV_WILLNEED')
+            POSIX_FADV_NORMAL = rffi_platform.DefinedConstantInteger('POSIX_FADV_NORMAL')
+            POSIX_FADV_SEQUENTIAL = rffi_platform.DefinedConstantInteger('POSIX_FADV_SEQUENTIAL')
+            POSIX_FADV_RANDOM= rffi_platform.DefinedConstantInteger('POSIX_FADV_RANDOM')
+            POSIX_FADV_NOREUSE = rffi_platform.DefinedConstantInteger('POSIX_FADV_NOREUSE')
+            POSIX_FADV_DONTNEED = rffi_platform.DefinedConstantInteger('POSIX_FADV_DONTNEED')
+
+        config = rffi_platform.configure(CConfig)
+        globals().update(config)
+
+        c_posix_fadvise = external('posix_fadvise',
+                                   [rffi.INT, OFF_T, OFF_T, rffi.INT], rffi.INT,
+                                   save_err=rffi.RFFI_SAVE_ERRNO)
+
+        @enforceargs(int, None, None, int)
+        def posix_fadvise(fd, offset, length, advice):
+            validate_fd(fd)
+            error = c_posix_fadvise(fd, offset, length, advice)
+            error = widen(error)
+            if error != 0:
+                raise OSError(error, 'posix_fadvise failed')
+
 c_ftruncate = external('ftruncate', [rffi.INT, rffi.LONGLONG], rffi.INT,
                        macro=_MACRO_ON_POSIX, save_err=rffi.RFFI_SAVE_ERRNO)
 c_fsync = external('fsync' if not _WIN32 else '_commit', [rffi.INT], rffi.INT,
@@ -2020,8 +2057,10 @@
         raise OSError(get_saved_errno(), "execve failed")
 
 if HAVE_LINKAT:
-    c_linkat = external('linkat',
-        [rffi.INT, rffi.CCHARP, rffi.INT, rffi.CCHARP, rffi.INT], rffi.INT)
+    c_linkat = external(
+        'linkat',
+        [rffi.INT, rffi.CCHARP, rffi.INT, rffi.CCHARP, rffi.INT], rffi.INT,
+        save_err=rffi.RFFI_SAVE_ERRNO)
 
     def linkat(src, dst, src_dir_fd=AT_FDCWD, dst_dir_fd=AT_FDCWD,
             follow_symlinks=True):
@@ -2036,7 +2075,8 @@
         handle_posix_error('linkat', error)
 
 if HAVE_FUTIMENS:
-    c_futimens = external('futimens', [rffi.INT, TIMESPEC2P], rffi.INT)
+    c_futimens = external('futimens', [rffi.INT, TIMESPEC2P], rffi.INT,
+                          save_err=rffi.RFFI_SAVE_ERRNO)
 
     def futimens(fd, atime, atime_ns, mtime, mtime_ns):
         l_times = lltype.malloc(TIMESPEC2P.TO, 2, flavor='raw')
@@ -2049,8 +2089,10 @@
         handle_posix_error('futimens', error)
 
 if HAVE_UTIMENSAT:
-    c_utimensat = external('utimensat',
-        [rffi.INT, rffi.CCHARP, TIMESPEC2P, rffi.INT], rffi.INT)
+    c_utimensat = external(
+        'utimensat',
+        [rffi.INT, rffi.CCHARP, TIMESPEC2P, rffi.INT], rffi.INT,
+        save_err=rffi.RFFI_SAVE_ERRNO)
 
     def utimensat(pathname, atime, atime_ns, mtime, mtime_ns,
             dir_fd=AT_FDCWD, follow_symlinks=True):
diff --git a/rpython/rlib/test/test_rposix.py b/rpython/rlib/test/test_rposix.py
--- a/rpython/rlib/test/test_rposix.py
+++ b/rpython/rlib/test/test_rposix.py
@@ -750,3 +750,34 @@
     finally:
         os.close(fd)
     py.test.raises(OSError, rposix.pwrite, fd, b'ea', 1)
+
+ at rposix_requires('posix_fadvise')
+def test_posix_fadvise():
+    fname = str(udir.join('test_os_posix_fadvise'))
+    fd = os.open(fname, os.O_CREAT | os.O_RDWR)
+    try:
+        os.write(fd, b"foobar")
+        assert rposix.posix_fadvise(fd, 0, 1, rposix.POSIX_FADV_WILLNEED) is None
+        assert rposix.posix_fadvise(fd, 1, 1, rposix.POSIX_FADV_NORMAL) is None
+        assert rposix.posix_fadvise(fd, 2, 1, rposix.POSIX_FADV_SEQUENTIAL) is None
+        assert rposix.posix_fadvise(fd, 3, 1, rposix.POSIX_FADV_RANDOM) is None
+        assert rposix.posix_fadvise(fd, 4, 1, rposix.POSIX_FADV_NOREUSE) is None
+        assert rposix.posix_fadvise(fd, 5, 1, rposix.POSIX_FADV_DONTNEED) is None
+        py.test.raises(OSError, rposix.posix_fadvise, fd, 6, 1, 1234567)
+    finally:
+        os.close(fd)
+
+ at rposix_requires('posix_fallocate')
+def test_posix_fallocate():
+    fname = str(udir.join('os_test.txt'))
+    fd = os.open(fname, os.O_WRONLY | os.O_CREAT, 0777)
+    try:
+        assert rposix.posix_fallocate(fd, 0, 10) == 0
+    except OSError as inst:
+        """ ZFS seems not to support fallocate.
+        so skipping solaris-based since it is likely to come with ZFS
+        """
+        if inst.errno != errno.EINVAL or not sys.platform.startswith("sunos"):
+            raise
+    finally:
+        os.close(fd)


More information about the pypy-commit mailing list