Skip to content

gh-108765: [TEST] Test combined Python.h changes #108784

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Include/Python.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
#include <ctype.h> // tolower()
#include <inttypes.h> // uintptr_t
#include <limits.h> // INT_MAX
#include <math.h> // HUGE_VAL
#include <stdarg.h> // va_list
#include <wchar.h> // wchar_t
#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*
Expand Down
51 changes: 0 additions & 51 deletions Include/pyport.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,31 +184,6 @@ typedef Py_ssize_t Py_ssize_clean_t;
# define Py_MEMCPY memcpy
#endif

#ifdef HAVE_IEEEFP_H
#include <ieeefp.h> /* needed for 'finite' declaration on some platforms */
#endif

#include <math.h> /* Moved here from the math section, before extern "C" */

/********************************************
* WRAPPER FOR <time.h> and/or <sys/time.h> *
********************************************/

#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#include <time.h>

/******************************
* WRAPPER FOR <sys/select.h> *
******************************/

/* NB caller must include <sys/types.h> */

#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif /* !HAVE_SYS_SELECT_H */

/*******************************
* stat() and fstat() fiddling *
*******************************/
Expand Down Expand Up @@ -417,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 <sys/types.h> /* 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 <sys/termio.h>
#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
Expand Down
13 changes: 7 additions & 6 deletions Modules/_ctypes/malloc_closure.c
Original file line number Diff line number Diff line change
@@ -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>
# if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
# define MAP_ANONYMOUS MAP_ANON
# endif
#endif
#include "ctypes.h"

Expand Down
4 changes: 4 additions & 0 deletions Modules/_multiprocessing/semaphore.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

#include "multiprocessing.h"

#ifdef HAVE_SYS_TIME_H
# include <sys/time.h> // gettimeofday()
#endif

#ifdef HAVE_MP_SEMAPHORE

enum { RECURSIVE_MUTEX, SEMAPHORE };
Expand Down
4 changes: 2 additions & 2 deletions Modules/_posixsubprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <unistd.h>
#include <unistd.h> // close()
#include <fcntl.h>
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
Expand Down
3 changes: 0 additions & 3 deletions Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Modules/grpmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 3 additions & 0 deletions Modules/mmapmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@

#include <stdio.h> // ctermid()
#include <stdlib.h> // system()
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h> // futimes()
#endif

// SGI apparently needs this forward declaration
#ifdef HAVE__GETPTY
# include <sys/types.h> // mode_t
extern char * _getpty(int *, int, mode_t, int);
#endif


/*
* A number of APIs are available on macOS from a certain macOS version.
Expand Down Expand Up @@ -279,7 +289,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)
Expand Down
3 changes: 2 additions & 1 deletion Modules/pwdmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
9 changes: 4 additions & 5 deletions Modules/resource.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

#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>

/* On some systems, these aren't in any header file.
Expand Down
3 changes: 3 additions & 0 deletions Modules/selectmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
8 changes: 6 additions & 2 deletions Modules/socketmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <sanitizer/msan_interface.h>
# include <sanitizer/msan_interface.h>
#endif

/* Socket object documentation */
Expand Down Expand Up @@ -265,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>
Expand Down
13 changes: 10 additions & 3 deletions Modules/termios.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <sys/termio.h>
#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)
Expand Down
2 changes: 1 addition & 1 deletion Modules/timemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "pycore_runtime.h" // _Py_ID()

#include <ctype.h>

#include <time.h> // clock()
#ifdef HAVE_SYS_TIMES_H
# include <sys/times.h>
#endif
Expand Down
2 changes: 2 additions & 0 deletions Modules/xxsubtype.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "Python.h"

#include <stddef.h> // offsetof()
#include <time.h> // clock()


PyDoc_STRVAR(xxsubtype__doc__,
Expand Down
2 changes: 1 addition & 1 deletion Programs/_freeze_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions Python/dup2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions Python/pytime.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#include "Python.h"
#include "pycore_time.h" // _PyTime_t

#include <time.h> // gmtime_r() on Windows
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h> // gettimeofday()
#endif
#ifdef MS_WINDOWS
# include <winsock2.h> // struct timeval
#endif
Expand Down