gh-108765: Move standard includes to Python.h (#108769)

* Move <ctype.h>, <limits.h> and <stdarg.h> standard includes to
  Python.h.
* Move "pystats.h" include from object.h to Python.h.
* Remove redundant "pymem.h" include in objimpl.h and "pyport.h"
  include in pymem.h; Python.h already includes them earlier.
* Remove redundant <wchar.h> include in unicodeobject.h; Python.h
  already includes it.
* Move _SGI_MP_SOURCE define from Python.h to pyport.h.
* pycore_condvar.h includes explicitly <unistd.h> for the
  _POSIX_THREADS macro.
This commit is contained in:
Victor Stinner 2023-09-01 21:03:20 +02:00 committed by GitHub
parent 0e01fac315
commit 45b9e6a61f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 45 additions and 61 deletions

View File

@ -5,42 +5,50 @@
#ifndef Py_PYTHON_H #ifndef Py_PYTHON_H
#define Py_PYTHON_H #define Py_PYTHON_H
// Since this is a "meta-include" file, no #ifdef __cplusplus / extern "C" { // Since this is a "meta-include" file, "#ifdef __cplusplus / extern "C" {"
// is not needed.
// Include Python header files // Include Python header files
#include "patchlevel.h" #include "patchlevel.h"
#include "pyconfig.h" #include "pyconfig.h"
#include "pymacconfig.h" #include "pymacconfig.h"
#if defined(__sgi) && !defined(_SGI_MP_SOURCE)
# define _SGI_MP_SOURCE
#endif
// stdlib.h, stdio.h, errno.h and string.h headers are not used by Python // Include standard header files
// headers, but kept for backward compatibility. They are excluded from the #include <assert.h> // assert()
// limited C API of Python 3.11. #include <ctype.h> // tolower()
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000 #include <inttypes.h> // uintptr_t
# include <stdlib.h> #include <limits.h> // INT_MAX
# include <stdio.h> // FILE* #include <stdarg.h> // va_list
# include <errno.h> // errno #include <wchar.h> // wchar_t
# include <string.h> // memcpy()
#endif
#ifndef MS_WINDOWS
# include <unistd.h>
#endif
#ifdef HAVE_STDDEF_H #ifdef HAVE_STDDEF_H
# include <stddef.h> // size_t # include <stddef.h> // size_t
#endif #endif
#ifndef MS_WINDOWS
# include <unistd.h> // sysconf()
#endif
#include <assert.h> // assert() // errno.h, stdio.h, stdlib.h and string.h headers are no longer used by Python
#include <wchar.h> // wchar_t // 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.
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
# include <errno.h> // errno
# include <stdio.h> // FILE*
# include <stdlib.h> // getenv()
# include <string.h> // memcpy()
#endif
// Include Python header files
#include "pyport.h" #include "pyport.h"
#include "pymacro.h" #include "pymacro.h"
#include "pymath.h" #include "pymath.h"
#include "pymem.h" #include "pymem.h"
#include "pytypedefs.h" #include "pytypedefs.h"
#include "pybuffer.h" #include "pybuffer.h"
#include "pystats.h"
#include "object.h" #include "object.h"
#include "objimpl.h" #include "objimpl.h"
#include "typeslots.h" #include "typeslots.h"

View File

@ -1,5 +1,4 @@
// Bytes object interface
/* Bytes object interface */
#ifndef Py_BYTESOBJECT_H #ifndef Py_BYTESOBJECT_H
#define Py_BYTESOBJECT_H #define Py_BYTESOBJECT_H
@ -7,8 +6,6 @@
extern "C" { extern "C" {
#endif #endif
#include <stdarg.h> // va_list
/* /*
Type PyBytesObject represents a byte string. An extra zero byte is Type PyBytesObject represents a byte string. An extra zero byte is
reserved at the end to ensure it is zero-terminated, but a size is reserved at the end to ensure it is zero-terminated, but a size is

View File

@ -5,6 +5,10 @@
# error "this header requires Py_BUILD_CORE define" # error "this header requires Py_BUILD_CORE define"
#endif #endif
#ifndef MS_WINDOWS
# include <unistd.h> // _POSIX_THREADS
#endif
#ifndef _POSIX_THREADS #ifndef _POSIX_THREADS
/* This means pthreads are not implemented in libc headers, hence the macro /* This means pthreads are not implemented in libc headers, hence the macro
not present in unistd.h. But they still can be implemented as an external not present in unistd.h. But they still can be implemented as an external

View File

@ -1,3 +1,4 @@
// Module support interface
#ifndef Py_MODSUPPORT_H #ifndef Py_MODSUPPORT_H
#define Py_MODSUPPORT_H #define Py_MODSUPPORT_H
@ -5,10 +6,6 @@
extern "C" { extern "C" {
#endif #endif
/* Module support interface */
#include <stdarg.h> // va_list
PyAPI_FUNC(int) PyArg_Parse(PyObject *, const char *, ...); PyAPI_FUNC(int) PyArg_Parse(PyObject *, const char *, ...);
PyAPI_FUNC(int) PyArg_ParseTuple(PyObject *, const char *, ...); PyAPI_FUNC(int) PyArg_ParseTuple(PyObject *, const char *, ...);
PyAPI_FUNC(int) PyArg_ParseTupleAndKeywords(PyObject *, PyObject *, PyAPI_FUNC(int) PyArg_ParseTupleAndKeywords(PyObject *, PyObject *,

View File

@ -51,8 +51,6 @@ A standard interface exists for objects that contain an array of items
whose size is determined when the object is allocated. whose size is determined when the object is allocated.
*/ */
#include "pystats.h"
/* Py_DEBUG implies Py_REF_DEBUG. */ /* Py_DEBUG implies Py_REF_DEBUG. */
#if defined(Py_DEBUG) && !defined(Py_REF_DEBUG) #if defined(Py_DEBUG) && !defined(Py_REF_DEBUG)
# define Py_REF_DEBUG # define Py_REF_DEBUG

View File

@ -1,12 +1,8 @@
/* The PyObject_ memory family: high-level object memory interfaces. // The PyObject_ memory family: high-level object memory interfaces.
See pymem.h for the low-level PyMem_ family. // See pymem.h for the low-level PyMem_ family.
*/
#ifndef Py_OBJIMPL_H #ifndef Py_OBJIMPL_H
#define Py_OBJIMPL_H #define Py_OBJIMPL_H
#include "pymem.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -231,4 +227,4 @@ PyAPI_FUNC(int) PyObject_GC_IsFinalized(PyObject *);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* !Py_OBJIMPL_H */ #endif // !Py_OBJIMPL_H

View File

@ -1,13 +1,11 @@
// Error handling definitions
#ifndef Py_ERRORS_H #ifndef Py_ERRORS_H
#define Py_ERRORS_H #define Py_ERRORS_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include <stdarg.h> // va_list
/* Error handling definitions */
PyAPI_FUNC(void) PyErr_SetNone(PyObject *); PyAPI_FUNC(void) PyErr_SetNone(PyObject *);
PyAPI_FUNC(void) PyErr_SetObject(PyObject *, PyObject *); PyAPI_FUNC(void) PyErr_SetObject(PyObject *, PyObject *);
PyAPI_FUNC(void) PyErr_SetString( PyAPI_FUNC(void) PyErr_SetString(

View File

@ -1,12 +1,8 @@
/* The PyMem_ family: low-level memory allocation interfaces. // The PyMem_ family: low-level memory allocation interfaces.
See objimpl.h for the PyObject_ memory family. // See objimpl.h for the PyObject_ memory family.
*/
#ifndef Py_PYMEM_H #ifndef Py_PYMEM_H
#define Py_PYMEM_H #define Py_PYMEM_H
#include "pyport.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -100,5 +96,4 @@ PyAPI_FUNC(void) PyMem_Free(void *ptr);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif // !Py_PYMEM_H
#endif /* !Py_PYMEM_H */

View File

@ -1,13 +1,8 @@
#ifndef Py_PYPORT_H #ifndef Py_PYPORT_H
#define Py_PYPORT_H #define Py_PYPORT_H
#include "pyconfig.h" /* include for defines */
#include <inttypes.h>
#include <limits.h>
#ifndef UCHAR_MAX #ifndef UCHAR_MAX
# error "limits.h must define UCHAR_MAX" # error "<limits.h> header must define UCHAR_MAX"
#endif #endif
#if UCHAR_MAX != 255 #if UCHAR_MAX != 255
# error "Python's source code assumes C's unsigned char is an 8-bit type" # error "Python's source code assumes C's unsigned char is an 8-bit type"
@ -771,4 +766,8 @@ extern char * _getpty(int *, int, mode_t, int);
# define ALIGNOF_MAX_ALIGN_T _Alignof(long double) # define ALIGNOF_MAX_ALIGN_T _Alignof(long double)
#endif #endif
#if defined(__sgi) && !defined(_SGI_MP_SOURCE)
# define _SGI_MP_SOURCE
#endif
#endif /* Py_PYPORT_H */ #endif /* Py_PYPORT_H */

View File

@ -1,8 +1,6 @@
#ifndef Py_UNICODEOBJECT_H #ifndef Py_UNICODEOBJECT_H
#define Py_UNICODEOBJECT_H #define Py_UNICODEOBJECT_H
#include <stdarg.h> // va_list
/* /*
Unicode implementation based on original code by Fredrik Lundh, Unicode implementation based on original code by Fredrik Lundh,
@ -55,8 +53,6 @@ Copyright (c) Corporation for National Research Initiatives.
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
* -------------------------------------------------------------------- */ * -------------------------------------------------------------------- */
#include <ctype.h>
/* === Internal API ======================================================= */ /* === Internal API ======================================================= */
/* --- Internal Unicode Format -------------------------------------------- */ /* --- Internal Unicode Format -------------------------------------------- */
@ -93,10 +89,6 @@ Copyright (c) Corporation for National Research Initiatives.
# endif # endif
#endif #endif
#ifdef HAVE_WCHAR_H
# include <wchar.h>
#endif
/* Py_UCS4 and Py_UCS2 are typedefs for the respective /* Py_UCS4 and Py_UCS2 are typedefs for the respective
unicode representations. */ unicode representations. */
typedef uint32_t Py_UCS4; typedef uint32_t Py_UCS4;