[pypy-commit] pypy py3.5: Fix test, broken on several levels, and fix implementation to match.
arigo
pypy.commits at gmail.com
Wed Apr 19 06:47:38 EDT 2017
Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5
Changeset: r91092:0c746868b18a
Date: 2017-04-19 11:47 +0100
http://bitbucket.org/pypy/pypy/changeset/0c746868b18a/
Log: Fix test, broken on several levels, and fix implementation to match.
diff --git a/pypy/module/posix/interp_posix.py b/pypy/module/posix/interp_posix.py
--- a/pypy/module/posix/interp_posix.py
+++ b/pypy/module/posix/interp_posix.py
@@ -419,11 +419,11 @@
"""
while True:
try:
- res = rposix.posix_fadvise(fd, offset, length, advice)
+ rposix.posix_fadvise(fd, offset, length, advice)
except OSError as e:
wrap_oserror(space, e, eintr_retry=True)
else:
- return space.newint(res)
+ return
# ____________________________________________________________
diff --git a/pypy/module/posix/test/test_posix2.py b/pypy/module/posix/test/test_posix2.py
--- a/pypy/module/posix/test/test_posix2.py
+++ b/pypy/module/posix/test/test_posix2.py
@@ -862,23 +862,19 @@
if hasattr(rposix, 'posix_fadvise'):
def test_os_posix_fadvise(self):
- posix, os = self.posix, self.os
- localdir = os.getcwd()
- os.mkdir(self.path2 + 'test_os_posix_fadvise')
+ posix = self.posix
+ fd = posix.open(self.path2 + 'test_os_posix_fadvise', posix.O_CREAT | posix.O_RDWR)
try:
- fd = os.open(self.path2 + 'test_os_posix_fadvise', os.O_RDONLY)
- try:
- mypath = os.getcwd()
- assert posix.posix_fadvise(fd, 0, 0, posix.POSIX_FADV_WILLNEED) == 0
- assert posix.posix_fadvise(fd, 0, 0, posix.POSIX_FADV_NORMAL) == 0
- assert posix.posix_fadvise(fd, 0, 0, posix.POSIX_FADV_SEQUENTIAL) == 0
- assert posix.posix_fadvise(fd, 0, 0, posix.POSIX_FADV_RANDOM) == 0
- assert posix.posix_fadvise(fd, 0, 0, posix.POSIX_FADV_NOREUSE) == 0
- assert posix.posix_fadvise(fd, 0, 0, posix.POSIX_FADV_DONTNEED) == 0
- finally:
- os.close(fd)
+ posix.write(fd, b"foobar")
+ assert posix.posix_fadvise(fd, 0, 1, posix.POSIX_FADV_WILLNEED) is None
+ assert posix.posix_fadvise(fd, 1, 1, posix.POSIX_FADV_NORMAL) is None
+ assert posix.posix_fadvise(fd, 2, 1, posix.POSIX_FADV_SEQUENTIAL) is None
+ assert posix.posix_fadvise(fd, 3, 1, posix.POSIX_FADV_RANDOM) is None
+ assert posix.posix_fadvise(fd, 4, 1, posix.POSIX_FADV_NOREUSE) is None
+ assert posix.posix_fadvise(fd, 5, 1, posix.POSIX_FADV_DONTNEED) is None
+ raises(OSError, posix.posix_fadvise, fd, 6, 1, 1234567)
finally:
- os.chdir(localdir)
+ posix.close(fd)
if hasattr(rposix, 'posix_fallocate'):
def test_os_posix_posix_fallocate(self):
diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py
--- a/rpython/rlib/rposix.py
+++ b/rpython/rlib/rposix.py
@@ -522,7 +522,10 @@
@enforceargs(int, None, None, int)
def posix_fadvise(fd, offset, length, advice):
validate_fd(fd)
- return handle_posix_error('posix_fadvise', c_posix_fadvise(fd, offset, length, advice))
+ 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)
More information about the pypy-commit
mailing list