[pypy-commit] pypy default: Add rposix.{get, set}_inheritable(), needed by Python 3.5
arigo
pypy.commits at gmail.com
Tue Aug 16 14:06:33 EDT 2016
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r86229:5066ac85f54d
Date: 2016-08-16 17:06 +0200
http://bitbucket.org/pypy/pypy/changeset/5066ac85f54d/
Log: Add rposix.{get,set}_inheritable(), needed by Python 3.5
diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py
--- a/rpython/rlib/rposix.py
+++ b/rpython/rlib/rposix.py
@@ -2049,3 +2049,40 @@
def mknodat(path, mode, device, dir_fd=AT_FDCWD):
error = c_mknodat(dir_fd, path, mode, device)
handle_posix_error('mknodat', error)
+
+
+eci_inheritable = eci.merge(ExternalCompilationInfo(
+ separate_module_sources=["""
+RPY_EXTERN
+int rpy_set_inheritable(int fd, int inheritable)
+{
+ /* XXX minimal impl. XXX */
+ int request = inheritable ? FIONCLEX : FIOCLEX;
+ return ioctl(fd, request, NULL);
+}
+RPY_EXTERN
+int rpy_get_inheritable(int fd)
+{
+ int flags = fcntl(fd, F_GETFD, 0);
+ if (flags == -1)
+ return -1;
+ return !(flags & FD_CLOEXEC);
+}
+ """],
+ post_include_bits=['RPY_EXTERN int rpy_set_inheritable(int, int);']))
+
+c_set_inheritable = external('rpy_set_inheritable', [rffi.INT, rffi.INT],
+ rffi.INT, save_err=rffi.RFFI_SAVE_ERRNO,
+ compilation_info=eci_inheritable)
+c_get_inheritable = external('rpy_get_inheritable', [rffi.INT],
+ rffi.INT, save_err=rffi.RFFI_SAVE_ERRNO,
+ compilation_info=eci_inheritable)
+
+def set_inheritable(fd, inheritable):
+ error = c_set_inheritable(fd, inheritable)
+ handle_posix_error('set_inheritable', error)
+
+def get_inheritable(fd):
+ res = c_get_inheritable(fd)
+ res = handle_posix_error('get_inheritable', res)
+ return res != 0
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
@@ -572,3 +572,12 @@
os.close(dirfd)
assert tmpdir.join('file').check(exists=False)
assert tmpdir.join('file2').check(exists=True)
+
+def test_set_inheritable():
+ fd1, fd2 = os.pipe()
+ rposix.set_inheritable(fd1, True)
+ assert rposix.get_inheritable(fd1) == True
+ rposix.set_inheritable(fd1, False)
+ assert rposix.get_inheritable(fd1) == False
+ os.close(fd1)
+ os.close(fd2)
More information about the pypy-commit
mailing list