From e9a3acd135a593cd8e9ab02f4e3b22e159da1de7 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Wed, 5 Aug 2026 10:07:15 +0200 Subject: [PATCH 1/2] gh-153711: Test availability for dup3() and pipe2() on iOS --- Doc/library/os.rst | 2 +- .../Library/2026-08-05-10-13-23.gh-issue-153711.9g9dVz.rst | 3 +++ Modules/posixmodule.c | 4 ++-- configure.ac | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2026-08-05-10-13-23.gh-issue-153711.9g9dVz.rst diff --git a/Doc/library/os.rst b/Doc/library/os.rst index 0a4a02c45b533bd..a2dd89bad9e38ab 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -1448,7 +1448,7 @@ or `the MSDN `_ on Windo Return a pair of file descriptors ``(r, w)`` usable for reading and writing, respectively. - .. availability:: Unix, macOS >= 27.0, not WASI, not iOS. + .. availability:: Unix, macOS >= 27.0, iOS >= 27.0, not WASI. .. versionadded:: 3.3 diff --git a/Misc/NEWS.d/next/Library/2026-08-05-10-13-23.gh-issue-153711.9g9dVz.rst b/Misc/NEWS.d/next/Library/2026-08-05-10-13-23.gh-issue-153711.9g9dVz.rst new file mode 100644 index 000000000000000..ca825ce6917db9a --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-08-05-10-13-23.gh-issue-153711.9g9dVz.rst @@ -0,0 +1,3 @@ +On iOS, add :func:`os.pipe2`, and use the syscalls :manpage:`pipe2 (2)` and +:manpage:`dup3 (2)` internally, when available at both build-time and +run-time. diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index db65d5862440655..a0578fa0419568f 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -504,8 +504,8 @@ static const unsigned int _Py_STATX_KNOWN = (STATX_BASIC_STATS | STATX_BTIME # define HAVE_MKFIFOAT_RUNTIME __builtin_available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) # define HAVE_MKNODAT_RUNTIME __builtin_available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) # define HAVE_PTSNAME_R_RUNTIME __builtin_available(macOS 10.13.4, iOS 11.3, tvOS 11.3, watchOS 4.3, *) -# define HAVE_DUP3_RUNTIME __builtin_available(macOS 27.0, *) -# define HAVE_PIPE2_RUNTIME __builtin_available(macOS 27.0, *) +# define HAVE_DUP3_RUNTIME __builtin_available(macOS 27.0, iOS 27.0, tvOS 27.0, watchOS 27.0, visionOS 27.0, *) +# define HAVE_PIPE2_RUNTIME __builtin_available(macOS 27.0, iOS 27.0, tvOS 27.0, watchOS 27.0, visionOS 27.0, *) # define HAVE_POSIX_SPAWN_SETSID_RUNTIME __builtin_available(macOS 10.15, *) diff --git a/configure.ac b/configure.ac index 3a9841b1e7d0747..0bc61c168a30726 100644 --- a/configure.ac +++ b/configure.ac @@ -5540,7 +5540,7 @@ fi # header definition prevents usage - autoconf doesn't use the headers), or # raise an error if used at runtime. Force these symbols off. if test "$ac_sys_system" != "iOS" ; then - AC_CHECK_FUNCS([dup3 getentropy getgroups pipe2 system]) + AC_CHECK_FUNCS([getentropy getgroups system]) fi AC_CHECK_DECL([dirfd], From 001df7d444f7f84a4afa81226293f03bdbc322d0 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Wed, 5 Aug 2026 10:32:11 +0200 Subject: [PATCH 2/2] Fix configure --- configure | 26 +++++++++++++------------- configure.ac | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/configure b/configure index 836eb88e4cdb6e5..6aa582d5ce9f32b 100755 --- a/configure +++ b/configure @@ -20394,6 +20394,12 @@ if test "x$ac_cv_func_dup" = xyes then : printf "%s\n" "#define HAVE_DUP 1" >>confdefs.h +fi +ac_fn_c_check_func "$LINENO" "dup3" "ac_cv_func_dup3" +if test "x$ac_cv_func_dup3" = xyes +then : + printf "%s\n" "#define HAVE_DUP3 1" >>confdefs.h + fi ac_fn_c_check_func "$LINENO" "execv" "ac_cv_func_execv" if test "x$ac_cv_func_execv" = xyes @@ -20868,6 +20874,12 @@ if test "x$ac_cv_func_pipe" = xyes then : printf "%s\n" "#define HAVE_PIPE 1" >>confdefs.h +fi +ac_fn_c_check_func "$LINENO" "pipe2" "ac_cv_func_pipe2" +if test "x$ac_cv_func_pipe2" = xyes +then : + printf "%s\n" "#define HAVE_PIPE2 1" >>confdefs.h + fi ac_fn_c_check_func "$LINENO" "plock" "ac_cv_func_plock" if test "x$ac_cv_func_plock" = xyes @@ -21541,13 +21553,7 @@ fi # header definition prevents usage - autoconf doesn't use the headers), or # raise an error if used at runtime. Force these symbols off. if test "$ac_sys_system" != "iOS" ; then - ac_fn_c_check_func "$LINENO" "dup3" "ac_cv_func_dup3" -if test "x$ac_cv_func_dup3" = xyes -then : - printf "%s\n" "#define HAVE_DUP3 1" >>confdefs.h - -fi -ac_fn_c_check_func "$LINENO" "getentropy" "ac_cv_func_getentropy" + ac_fn_c_check_func "$LINENO" "getentropy" "ac_cv_func_getentropy" if test "x$ac_cv_func_getentropy" = xyes then : printf "%s\n" "#define HAVE_GETENTROPY 1" >>confdefs.h @@ -21558,12 +21564,6 @@ if test "x$ac_cv_func_getgroups" = xyes then : printf "%s\n" "#define HAVE_GETGROUPS 1" >>confdefs.h -fi -ac_fn_c_check_func "$LINENO" "pipe2" "ac_cv_func_pipe2" -if test "x$ac_cv_func_pipe2" = xyes -then : - printf "%s\n" "#define HAVE_PIPE2 1" >>confdefs.h - fi ac_fn_c_check_func "$LINENO" "system" "ac_cv_func_system" if test "x$ac_cv_func_system" = xyes diff --git a/configure.ac b/configure.ac index 0bc61c168a30726..2b335ab1ff63554 100644 --- a/configure.ac +++ b/configure.ac @@ -5493,7 +5493,7 @@ fi AC_CHECK_FUNCS([ \ accept4 alarm bind_textdomain_codeset chmod chown clearenv \ clock closefrom close_range confstr \ - copy_file_range ctermid dladdr dup execv explicit_bzero explicit_memset \ + copy_file_range ctermid dladdr dup dup3 execv explicit_bzero explicit_memset \ faccessat fchmod fchmodat fchown fchownat fdopendir fdwalk fexecve \ fork fork1 fpathconf fstatat ftime ftruncate futimens futimes futimesat \ gai_strerror getegid geteuid getgid getgrent getgrgid getgrgid_r \ @@ -5502,7 +5502,7 @@ AC_CHECK_FUNCS([ \ getpwent getpwnam_r getpwuid getpwuid_r getresgid getresuid getrusage getsid getspent \ getspnam getuid getwd grantpt if_nameindex initgroups kill killpg lchown linkat \ lockf lstat lutimes madvise mbrtowc memrchr mkdirat mkfifo mkfifoat \ - mknod mknodat mktime mmap mremap nice openat opendir pathconf pause pipe \ + mknod mknodat mktime mmap mremap nice openat opendir pathconf pause pipe pipe2 \ plock poll ppoll posix_fadvise posix_fallocate posix_openpt posix_spawn posix_spawnp \ posix_spawn_file_actions_addclosefrom_np \ pread preadv preadv2 process_vm_readv \