From 12a842c778526eebb054357bd94215593685effd Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 1 Sep 2023 21:14:30 +0200 Subject: [PATCH 1/6] gh-108765: Python.h no longer includes --- Include/pyport.h | 19 ------------------- Modules/_multiprocessing/semaphore.c | 4 ++++ Modules/posixmodule.c | 4 ++++ Modules/timemodule.c | 2 +- Modules/xxsubtype.c | 2 ++ Python/pytime.c | 5 +++++ 6 files changed, 16 insertions(+), 20 deletions(-) diff --git a/Include/pyport.h b/Include/pyport.h index 511c3fda1a40a5..f47a79542e0d98 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -190,25 +190,6 @@ typedef Py_ssize_t Py_ssize_clean_t; #include /* Moved here from the math section, before extern "C" */ -/******************************************** - * WRAPPER FOR and/or * - ********************************************/ - -#ifdef HAVE_SYS_TIME_H -#include -#endif -#include - -/****************************** - * WRAPPER FOR * - ******************************/ - -/* NB caller must include */ - -#ifdef HAVE_SYS_SELECT_H -#include -#endif /* !HAVE_SYS_SELECT_H */ - /******************************* * stat() and fstat() fiddling * *******************************/ diff --git a/Modules/_multiprocessing/semaphore.c b/Modules/_multiprocessing/semaphore.c index d22b8d18e33e42..f8f2afda28d06d 100644 --- a/Modules/_multiprocessing/semaphore.c +++ b/Modules/_multiprocessing/semaphore.c @@ -9,6 +9,10 @@ #include "multiprocessing.h" +#ifdef HAVE_SYS_TIME_H +# include // gettimeofday() +#endif + #ifdef HAVE_MP_SEMAPHORE enum { RECURSIVE_MUTEX, SEMAPHORE }; diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 0436571abc9054..62c99e3bfe24ef 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -57,6 +57,10 @@ #include // ctermid() #include // system() +#ifdef HAVE_SYS_TIME_H +# include // futimes() +#endif + /* * A number of APIs are available on macOS from a certain macOS version. diff --git a/Modules/timemodule.c b/Modules/timemodule.c index 68948b6be1a61a..4e55da71b117ca 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -7,7 +7,7 @@ #include "pycore_runtime.h" // _Py_ID() #include - +#include // clock() #ifdef HAVE_SYS_TIMES_H # include #endif diff --git a/Modules/xxsubtype.c b/Modules/xxsubtype.c index 63b22268c597b6..560f43e5b3a643 100644 --- a/Modules/xxsubtype.c +++ b/Modules/xxsubtype.c @@ -1,5 +1,7 @@ #include "Python.h" + #include // offsetof() +#include // clock() PyDoc_STRVAR(xxsubtype__doc__, diff --git a/Python/pytime.c b/Python/pytime.c index 49cd5f4e8ea617..77f7e9ecbd840e 100644 --- a/Python/pytime.c +++ b/Python/pytime.c @@ -1,5 +1,10 @@ #include "Python.h" #include "pycore_time.h" // _PyTime_t + +#include // gmtime_r() on Windows +#ifdef HAVE_SYS_TIME_H +# include // gettimeofday() +#endif #ifdef MS_WINDOWS # include // struct timeval #endif From 7f04dda4fdd30d9d0abc0e66a587e27f36cd2fc4 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 1 Sep 2023 21:15:26 +0200 Subject: [PATCH 2/6] gh-108765: Python.h no longer includes --- Include/Python.h | 1 + Include/pyport.h | 6 ------ 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/Include/Python.h b/Include/Python.h index 44f0fd3ee4b56b..002a79dbdc9362 100644 --- a/Include/Python.h +++ b/Include/Python.h @@ -20,6 +20,7 @@ #include // tolower() #include // uintptr_t #include // INT_MAX +#include // HUGE_VAL #include // va_list #include // wchar_t #ifdef HAVE_STDDEF_H diff --git a/Include/pyport.h b/Include/pyport.h index f47a79542e0d98..726b5c525f0e8b 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -184,12 +184,6 @@ typedef Py_ssize_t Py_ssize_clean_t; # define Py_MEMCPY memcpy #endif -#ifdef HAVE_IEEEFP_H -#include /* needed for 'finite' declaration on some platforms */ -#endif - -#include /* Moved here from the math section, before extern "C" */ - /******************************* * stat() and fstat() fiddling * *******************************/ From 1b43dc166d496cb4937a2f749db7c7ee9956c2a9 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 1 Sep 2023 21:16:18 +0200 Subject: [PATCH 3/6] gh-108765: Remove old prototypes from pyport.h --- Include/pyport.h | 26 -------------------------- Modules/posixmodule.c | 6 ++++++ Modules/socketmodule.c | 6 +++++- Modules/termios.c | 13 ++++++++++--- 4 files changed, 21 insertions(+), 30 deletions(-) diff --git a/Include/pyport.h b/Include/pyport.h index 726b5c525f0e8b..c4168d10f58151 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -392,32 +392,6 @@ extern "C" { # define Py_NO_INLINE #endif -/************************************************************************** -Prototypes that are missing from the standard include files on some systems -(and possibly only some versions of such systems.) - -Please be conservative with adding new ones, document them and enclose them -in platform-specific #ifdefs. -**************************************************************************/ - -#ifdef SOLARIS -/* Unchecked */ -extern int gethostname(char *, int); -#endif - -#ifdef HAVE__GETPTY -#include /* we need to import mode_t */ -extern char * _getpty(int *, int, mode_t, int); -#endif - -/* On QNX 6, struct termio must be declared by including sys/termio.h - if TCGETA, TCSETA, TCSETAW, or TCSETAF are used. sys/termio.h must - be included before termios.h or it will generate an error. */ -#if defined(HAVE_SYS_TERMIO_H) && !defined(__hpux) -#include -#endif - - /* On 4.4BSD-descendants, ctype functions serves the whole range of * wchar_t character set rather than single byte code points only. * This characteristic can break some operations of string object diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 62c99e3bfe24ef..9feb8855475a68 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -61,6 +61,12 @@ # include // futimes() #endif +// SGI apparently needs this forward declaration +#ifdef HAVE__GETPTY +# include // mode_t + extern char * _getpty(int *, int, mode_t, int); +#endif + /* * A number of APIs are available on macOS from a certain macOS version. diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index e3681853dad095..2f12c9cedbd8a6 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -111,9 +111,13 @@ Local naming conventions: #include "pycore_fileutils.h" // _Py_set_inheritable() #include "pycore_moduleobject.h" // _PyModule_GetState +// gethostname() prototype missing from Solaris standard header files +#ifdef __sun +extern int gethostname(char *, int); +#endif #ifdef _Py_MEMORY_SANITIZER -# include +# include #endif /* Socket object documentation */ diff --git a/Modules/termios.c b/Modules/termios.c index 21d3541c177bc3..a0613837ef9795 100644 --- a/Modules/termios.c +++ b/Modules/termios.c @@ -6,10 +6,17 @@ #include "Python.h" -/* Apparently, on SGI, termios.h won't define CTRL if _XOPEN_SOURCE - is defined, so we define it here. */ +// On QNX 6, struct termio must be declared by including sys/termio.h +// if TCGETA, TCSETA, TCSETAW, or TCSETAF are used. sys/termio.h must +// be included before termios.h or it will generate an error. +#if defined(HAVE_SYS_TERMIO_H) && !defined(__hpux) +# include +#endif + +// Apparently, on SGI, termios.h won't define CTRL if _XOPEN_SOURCE +// is defined, so we define it here. #if defined(__sgi) -#define CTRL(c) ((c)&037) +# define CTRL(c) ((c)&037) #endif #if defined(__sun) From 6aede6048016429fe9c477a3275c0232860d0c53 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 1 Sep 2023 21:16:43 +0200 Subject: [PATCH 4/6] gh-108765: Python.h no longer includes --- Include/Python.h | 11 +++++------ Modules/grpmodule.c | 3 ++- Modules/mmapmodule.c | 1 + Modules/pwdmodule.c | 4 +++- Modules/selectmodule.c | 1 + 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Include/Python.h b/Include/Python.h index 002a79dbdc9362..4cc72bb23ce7a3 100644 --- a/Include/Python.h +++ b/Include/Python.h @@ -26,14 +26,13 @@ #ifdef HAVE_STDDEF_H # include // size_t #endif -#ifndef MS_WINDOWS -# include // sysconf() +#ifdef HAVE_SYS_TYPES_H +# include // 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 # include // FILE* diff --git a/Modules/grpmodule.c b/Modules/grpmodule.c index f5709296334a8f..20e83de84e8340 100644 --- a/Modules/grpmodule.c +++ b/Modules/grpmodule.c @@ -4,7 +4,8 @@ #include "Python.h" #include "posixmodule.h" -#include +#include // getgrgid_r() +#include // sysconf() #include "clinic/grpmodule.c.h" /*[clinic input] diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index c8cd7e59dbab50..3e5c80a492f420 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -28,6 +28,7 @@ #include "pycore_fileutils.h" // _Py_stat_struct #include // offsetof() +#include // close() // to support MS_WINDOWS_SYSTEM OpenFileMappingA / CreateFileMappingA // need to be replaced with OpenFileMappingW / CreateFileMappingW diff --git a/Modules/pwdmodule.c b/Modules/pwdmodule.c index cc2e2a43893971..f662cf63856c77 100644 --- a/Modules/pwdmodule.c +++ b/Modules/pwdmodule.c @@ -4,7 +4,9 @@ #include "Python.h" #include "posixmodule.h" -#include +#include // getpwuid() +#include // sysconf() + #include "clinic/pwdmodule.c.h" /*[clinic input] diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c index 4987cf0f2065c2..367d31f265750e 100644 --- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -17,6 +17,7 @@ #include "pycore_time.h" // _PyTime_t #include // offsetof() +#include // close() #ifdef HAVE_SYS_DEVPOLL_H #include From 0a43cccc3f7b1d52b25645264dc1fbecb450d812 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sat, 2 Sep 2023 01:12:51 +0200 Subject: [PATCH 5/6] Fix mmapmodule.c Cleanup also other includes. --- Modules/_ctypes/malloc_closure.c | 13 +++++++------ Modules/_posixsubprocess.c | 4 ++-- Modules/_testcapimodule.c | 3 --- Modules/mmapmodule.c | 4 +++- Modules/posixmodule.c | 2 +- Modules/pwdmodule.c | 1 - Modules/resource.c | 9 ++++----- Modules/socketmodule.c | 2 +- Programs/_freeze_module.c | 2 +- Python/dup2.c | 6 +++--- 10 files changed, 22 insertions(+), 24 deletions(-) diff --git a/Modules/_ctypes/malloc_closure.c b/Modules/_ctypes/malloc_closure.c index 3a859322772ba7..8dc0de1c7fcfad 100644 --- a/Modules/_ctypes/malloc_closure.c +++ b/Modules/_ctypes/malloc_closure.c @@ -1,16 +1,17 @@ #ifndef Py_BUILD_CORE_BUILTIN # define Py_BUILD_CORE_MODULE 1 #endif + #include #include #ifdef MS_WIN32 -#include +# include #else -#include -#include -# if !defined(MAP_ANONYMOUS) && defined(MAP_ANON) -# define MAP_ANONYMOUS MAP_ANON -# endif +# include +# include +# if !defined(MAP_ANONYMOUS) && defined(MAP_ANON) +# define MAP_ANONYMOUS MAP_ANON +# endif #endif #include "ctypes.h" diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c index ac2b0d4f55468c..aefa99682c5478 100644 --- a/Modules/_posixsubprocess.c +++ b/Modules/_posixsubprocess.c @@ -8,9 +8,9 @@ #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 +#include // close() #include #ifdef HAVE_SYS_TYPES_H #include diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 4fc354ae79bfed..ab33702cdfd872 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -24,9 +24,6 @@ #include // FLT_MAX #include #include // offsetof() -#ifndef MS_WINDOWS -# include -#endif #ifdef HAVE_SYS_WAIT_H # include // W_STOPCODE diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index 3e5c80a492f420..d11200a4042551 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -28,7 +28,9 @@ #include "pycore_fileutils.h" // _Py_stat_struct #include // offsetof() -#include // close() +#ifndef MS_WINDOWS +# include // close() +#endif // to support MS_WINDOWS_SYSTEM OpenFileMappingA / CreateFileMappingA // need to be replaced with OpenFileMappingW / CreateFileMappingW diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 9feb8855475a68..e60898b52f4144 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -289,7 +289,7 @@ corresponding Unix manual entries for more information on calls."); #endif #ifdef HAVE_COPY_FILE_RANGE -# include +# include // copy_file_range() #endif #if !defined(CPU_ALLOC) && defined(HAVE_SCHED_SETAFFINITY) diff --git a/Modules/pwdmodule.c b/Modules/pwdmodule.c index f662cf63856c77..b7034369c4731e 100644 --- a/Modules/pwdmodule.c +++ b/Modules/pwdmodule.c @@ -7,7 +7,6 @@ #include // getpwuid() #include // sysconf() - #include "clinic/pwdmodule.c.h" /*[clinic input] module pwd diff --git a/Modules/resource.c b/Modules/resource.c index 4614f5e98cc888..720d494a3e5723 100644 --- a/Modules/resource.c +++ b/Modules/resource.c @@ -1,12 +1,11 @@ - #include "Python.h" -#include +#include // errno +#include +#include // getrusage() #ifdef HAVE_SYS_TIME_H -#include +# include #endif #include -#include -#include #include /* On some systems, these aren't in any header file. diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 2f12c9cedbd8a6..74b1c1c661604f 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -269,7 +269,7 @@ shutdown(how) -- shut down traffic in one or both directions\n\ #ifdef HAVE_NETDB_H # include #endif -# include +#include // close() /* Headers needed for inet_ntoa() and inet_addr() */ # include diff --git a/Programs/_freeze_module.c b/Programs/_freeze_module.c index e55f1d56745c4d..f6c46fa629efba 100644 --- a/Programs/_freeze_module.c +++ b/Programs/_freeze_module.c @@ -19,7 +19,7 @@ #include #include #ifndef MS_WINDOWS -#include +# include #endif uint32_t _Py_next_func_version = 1; diff --git a/Python/dup2.c b/Python/dup2.c index a1df0492099163..936211f27ec737 100644 --- a/Python/dup2.c +++ b/Python/dup2.c @@ -11,9 +11,9 @@ * Return fd2 if all went well; return BADEXIT otherwise. */ -#include -#include -#include +#include // errno +#include // fcntl() +#include // close() #define BADEXIT -1 From 7531a551fec2a159fd638e2b208c6544c2a77002 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sat, 2 Sep 2023 03:54:55 +0200 Subject: [PATCH 6/6] Fix select module --- Modules/selectmodule.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c index 367d31f265750e..c56e682b21e2a1 100644 --- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -17,7 +17,9 @@ #include "pycore_time.h" // _PyTime_t #include // offsetof() -#include // close() +#ifndef MS_WINDOWS +# include // close() +#endif #ifdef HAVE_SYS_DEVPOLL_H #include