8000 gh-108765: Python.h no longer includes <sys/time.h> · python/cpython@ccab234 · GitHub
[go: up one dir, main page]

Skip to content

Commit ccab234

Browse files
committed
gh-108765: Python.h no longer includes <sys/time.h>
Python.h no longer includes <time.h>, <sys/select.h> and <sys/time.h> standard header files. * Add <time.h> include to xxsubtype.c. * Add <sys/time.h> includes to posixmodule.c and semaphore.c. * readline.c includes <sys/select.h> instead of <sys/time.h>. * resource.c no longer includes <time.h> and <sys/time.h>.
1 parent 4ba1809 commit ccab234

File tree

11 files changed

+43
-41
lines changed

11 files changed

+43
-41
lines changed

Doc/whatsnew/3.13.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,14 @@ Porting to Python 3.13
921921
also the ``HAVE_IEEEFP_H`` macro.
922922
(Contributed by Victor Stinner in :gh:`108765`.)
923923

924+
* ``Python.h`` no longer includes these standard header files: ``<time.h>``,
925+
``<sys/select.h>`` and ``<sys/time.h>``. If needed, they should now be
926+
included explicitly. For example, ``<time.h>`` defines the ``clock()`` and
927+
``gmtime()`` functions, ``<sys/select.h>`` defines the ``select()`` function,
928+
and ``<sys/time.h>`` defines the ``futimes()``, ``gettimeofday()`` and
929+
``setitimer()`` functions.
930+
(Contributed by Victor Stinner in :gh:`108765`.)
931+
924932
Deprecated
925933
----------
926934

Include/pyport.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -184,25 +184,6 @@ typedef Py_ssize_t Py_ssize_clean_t;
184184
# define Py_MEMCPY memcpy
185185
#endif
186186

187-
/********************************************
188-
* WRAPPER FOR <time.h> and/or <sys/time.h> *
189-
********************************************/
190-
191-
#ifdef HAVE_SYS_TIME_H
192-
#include <sys/time.h>
193-
#endif
194-
#include <time.h>
195-
196-
/******************************
197-
* WRAPPER FOR <sys/select.h> *
198-
******************************/
199-
200-
/* NB caller must include <sys/types.h> */
201-
202-
#ifdef HAVE_SYS_SELECT_H
203-
#include <sys/select.h>
204-
#endif /* !HAVE_SYS_SELECT_H */
205-
206187
/*******************************
207188
* stat() and fstat() fiddling *
208189
*******************************/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``Python.h`` no longer includes these standard header files: ``<time.h>``,
2+
``<sys/select.h>`` and ``<sys/time.h>``. They should now be included
3+
explicitly if needed. Patch by Victor Stinner.

Modules/_multiprocessing/semaphore.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010
#include "multiprocessing.h"
1111

12+
#ifdef HAVE_SYS_TIME_H
13+
# include <sys/time.h> // gettimeofday()
14+
#endif
15+
1216
#ifdef HAVE_MP_SEMAPHORE
1317

1418
enum { RECURSIVE_MUTEX, SEMAPHORE };

Modules/posixmodule.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@
5757

5858
#include <stdio.h> // ctermid()
5959
#include <stdlib.h> // system()
60+
#ifdef HAVE_SYS_TIME_H
61+
# include <sys/time.h> // futimes()
62+
#endif
63+
6064

6165
// SGI apparently needs this forward declaration
6266
#ifdef HAVE__GETPTY

Modules/readline.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,21 @@
1212
#include "Python.h"
1313
#include "pycore_pylifecycle.h" // _Py_SetLocaleFromEnv()
1414

15-
#include <errno.h>
16-
#include <signal.h>
17-
#include <stddef.h>
15+
#include <errno.h> // errno
16+
#include <signal.h> // SIGWINCH
1817
#include <stdlib.h> // free()
19-
#ifdef HAVE_SYS_TIME_H
20-
#include <sys/time.h>
18+
#include <string.h> // strdup()
19+
#ifdef HAVE_SYS_SELECT_H
20+
# include <sys/select.h> // select()
2121
#endif
22-
#include <time.h>
2322

