gh-108765: Python.h no longer includes <unistd.h> (#108783)

This commit is contained in:
Victor Stinner 2023-09-02 16:50:18 +02:00 committed by GitHub
parent 4f9b706c6f
commit 594b00057e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 55 additions and 42 deletions

View File

@ -929,6 +929,11 @@ Porting to Python 3.13
also the ``HAVE_IEEEFP_H`` macro. also the ``HAVE_IEEEFP_H`` macro.
(Contributed by Victor Stinner in :gh:`108765`.) (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 Deprecated
---------- ----------

View File

@ -26,14 +26,13 @@
#ifdef HAVE_STDDEF_H #ifdef HAVE_STDDEF_H
# include <stddef.h> // size_t # include <stddef.h> // size_t
#endif #endif
#ifndef MS_WINDOWS #ifdef HAVE_SYS_TYPES_H
# include <unistd.h> // sysconf() # include <sys/types.h> // ssize_t
#endif #endif
// errno.h, stdio.h, stdlib.h and string.h headers are no longer used by Python // errno.h, stdio.h, stdlib.h and string.h headers are no longer used by
// headers, but kept for backward compatibility (no introduce new compiler // Python, but kept for backward compatibility (avoid compiler warnings).
// warnings). They are not included by the limited C API version 3.11 and // They are no longer included by limited C API version 3.11 and newer.
// above.
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
# include <errno.h> // errno # include <errno.h> // errno
# include <stdio.h> // FILE* # include <stdio.h> // FILE*

View File

@ -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.

View File

@ -1,16 +1,17 @@
#ifndef Py_BUILD_CORE_BUILTIN #ifndef Py_BUILD_CORE_BUILTIN
# define Py_BUILD_CORE_MODULE 1 # define Py_BUILD_CORE_MODULE 1
#endif #endif
#include <Python.h> #include <Python.h>
#include <ffi.h> #include <ffi.h>
#ifdef MS_WIN32 #ifdef MS_WIN32
#include <windows.h> # include <windows.h>
#else #else
#include <sys/mman.h> # include <sys/mman.h>
#include <unistd.h> # include <unistd.h> // sysconf()
# if !defined(MAP_ANONYMOUS) && defined(MAP_ANON) # if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
# define MAP_ANONYMOUS MAP_ANON # define MAP_ANONYMOUS MAP_ANON
# endif # endif
#endif #endif
#include "ctypes.h" #include "ctypes.h"

View File

@ -8,28 +8,28 @@
#include "pycore_pystate.h" #include "pycore_pystate.h"
#include "pycore_signal.h" // _Py_RestoreSignals() #include "pycore_signal.h" // _Py_RestoreSignals()
#if defined(HAVE_PIPE2) && !defined(_GNU_SOURCE) #if defined(HAVE_PIPE2) && !defined(_GNU_SOURCE)
# define _GNU_SOURCE # define _GNU_SOURCE
#endif #endif
#include <unistd.h> #include <unistd.h> // close()
#include <fcntl.h> #include <fcntl.h> // fcntl()
#ifdef HAVE_SYS_TYPES_H #ifdef HAVE_SYS_TYPES_H
#include <sys/types.h> # include <sys/types.h>
#endif #endif
#if defined(HAVE_SYS_STAT_H) #if defined(HAVE_SYS_STAT_H)
#include <sys/stat.h> # include <sys/stat.h> // stat()
#endif #endif
#ifdef HAVE_SYS_SYSCALL_H #ifdef HAVE_SYS_SYSCALL_H
#include <sys/syscall.h> # include <sys/syscall.h>
#endif #endif
#if defined(HAVE_SYS_RESOURCE_H) #if defined(HAVE_SYS_RESOURCE_H)
#include <sys/resource.h> # include <sys/resource.h>
#endif #endif
#ifdef HAVE_DIRENT_H #ifdef HAVE_DIRENT_H
#include <dirent.h> # include <dirent.h> // opendir()
#endif
#if defined(HAVE_SETGROUPS)
# include <grp.h> // setgroups()
#endif #endif
#ifdef HAVE_GRP_H
#include <grp.h>
#endif /* HAVE_GRP_H */
#include "posixmodule.h" #include "posixmodule.h"

View File

@ -24,9 +24,6 @@
#include <float.h> // FLT_MAX #include <float.h> // FLT_MAX
#include <signal.h> #include <signal.h>
#include <stddef.h> // offsetof() #include <stddef.h> // offsetof()
#ifndef MS_WINDOWS
# include <unistd.h>
#endif
#ifdef HAVE_SYS_WAIT_H #ifdef HAVE_SYS_WAIT_H
# include <sys/wait.h> // W_STOPCODE # include <sys/wait.h> // W_STOPCODE

View File

@ -4,7 +4,8 @@
#include "Python.h" #include "Python.h"
#include "posixmodule.h" #include "posixmodule.h"
#include <grp.h> #include <grp.h> // getgrgid_r()
#include <unistd.h> // sysconf()
#include "clinic/grpmodule.c.h" #include "clinic/grpmodule.c.h"
/*[clinic input] /*[clinic input]

View File

@ -28,6 +28,9 @@
#include "pycore_fileutils.h" // _Py_stat_struct #include "pycore_fileutils.h" // _Py_stat_struct
#include <stddef.h> // offsetof() #include <stddef.h> // offsetof()
#ifndef MS_WINDOWS
# include <unistd.h> // close()
#endif
// to support MS_WINDOWS_SYSTEM OpenFileMappingA / CreateFileMappingA // to support MS_WINDOWS_SYSTEM OpenFileMappingA / CreateFileMappingA
// need to be replaced with OpenFileMappingW / CreateFileMappingW // need to be replaced with OpenFileMappingW / CreateFileMappingW

View File

@ -286,7 +286,7 @@ corresponding Unix manual entries for more information on calls.");
#endif #endif
#ifdef HAVE_COPY_FILE_RANGE #ifdef HAVE_COPY_FILE_RANGE
# include <unistd.h> # include <unistd.h> // copy_file_range()
#endif #endif
#if !defined(CPU_ALLOC) && defined(HAVE_SCHED_SETAFFINITY) #if !defined(CPU_ALLOC) && defined(HAVE_SCHED_SETAFFINITY)

View File

@ -4,7 +4,8 @@
#include "Python.h" #include "Python.h"
#include "posixmodule.h" #include "posixmodule.h"
#include <pwd.h> #include <pwd.h> // getpwuid()
#include <unistd.h> // sysconf()
#include "clinic/pwdmodule.c.h" #include "clinic/pwdmodule.c.h"
/*[clinic input] /*[clinic input]

View File

@ -1,13 +1,12 @@
#include "Python.h" #include "Python.h"
#include <sys/resource.h> #include <errno.h> // errno
#include <string.h>
#include <sys/resource.h> // getrusage()
#ifdef HAVE_SYS_TIME_H #ifdef HAVE_SYS_TIME_H
#include <sys/time.h> # include <sys/time.h>
#endif #endif
#include <time.h> #include <time.h>
#include <string.h> #include <unistd.h> // getpagesize()
#include <errno.h>
#include <unistd.h>
/* On some systems, these aren't in any header file. /* On some systems, these aren't in any header file.
On others they are, with inconsistent prototypes. On others they are, with inconsistent prototypes.

View File

@ -17,6 +17,9 @@
#include "pycore_time.h" // _PyTime_t #include "pycore_time.h" // _PyTime_t
#include <stddef.h> // offsetof() #include <stddef.h> // offsetof()
#ifndef MS_WINDOWS
# include <unistd.h> // close()
#endif
#ifdef HAVE_SYS_DEVPOLL_H #ifdef HAVE_SYS_DEVPOLL_H
#include <sys/resource.h> #include <sys/resource.h>

View File

@ -269,7 +269,7 @@ shutdown(how) -- shut down traffic in one or both directions\n\
#ifdef HAVE_NETDB_H #ifdef HAVE_NETDB_H
# include <netdb.h> # include <netdb.h>
#endif #endif
# include <unistd.h> #include <unistd.h> // close()
/* Headers needed for inet_ntoa() and inet_addr() */ /* Headers needed for inet_ntoa() and inet_addr() */
# include <arpa/inet.h> # include <arpa/inet.h>

View File

@ -19,7 +19,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#ifndef MS_WINDOWS #ifndef MS_WINDOWS
#include <unistd.h> # include <unistd.h>
#endif #endif
uint32_t _Py_next_func_version = 1; uint32_t _Py_next_func_version = 1;

View File

@ -11,9 +11,9 @@
* Return fd2 if all went well; return BADEXIT otherwise. * Return fd2 if all went well; return BADEXIT otherwise.
*/ */
#include <errno.h> #include <errno.h> // errno
#include <fcntl.h> #include <fcntl.h> // fcntl()
#include <unistd.h> #include <unistd.h> // close()
#define BADEXIT -1 #define BADEXIT -1

View File

@ -140,9 +140,9 @@ any DWARF information available for them).
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/mman.h> #include <sys/mman.h> // mmap()
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h> // sysconf()
#if defined(__arm__) || defined(__arm64__) || defined(__aarch64__) #if defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
#define PY_HAVE_INVALIDATE_ICACHE #define PY_HAVE_INVALIDATE_ICACHE