]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-114321: Expose more constants in the fcntl module (GH-114322)
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 22 Jan 2024 16:09:22 +0000 (18:09 +0200)
committerGitHub <noreply@github.com>
Mon, 22 Jan 2024 16:09:22 +0000 (18:09 +0200)
Doc/library/fcntl.rst
Misc/NEWS.d/next/Library/2024-01-19-18-41-02.gh-issue-114321.yj_Xw3.rst [new file with mode: 0644]
Modules/fcntlmodule.c

index 309ad652d4af34af596edb8d73062ffd335af193..13ad2dd7da5090afdd331df74ddbe7614470caba 100644 (file)
@@ -31,26 +31,26 @@ descriptor.
    raise an :exc:`OSError`.
 
 .. versionchanged:: 3.8
-   The fcntl module now contains ``F_ADD_SEALS``, ``F_GET_SEALS``, and
+   The :mod:`!fcntl` module now contains ``F_ADD_SEALS``, ``F_GET_SEALS``, and
    ``F_SEAL_*`` constants for sealing of :func:`os.memfd_create` file
    descriptors.
 
 .. versionchanged:: 3.9
-   On macOS, the fcntl module exposes the ``F_GETPATH`` constant, which obtains
-   the path of a file from a file descriptor.
-   On Linux(>=3.15), the fcntl module exposes the ``F_OFD_GETLK``, ``F_OFD_SETLK``
-   and ``F_OFD_SETLKW`` constants, which are used when working with open file
-   description locks.
+   On macOS, the :mod:`!fcntl` module exposes the ``F_GETPATH`` constant,
+   which obtains the path of a file from a file descriptor.
+   On Linux(>=3.15), the :mod:`!fcntl` module exposes the ``F_OFD_GETLK``,
+   ``F_OFD_SETLK`` and ``F_OFD_SETLKW`` constants, which are used when working
+   with open file description locks.
 
 .. versionchanged:: 3.10
-   On Linux >= 2.6.11, the fcntl module exposes the ``F_GETPIPE_SZ`` and
+   On Linux >= 2.6.11, the :mod:`!fcntl` module exposes the ``F_GETPIPE_SZ`` and
    ``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.
+   On FreeBSD, the :mod:`!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.
 
 .. versionchanged:: 3.12
    On Linux >= 4.5, the :mod:`fcntl` module exposes the ``FICLONE`` and
@@ -58,6 +58,27 @@ descriptor.
    another file by reflinking on some filesystems (e.g., btrfs, OCFS2, and
    XFS). This behavior is commonly referred to as "copy-on-write".
 
+.. versionchanged:: 3.13
+   On Linux >= 2.6.32, the :mod:`!fcntl` module exposes the
+   ``F_GETOWN_EX``, ``F_SETOWN_EX``, ``F_OWNER_TID``, ``F_OWNER_PID``, ``F_OWNER_PGRP`` constants, which allow to direct I/O availability signals
+   to a specific thread, process, or process group.
+   On Linux >= 4.13, the :mod:`!fcntl` module exposes the
+   ``F_GET_RW_HINT``, ``F_SET_RW_HINT``, ``F_GET_FILE_RW_HINT``,
+   ``F_SET_FILE_RW_HINT``, and ``RWH_WRITE_LIFE_*`` constants, which allow
+   to inform the kernel about the relative expected lifetime of writes on
+   a given inode or via a particular open file description.
+   On Linux >= 5.1 and NetBSD, the :mod:`!fcntl` module exposes the
+   ``F_SEAL_FUTURE_WRITE`` constant for use with ``F_ADD_SEALS`` and
+   ``F_GET_SEALS`` operations.
+   On FreeBSD, the :mod:`!fcntl` module exposes the ``F_READAHEAD``, ``F_ISUNIONSTACK``, and ``F_KINFO`` constants.
+   On macOS and FreeBSD, the :mod:`!fcntl` module exposes the ``F_RDAHEAD``
+   constant.
+   On NetBSD and AIX, the :mod:`!fcntl` module exposes the ``F_CLOSEM``
+   constant.
+   On NetBSD, the :mod:`!fcntl` module exposes the ``F_MAXFD`` constant.
+   On macOS and NetBSD, the :mod:`!fcntl` module exposes the ``F_GETNOSIGPIPE``
+   and ``F_SETNOSIGPIPE`` constant.
+
 The module defines the following functions:
 
 
diff --git a/Misc/NEWS.d/next/Library/2024-01-19-18-41-02.gh-issue-114321.yj_Xw3.rst b/Misc/NEWS.d/next/Library/2024-01-19-18-41-02.gh-issue-114321.yj_Xw3.rst
new file mode 100644 (file)
index 0000000..dc2934b
--- /dev/null
@@ -0,0 +1,2 @@
+Expose more platform specific constants in the :mod:`fcntl` module on Linux,
+macOS, FreeBSD and NetBSD.
index fd03abf0561da62b42596ae3b00ac6fca253dd9f..0d16602692b62d0fdaceccb42986a8f20a73fdce 100644 (file)
@@ -583,6 +583,30 @@ all_ins(PyObject* m)
 #ifdef FICLONERANGE
     if (PyModule_AddIntMacro(m, FICLONERANGE)) return -1;
 #endif
+#ifdef F_GETOWN_EX
+    // since Linux 2.6.32
+    if (PyModule_AddIntMacro(m, F_GETOWN_EX)) return -1;
+    if (PyModule_AddIntMacro(m, F_SETOWN_EX)) return -1;
+    if (PyModule_AddIntMacro(m, F_OWNER_TID)) return -1;
+    if (PyModule_AddIntMacro(m, F_OWNER_PID)) return -1;
+    if (PyModule_AddIntMacro(m, F_OWNER_PGRP)) return -1;
+#endif
+#ifdef F_GET_RW_HINT
+    // since Linux 4.13
+    if (PyModule_AddIntMacro(m, F_GET_RW_HINT)) return -1;
+    if (PyModule_AddIntMacro(m, F_SET_RW_HINT)) return -1;
+    if (PyModule_AddIntMacro(m, F_GET_FILE_RW_HINT)) return -1;
+    if (PyModule_AddIntMacro(m, F_SET_FILE_RW_HINT)) return -1;
+#ifndef RWH_WRITE_LIFE_NOT_SET  // typo in Linux < 5.5
+# define RWH_WRITE_LIFE_NOT_SET RWF_WRITE_LIFE_NOT_SET
+#endif
+    if (PyModule_AddIntMacro(m, RWH_WRITE_LIFE_NOT_SET)) return -1;
+    if (PyModule_AddIntMacro(m, RWH_WRITE_LIFE_NONE)) return -1;
+    if (PyModule_AddIntMacro(m, RWH_WRITE_LIFE_SHORT)) return -1;
+    if (PyModule_AddIntMacro(m, RWH_WRITE_LIFE_MEDIUM)) return -1;
+    if (PyModule_AddIntMacro(m, RWH_WRITE_LIFE_LONG)) return -1;
+    if (PyModule_AddIntMacro(m, RWH_WRITE_LIFE_EXTREME)) return -1;
+#endif
 
 /* OS X specifics */
 #ifdef F_FULLFSYNC
@@ -599,6 +623,32 @@ all_ins(PyObject* m)
 #ifdef F_DUP2FD_CLOEXEC
     if (PyModule_AddIntMacro(m, F_DUP2FD_CLOEXEC)) return -1;
 #endif
+#ifdef F_READAHEAD
+    if (PyModule_AddIntMacro(m, F_READAHEAD)) return -1;
+#endif
+#ifdef F_RDAHEAD
+    if (PyModule_AddIntMacro(m, F_RDAHEAD)) return -1;
+#endif
+#ifdef F_ISUNIONSTACK
+    if (PyModule_AddIntMacro(m, F_ISUNIONSTACK)) return -1;
+#endif
+#ifdef F_KINFO
+    if (PyModule_AddIntMacro(m, F_KINFO)) return -1;
+#endif
+
+/* NetBSD specifics */
+#ifdef F_CLOSEM
+    if (PyModule_AddIntMacro(m, F_CLOSEM)) return -1;
+#endif
+#ifdef F_MAXFD
+    if (PyModule_AddIntMacro(m, F_MAXFD)) return -1;
+#endif
+#ifdef F_GETNOSIGPIPE
+    if (PyModule_AddIntMacro(m, F_GETNOSIGPIPE)) return -1;
+#endif
+#ifdef F_SETNOSIGPIPE
+    if (PyModule_AddIntMacro(m, F_SETNOSIGPIPE)) return -1;
+#endif
 
 /* For F_{GET|SET}FL */
 #ifdef FD_CLOEXEC
@@ -673,6 +723,9 @@ all_ins(PyObject* m)
     if (PyModule_AddIntMacro(m, F_SEAL_SHRINK)) return -1;
     if (PyModule_AddIntMacro(m, F_SEAL_GROW)) return -1;
     if (PyModule_AddIntMacro(m, F_SEAL_WRITE)) return -1;
+#ifdef F_SEAL_FUTURE_WRITE
+    if (PyModule_AddIntMacro(m, F_SEAL_FUTURE_WRITE)) return -1;
+#endif
 #endif
     return 0;
 }