2423
#if defined(HAVE_SETLOCALE)
2524
/* GNU readline() mistakenly sets the LC_CTYPE locale.
2625
* This is evil. Only the user or the app's main() should do this!
2726
* We must save and restore the locale around the rl_initialize() call.
2827
*/
2928
#define SAVE_LOCALE
30-
#include <locale.h>
29+
# include <locale.h> // setlocale()
3130
#endif
3231

3332
#ifdef SAVE_LOCALE
@@ -1333,7 +1332,8 @@ readline_until_enter_or_signal(const char *prompt, int *signal)
13331332
int has_input = 0, err = 0;
13341333

13351334
while (!has_input)
1336-
{ struct timeval timeout = {0, 100000}; /* 0.1 seconds */
1335+
{
1336+
struct timeval timeout = {0, 100000}; // 100 ms (0.1 seconds)
13371337

13381338
/* [Bug #1552726] Only limit the pause if an input hook has been
13391339
defined. */

Modules/resource.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
21
#include "Python.h"
3-
#include <sys/resource.h>
4-
#ifdef HAVE_SYS_TIME_H
5-
#include <sys/time.h>
6-
#endif
7-
#include <time.h>
2+
#include <errno.h> // errno
83
#include <string.h>
9-
#include <errno.h>
10-
#include <unistd.h>
4+
#include <sys/resource.h> // getrusage()
5+
#include <unistd.h> // getpagesize()
116

127
/* On some systems, these aren't in any header file.
138
On others they are, with inconsistent prototypes.

Modules/signalmodule.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
#include "pycore_signal.h" // _Py_RestoreSignals()
1717

1818
#ifndef MS_WINDOWS
19-
# include "posixmodule.h"
19+
# include "posixmodule.h" // _PyLong_FromUid()
2020
#endif
2121
#ifdef MS_WINDOWS
22-
# include "socketmodule.h" /* needed for SOCKET_T */
22+
# include "socketmodule.h" // SOCKET_T
2323
#endif
2424

2525
#ifdef MS_WINDOWS
@@ -29,16 +29,16 @@
2929
#endif
3030

3131
#ifdef HAVE_SIGNAL_H
32-
# include <signal.h>
32+
# include <signal.h> // sigaction()
3333
#endif
3434
#ifdef HAVE_SYS_SYSCALL_H
35-
# include <sys/syscall.h>
35+
# include <sys/syscall.h> // __NR_pidfd_send_signal
3636
#endif
3737
#ifdef HAVE_SYS_STAT_H
3838
# include <sys/stat.h>
3939
#endif
4040
#ifdef HAVE_SYS_TIME_H
41-
# include <sys/time.h>
41+
# include <sys/time.h> // setitimer()
4242
#endif
4343

4444
#if defined(HAVE_PTHREAD_SIGMASK) && !defined(HAVE_BROKEN_PTHREAD_SIGMASK)

Modules/timemodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "pycore_runtime.h" // _Py_ID()
88

99
#include <ctype.h>
10-
10+
#include <time.h> // clock()
1111
#ifdef HAVE_SYS_TIMES_H
1212
# include <sys/times.h>
1313
#endif

Modules/xxsubtype.c

D2BA Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "Python.h"
2+
23
#include <stddef.h> // offsetof()
4+
#include <time.h> // clock()
35

46

57
PyDoc_STRVAR(xxsubtype__doc__,

Python/pytime.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#include "Python.h"
22
#include "pycore_time.h" // _PyTime_t
3+
4+
#include <time.h> // gmtime_r()
5+
#ifdef HAVE_SYS_TIME_H
6+
# include <sys/time.h> // gettimeofday()
7+
#endif
38
#ifdef MS_WINDOWS
49
# include <winsock2.h> // struct timeval
510
#endif

0 commit comments

Comments
 (0)
0