From e7de0c5901b85a5241386a33f98c27a4e08d5384 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sat, 2 Sep 2023 17:51:19 +0200 Subject: gh-108765: Python.h no longer includes (#108775) Python.h no longer includes , and standard header files. * Add include to xxsubtype.c. * Add include to posixmodule.c and semaphore.c. * readline.c includes instead of . * resource.c no longer includes and . --- Doc/whatsnew/3.13.rst | 8 ++++++++ Include/pyport.h | 19 ------------------- .../2023-09-01-18-42-31.gh-issue-108765.IyYNDu.rst | 6 ++++++ Modules/_multiprocessing/semaphore.c | 4 ++++ Modules/posixmodule.c | 4 ++++ Modules/readline.c | 16 ++++++++-------- Modules/resource.c | 4 ---- Modules/signalmodule.c | 10 +++++----- Modules/timemodule.c | 2 +- Modules/xxsubtype.c | 2 ++ Python/pytime.c | 5 +++++ 11 files changed, 43 insertions(+), 37 deletions(-) create mode 100644 Misc/NEWS.d/next/C API/2023-09-01-18-42-31.gh-issue-108765.IyYNDu.rst diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index 401de11..1c91a1d 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -934,6 +934,14 @@ Porting to Python 3.13 functions: ``close()``, ``getpagesize()``, ``getpid()`` and ``sysconf()``. (Contributed by Victor Stinner in :gh:`108765`.) +* ``Python.h`` no longer includes these standard header files: ````, + ```` and ````. If needed, they should now be + included explicitly. For example, ```` provides the ``clock()`` and + ``gmtime()`` functions, ```` provides the ``select()`` + function, and ```` provides the ``futimes()``, ``gettimeofday()`` + and ``setitimer()`` functions. + (Contributed by Victor Stinner in :gh:`108765`.) + Deprecated ---------- diff --git a/Include/pyport.h b/Include/pyport.h index f2046de..c4168d1 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -184,25 +184,6 @@ typedef Py_ssize_t Py_ssize_clean_t; # define Py_MEMCPY memcpy #endif -/******************************************** - * 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/Misc/NEWS.d/next/C API/2023-09-01-18-42-31.gh-issue-108765.IyYNDu.rst b/Misc/NEWS.d/next/C API/2023-09-01-18-42-31.gh-issue-108765.IyYNDu.rst new file mode 100644 index 0000000..7b33481 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2023-09-01-18-42-31.gh-issue-108765.IyYNDu.rst @@ -0,0 +1,6 @@ +``Python.h`` no longer includes these standard header files: ````, +```` and ````. If needed, they should now be included +explicitly. For example, ```` provides the ``clock()`` and ``gmtime()`` +functions, ```` provides the ``select()`` function, and +```` provides the ``futimes()``, ``gettimeofday()`` and +``setitimer()`` functions. Patch by Victor Stinner. diff --git a/Modules/_multiprocessing/semaphore.c b/Modules/_multiprocessing/semaphore.c index d22b8d1..f8f2afd 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 6e829b2..b4c502b 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 + // SGI apparently needs this forward declaration #ifdef HAVE__GETPTY diff --git a/Modules/readline.c b/Modules/readline.c index 2531b23..aeae654 100644 --- a/Modules/readline.c +++ b/Modules/readline.c @@ -12,14 +12,13 @@ #include "Python.h" #include "pycore_pylifecycle.h" // _Py_SetLocaleFromEnv() -#include -#include -#include +#include // errno +#include // SIGWINCH #include // free() -#ifdef HAVE_SYS_TIME_H -#include +#include // strdup() +#ifdef HAVE_SYS_SELECT_H +# include // select() #endif -#include #if defined(HAVE_SETLOCALE) /* GNU readline() mistakenly sets the LC_CTYPE locale. @@ -27,7 +26,7 @@ * We must save and restore the locale around the rl_initialize() call. */ #define SAVE_LOCALE -#include +# include // setlocale() #endif #ifdef SAVE_LOCALE @@ -1333,7 +1332,8 @@ readline_until_enter_or_signal(const char *prompt, int *signal) int has_input = 0, err = 0; while (!has_input) - { struct timeval timeout = {0, 100000}; /* 0.1 seconds */ + { + struct timeval timeout = {0, 100000}; // 100 ms (0.1 seconds) /* [Bug #1552726] Only limit the pause if an input hook has been defined. */ diff --git a/Modules/resource.c b/Modules/resource.c index f5d9972..9e302a3 100644 --- a/Modules/resource.c +++ b/Modules/resource.c @@ -2,10 +2,6 @@ #include // errno #include #include // getrusage() -#ifdef HAVE_SYS_TIME_H -# include -#endif -#include #include // getpagesize() /* On some systems, these aren't in any header file. diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c index 3adb2e8..8d65567 100644 --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -16,10 +16,10 @@ #include "pycore_signal.h" // _Py_RestoreSignals() #ifndef MS_WINDOWS -# include "posixmodule.h" +# include "posixmodule.h" // _PyLong_FromUid() #endif #ifdef MS_WINDOWS -# include "socketmodule.h" /* needed for SOCKET_T */ +# include "socketmodule.h" // SOCKET_T #endif #ifdef MS_WINDOWS @@ -29,16 +29,16 @@ #endif #ifdef HAVE_SIGNAL_H -# include +# include // sigaction() #endif #ifdef HAVE_SYS_SYSCALL_H -# include +# include // __NR_pidfd_send_signal #endif #ifdef HAVE_SYS_STAT_H # include #endif #ifdef HAVE_SYS_TIME_H -# include +# include // setitimer() #endif #if defined(HAVE_PTHREAD_SIGMASK) && !defined(HAVE_BROKEN_PTHREAD_SIGMASK) diff --git a/Modules/timemodule.c b/Modules/timemodule.c index 68948b6..4e55da7 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 63b2226..560f43e 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 49cd5f4..d1e29e5 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() +#ifdef HAVE_SYS_TIME_H +# include // gettimeofday() +#endif #ifdef MS_WINDOWS # include // struct timeval #endif -- cgit v0.12