[Python-checkins] bpo-46016: fcntl module add FreeBSD's F_DUP2FD_CLOEXEC flag support (GH-29993)

vstinner webhook-mailer at python.org
Wed Dec 8 17:28:56 EST 2021


https://github.com/python/cpython/commit/267539bff700c2493778c07eeb1642b9584c4826
commit: 267539bff700c2493778c07eeb1642b9584c4826
branch: main
author: David CARLIER <devnexen at gmail.com>
committer: vstinner <vstinner at python.org>
date: 2021-12-08T23:28:51+01:00
summary:

bpo-46016: fcntl module add FreeBSD's F_DUP2FD_CLOEXEC flag support (GH-29993)

files:
A Misc/NEWS.d/next/Library/2021-12-08-19-15-03.bpo-46016.s9PuyF.rst
M Doc/library/fcntl.rst
M Doc/whatsnew/3.11.rst
M Modules/fcntlmodule.c

diff --git a/Doc/library/fcntl.rst b/Doc/library/fcntl.rst
index 9d8021150c42f..846c8d7ba96da 100644
--- a/Doc/library/fcntl.rst
+++ b/Doc/library/fcntl.rst
@@ -44,6 +44,11 @@ descriptor.
    ``F_SETPIPE_SZ`` constants, which allow to check and modify a pipe's size
    respectively.
 
+.. versionchanged:: 3.11
+   On FreeBSD, the fcntl module exposes the ``F_DUP2FD`` and ``F_DUP2FD_CLOEXEC``
+   constants, which allow to duplicate a file descriptor, the latter setting
+   ``FD_CLOEXEC`` flag in addition.
+
 The module defines the following functions:
 
 
diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst
index a570864743d47..264a801da7899 100644
--- a/Doc/whatsnew/3.11.rst
+++ b/Doc/whatsnew/3.11.rst
@@ -329,6 +329,14 @@ unicodedata
 * The Unicode database has been updated to version 14.0.0. (:issue:`45190`).
 
 
+fcntl
+-----
+
+* On FreeBSD, the `F_DUP2FD` and `F_DUP2FD_CLOEXEC` flags respectively
+  are supported, the former equals to ``dup2`` usage while the latter set
+  the ``FD_CLOEXEC`` flag in addition.
+
+
 Optimizations
 =============
 
diff --git a/Misc/NEWS.d/next/Library/2021-12-08-19-15-03.bpo-46016.s9PuyF.rst b/Misc/NEWS.d/next/Library/2021-12-08-19-15-03.bpo-46016.s9PuyF.rst
new file mode 100644
index 0000000000000..7308c542aacf5
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-12-08-19-15-03.bpo-46016.s9PuyF.rst
@@ -0,0 +1 @@
+Adding `F_DUP2FD` and `F_DUP2FD_CLOEXEC` constants from FreeBSD into the fcntl module.
diff --git a/Modules/fcntlmodule.c b/Modules/fcntlmodule.c
index cdf0f9bf3790e..ea9b2bc14a9f2 100644
--- a/Modules/fcntlmodule.c
+++ b/Modules/fcntlmodule.c
@@ -581,6 +581,14 @@ all_ins(PyObject* m)
     if (PyModule_AddIntMacro(m, F_NOCACHE)) return -1;
 #endif
 
+/* FreeBSD specifics */
+#ifdef F_DUP2FD
+    if (PyModule_AddIntMacro(m, F_DUP2FD)) return -1;
+#endif
+#ifdef F_DUP2FD_CLOEXEC
+    if (PyModule_AddIntMacro(m, F_DUP2FD_CLOEXEC)) return -1;
+#endif
+
 /* For F_{GET|SET}FL */
 #ifdef FD_CLOEXEC
     if (PyModule_AddIntMacro(m, FD_CLOEXEC)) return -1;



More information about the Python-checkins mailing list