Author: Dan Villiom Podlaski Christiansen <[email protected]>
Branch: py3.5-mac-translate
Changeset: r91079:4e08bb45b11b
Date: 2017-04-18 12:55 +0200
http://bitbucket.org/pypy/pypy/changeset/4e08bb45b11b/
Log: Add checks for posix_fadvise() and posix_fallocate()
macOS Sierra does not define these, and CPython 3.5 does not include
them in its 'posix' module. Without this, translation on my Mac
fails with an assertion failure when posix_fadvise() exists but the
constants do not.
diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py
--- a/rpython/rlib/rposix.py
+++ b/rpython/rlib/rposix.py
@@ -255,18 +255,14 @@
PRIO_PROCESS = rffi_platform.DefinedConstantInteger('PRIO_PROCESS')
PRIO_PGRP = rffi_platform.DefinedConstantInteger('PRIO_PGRP')
PRIO_USER = rffi_platform.DefinedConstantInteger('PRIO_USER')
- 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')
O_NONBLOCK = rffi_platform.DefinedConstantInteger('O_NONBLOCK')
OFF_T = rffi_platform.SimpleType('off_t')
OFF_T_SIZE = rffi_platform.SizeOf('off_t')
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)])
@@ -496,22 +492,37 @@
with rffi.scoped_nonmovingbuffer(data) as buf:
return handle_posix_error('pwrite', c_pwrite(fd, buf, count,
offset))
- c_posix_fallocate = external('posix_fallocate',
- [rffi.INT, OFF_T, OFF_T], rffi.INT,
- save_err=rffi.RFFI_SAVE_ERRNO)
- c_posix_fadvise = external('posix_fadvise',
- [rffi.INT, OFF_T, OFF_T, rffi.INT], rffi.INT,
- save_err=rffi.RFFI_SAVE_ERRNO)
+ 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))
+ @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))
- @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))
+ 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)
+ return handle_posix_error('posix_fadvise', c_posix_fadvise(fd,
offset, length, advice))
c_ftruncate = external('ftruncate', [rffi.INT, rffi.LONGLONG], rffi.INT,
macro=_MACRO_ON_POSIX, save_err=rffi.RFFI_SAVE_ERRNO)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit