]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-108765: Python.h no longer includes <unistd.h> (#108783)
authorVictor Stinner <vstinner@python.org>
Sat, 2 Sep 2023 14:50:18 +0000 (16:50 +0200)
committerGitHub <noreply@github.com>
Sat, 2 Sep 2023 14:50:18 +0000 (16:50 +0200)
16 files changed:
Doc/whatsnew/3.13.rst
Include/Python.h
Misc/NEWS.d/next/C API/2023-09-01-21-10-29.gh-issue-108765.eeXtYF.rst [new file with mode: 0644]
Modules/_ctypes/malloc_closure.c
Modules/_posixsubprocess.c
Modules/_testcapimodule.c
Modules/grpmodule.c
Modules/mmapmodule.c
Modules/posixmodule.c
Modules/pwdmodule.c
Modules/resource.c
Modules/selectmodule.c
Modules/socketmodule.c
Programs/_freeze_module.c
Python/dup2.c
Python/perf_trampoline.c

index eb3d8323daaf0e7a66910bc91cbcced7bf561878..401de11b34ec5fc408ea0ebf57d16ddc167a0cc9 100644 (file)
@@ -929,6 +929,11 @@ Porting to Python 3.13
   also the ``HAVE_IEEEFP_H`` macro.
   (Contributed by Victor Stinner in :gh:`108765`.)
 
+* ``Python.h`` no longer includes the ``<unistd.h>`` standard header file. If
+  needed, it should now be included explicitly. For example, it provides the
+  functions: ``close()``, ``getpagesize()``, ``getpid()`` and ``sysconf()``.
+  (Contributed by Victor Stinner in :gh:`108765`.)
+
 Deprecated
 ----------
 
index 002a79dbdc93629d46d20311b6e164ce51f87372..4cc72bb23ce7a3d80e4e38d88a23626e5390d2c6 100644 (file)
 #ifdef HAVE_STDDEF_H
 #  include <stddef.h>             // size_t
 #endif
-#ifndef MS_WINDOWS
-#  include <unistd.h>             // sysconf()
+#ifdef HAVE_SYS_TYPES_H
+#  include <sys/types.h>          // ssize_t
 #endif
 
-// errno.h, stdio.h, stdlib.h and string.h headers are no longer used by Python
-// headers, but kept for backward compatibility (no introduce new compiler
-// warnings). They are not included by the limited C API version 3.11 and
-// above.
+// errno.h, stdio.h, stdlib.h and string.h headers are no longer used by
+// Python, but kept for backward compatibility (avoid compiler warnings).
+// They are no longer included by limited C API version 3.11 and newer.
 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
 #  include <errno.h>              // errno
 #  include <stdio.h>              // FILE*
diff --git a/Misc/NEWS.d/next/C API/2023-09-01-21-10-29.gh-issue-108765.eeXtYF.rst b/Misc/NEWS.d/next/C API/2023-09-01-21-10-29.gh-issue-108765.eeXtYF.rst
new file mode 100644 (file)
index 0000000..ff8f799
--- /dev/null
@@ -0,0 +1,4 @@
+``Python.h`` no longer includes the ``<unistd.h>`` standard header file. If
+needed, it should now be included explicitly. For example, it provides the
+functions: ``close()``, ``getpagesize()``, ``getpid()`` and ``sysconf()``.
+Patch by Victor Stinner.
index 3a859322772ba720d518588208b3141f40c9ffdb..bb4f8f21bd3f7787d55e79b0e7dbcae5549ab23d 100644 (file)
@@ -1,16 +1,17 @@
 #ifndef Py_BUILD_CORE_BUILTIN
 #  define Py_BUILD_CORE_MODULE 1
 #endif
+
 #include <Python.h>
 #include <ffi.h>
 #ifdef MS_WIN32
-#include <windows.h>
+#  include <windows.h>
 #else
-#include <sys/mman.h>
-#include <unistd.h>
-# if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
-#  define MAP_ANONYMOUS MAP_ANON
-# endif
+#  include <sys/mman.h>
+#  include <unistd.h>             // sysconf()
+#  if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
+#    define MAP_ANONYMOUS MAP_ANON
+#  endif
 #endif
 #include "ctypes.h"
 
index ac2b0d4f55468c42d5c0b3135fffde18936ac7d9..ef76d26282e1b324bd03b18e5766c435359062e7 100644 (file)
@@ -8,28 +8,28 @@
 #include "pycore_pystate.h"
 #include "pycore_signal.h"        // _Py_RestoreSignals()
 #if defined(HAVE_PIPE2) && !defined(_GNU_SOURCE)
-# define _GNU_SOURCE
+#  define _GNU_SOURCE
 #endif
-#include <unistd.h>
-#include <fcntl.h>
+#include <unistd.h>               // close()
+#include <fcntl.h>                // fcntl()
 #ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
+#  include <sys/types.h>
 #endif
 #if defined(HAVE_SYS_STAT_H)
-#include <sys/stat.h>
+#  include <sys/stat.h>           // stat()
 #endif
 #ifdef HAVE_SYS_SYSCALL_H
-#include <sys/syscall.h>
+#  include <sys/syscall.h>
 #endif
 #if defined(HAVE_SYS_RESOURCE_H)
-#include <sys/resource.h>
+#  include <sys/resource.h>
 #endif
 #ifdef HAVE_DIRENT_H
-#include <dirent.h>
+#  include <dirent.h>             // opendir()
+#endif
+#if defined(HAVE_SETGROUPS)
+#  include <grp.h>                // setgroups()
 #endif
-#ifdef HAVE_GRP_H
-#include <grp.h>
-#endif /* HAVE_GRP_H */
 
 #include "posixmodule.h"
 
index 4fc354ae79bfed4bfcc94e327a84b9f2681eb8df..ab33702cdfd872474877433d51ccf5afb5028f31 100644 (file)
@@ -24,9 +24,6 @@
 #include <float.h>                // FLT_MAX
 #include <signal.h>
 #include <stddef.h>               // offsetof()
-#ifndef MS_WINDOWS
-#  include <unistd.h>
-#endif
 
 #ifdef HAVE_SYS_WAIT_H
 #  include <sys/wait.h>           // W_STOPCODE
index f5709296334a8fa4494f7a6d52568721ed3b0599..20e83de84e8340f8611fc3f05562ebc7c1455a17 100644 (file)
@@ -4,7 +4,8 @@
 #include "Python.h"
 #include "posixmodule.h"
 
-#include <grp.h>
+#include <grp.h>                  // getgrgid_r()
+#include <unistd.h>               // sysconf()
 
 #include "clinic/grpmodule.c.h"
 /*[clinic input]
index c8cd7e59dbab5008bd33d51243602574d0b4710d..d11200a40425518c42927c67e3ba1a2aeaa7d294 100644 (file)
@@ -28,6 +28,9 @@
 #include "pycore_fileutils.h"     // _Py_stat_struct
 
 #include <stddef.h>               // offsetof()
+#ifndef MS_WINDOWS
+#  include <unistd.h>             // close()
+#endif
 
 // to support MS_WINDOWS_SYSTEM OpenFileMappingA / CreateFileMappingA
 // need to be replaced with OpenFileMappingW / CreateFileMappingW
index 761542866d8f96cfe2bc0e9fc291e33cf9761527..6e829b200fa46df128f702cc448b06a9d5500142 100644 (file)
@@ -286,7 +286,7 @@ corresponding Unix manual entries for more information on calls.");
 #endif
 
 #ifdef HAVE_COPY_FILE_RANGE
-#  include <unistd.h>
+#  include <unistd.h>             // copy_file_range()
 #endif
 
 #if !defined(CPU_ALLOC) && defined(HAVE_SCHED_SETAFFINITY)
index cc2e2a43893971d4a2f8dc5036b78c74e0278362..b7034369c4731eeafaa0dc946e951330f2f7c07f 100644 (file)
@@ -4,7 +4,8 @@
 #include "Python.h"
 #include "posixmodule.h"
 
-#include <pwd.h>
+#include <pwd.h>                  // getpwuid()
+#include <unistd.h>               // sysconf()
 
 #include "clinic/pwdmodule.c.h"
 /*[clinic input]
index 4614f5e98cc888c3f1121460c68098a99c48f804..f5d9972d9a8ff79e9365b30500811e211e6623e5 100644 (file)
@@ -1,13 +1,12 @@
-
 #include "Python.h"
-#include <sys/resource.h>
+#include <errno.h>                // errno
+#include <string.h>
+#include <sys/resource.h>         // getrusage()
 #ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
+#  include <sys/time.h>
 #endif
 #include <time.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
+#include <unistd.h>               // getpagesize()
 
 /* On some systems, these aren't in any header file.
    On others they are, with inconsistent prototypes.
index 4987cf0f2065c2d1b11235566995785c3b0dde0b..c56e682b21e2a1e1745c47e5fa2fc38063ce918b 100644 (file)
@@ -17,6 +17,9 @@
 #include "pycore_time.h"          // _PyTime_t
 
 #include <stddef.h>               // offsetof()
+#ifndef MS_WINDOWS
+#  include <unistd.h>             // close()
+#endif
 
 #ifdef HAVE_SYS_DEVPOLL_H
 #include <sys/resource.h>
index 2f12c9cedbd8a6b0f8a79b4cdce7774ae31592d3..74b1c1c661604f122791770d1197075b5a442f6b 100644 (file)
@@ -269,7 +269,7 @@ shutdown(how) -- shut down traffic in one or both directions\n\
 #ifdef HAVE_NETDB_H
 #  include <netdb.h>
 #endif
-# include <unistd.h>
+#include <unistd.h>               // close()
 
 /* Headers needed for inet_ntoa() and inet_addr() */
 #   include <arpa/inet.h>
index e55f1d56745c4dcab8f6bc10e7b95ddb657d2faf..f6c46fa629efba9481a79e9b37ea73e0cc5d0321 100644 (file)
@@ -19,7 +19,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #ifndef MS_WINDOWS
-#include <unistd.h>
+#  include <unistd.h>
 #endif
 
 uint32_t _Py_next_func_version = 1;
index a1df0492099163982661b996e697c708c0235783..936211f27ec7374abff53fb8e685088fce5c12b4 100644 (file)
@@ -11,9 +11,9 @@
  * Return fd2 if all went well; return BADEXIT otherwise.
  */
 
-#include <errno.h>
-#include <fcntl.h>
-#include <unistd.h>
+#include <errno.h>                // errno
+#include <fcntl.h>                // fcntl()
+#include <unistd.h>               // close()
 
 #define BADEXIT -1
 
index b8885a303977d0f6ca46ce70f3d446fc0162d75f..10675bf9f8292a65b6d1e6ccc6333fc2936c8c01 100644 (file)
@@ -140,9 +140,9 @@ any DWARF information available for them).
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <sys/mman.h>
+#include <sys/mman.h>             // mmap()
 #include <sys/types.h>
-#include <unistd.h>
+#include <unistd.h>               // sysconf()
 
 #if defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
 #define PY_HAVE_INVALIDATE_ICACHE