gh-131238: Add explicit includes to pycore headers (#131257)

This commit is contained in:
Victor Stinner 2025-03-17 12:32:43 +01:00 committed by GitHub
parent 0453e494b6
commit 978e37bb5f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 80 additions and 45 deletions

View file

@ -9,7 +9,7 @@
#include "Python.h" #include "Python.h"
#include "pycore_abstract.h" // _PyNumber_Index() #include "pycore_abstract.h" // _PyNumber_Index()
#include "pycore_initconfig.h" // _PyStatus_OK() #include "pycore_interp.h" // _PyInterpreterState_GetConfig()
#include "pycore_long.h" // _PyLong_IsNegative() #include "pycore_long.h" // _PyLong_IsNegative()
#include "pycore_pyerrors.h" // _PyErr_ChainExceptions1() #include "pycore_pyerrors.h" // _PyErr_ChainExceptions1()
#include "pycore_pystate.h" // _PyInterpreterState_GET() #include "pycore_pystate.h" // _PyInterpreterState_GET()

View file

@ -1,8 +1,10 @@
#include "Python.h" #include "Python.h"
#include "pycore_modsupport.h" // _PyArg_NoKwnames() #include "pycore_modsupport.h" // _PyArg_NoKwnames()
#include "pycore_moduleobject.h" // _PyModule_GetState() #include "pycore_moduleobject.h" // _PyModule_GetState()
#include "pycore_runtime.h" // _Py_ID()
#include "pycore_pystate.h" // _PyInterpreterState_GET() #include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "pycore_tuple.h" // _PyTuple_ITEMS()
#include "pycore_typeobject.h" // _PyType_GetModuleState()
#include "pycore_unicodeobject.h" // _PyUnicode_InternMortal()
#include "clinic/_operator.c.h" #include "clinic/_operator.c.h"

View file

@ -4,9 +4,10 @@
#endif #endif
#include "Python.h" #include "Python.h"
#include "pycore_fileutils.h" #include "pycore_interp.h" // _PyInterpreterState_GetFinalizing()
#include "pycore_pystate.h" #include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "pycore_signal.h" // _Py_RestoreSignals() #include "pycore_signal.h" // _Py_RestoreSignals()
#if defined(HAVE_PIPE2) && !defined(_GNU_SOURCE) #if defined(HAVE_PIPE2) && !defined(_GNU_SOURCE)
# define _GNU_SOURCE # define _GNU_SOURCE
#endif #endif

View file

@ -6,11 +6,13 @@
#include "pycore_critical_section.h" // _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED() #include "pycore_critical_section.h" // _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED()
#include "pycore_long.h" // _PyLong_GetOne() #include "pycore_long.h" // _PyLong_GetOne()
#include "pycore_pyerrors.h" // _PyErr_ChainExceptions1() #include "pycore_pyerrors.h" // _PyErr_ChainExceptions1()
#include "pycore_typeobject.h" // _PyType_GetModuleState()
#include "datetime.h" // PyDateTime_TZInfo #include "datetime.h" // PyDateTime_TZInfo
#include <stddef.h> // offsetof() #include <stddef.h> // offsetof()
#include <stdint.h> #include <stdint.h> // int64_t
#include "clinic/_zoneinfo.c.h" #include "clinic/_zoneinfo.c.h"
/*[clinic input] /*[clinic input]

View file

@ -1,8 +1,9 @@
#include "Python.h" #include "Python.h"
#include "pycore_ceval.h" // _PyEval_IsGILEnabled #include "pycore_ceval.h" // _PyEval_IsGILEnabled()
#include "pycore_initconfig.h" // _PyStatus_ERR #include "pycore_initconfig.h" // _PyStatus_ERR()
#include "pycore_pyerrors.h" // _Py_DumpExtensionModules #include "pycore_pyerrors.h" // _Py_DumpExtensionModules()
#include "pycore_pystate.h" // _PyThreadState_GET() #include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_runtime.h" // _Py_ID()
#include "pycore_signal.h" // Py_NSIG #include "pycore_signal.h" // Py_NSIG
#include "pycore_sysmodule.h" // _PySys_GetRequiredAttr() #include "pycore_sysmodule.h" // _PySys_GetRequiredAttr()
#include "pycore_time.h" // _PyTime_FromSecondsObject() #include "pycore_time.h" // _PyTime_FromSecondsObject()
@ -28,6 +29,7 @@
# include <sys/auxv.h> // getauxval() # include <sys/auxv.h> // getauxval()
#endif #endif
/* Sentinel to ignore all_threads on free-threading */ /* Sentinel to ignore all_threads on free-threading */
#define FT_IGNORE_ALL_THREADS 2 #define FT_IGNORE_ALL_THREADS 2

View file

@ -3,11 +3,13 @@
#include "Python.h" #include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs() #include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_runtime.h" // _PyRuntime #include "pycore_runtime.h" // _PyRuntime
#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8String()
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
# include <unistd.h> // isatty() # include <unistd.h> // isatty()
#endif #endif
#if defined(HAVE_GETC_UNLOCKED) && !defined(_Py_MEMORY_SANITIZER) #if defined(HAVE_GETC_UNLOCKED) && !defined(_Py_MEMORY_SANITIZER)
/* clang MemorySanitizer doesn't yet understand getc_unlocked. */ /* clang MemorySanitizer doesn't yet understand getc_unlocked. */
# define GETC(f) getc_unlocked(f) # define GETC(f) getc_unlocked(f)

View file

@ -1,9 +1,12 @@
#include <Python.h> #include <Python.h>
#include "pegen.h" #include "pegen.h"
#include "string_parser.h" #include "string_parser.h" // _PyPegen_decode_string()
#include "pycore_runtime.h" // _PyRuntime
#include "pycore_pystate.h" // _PyInterpreterState_GET() #include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "pycore_runtime.h" // _PyRuntime
#include "pycore_unicodeobject.h" // _PyUnicode_InternImmortal()
void * void *
_PyPegen_dummy_name(Parser *p, ...) _PyPegen_dummy_name(Parser *p, ...)

View file

@ -2273,15 +2273,16 @@ def generate_module_def(mod, metadata, f, internal_h):
#include "Python.h" #include "Python.h"
#include "pycore_ast.h" #include "pycore_ast.h"
#include "pycore_ast_state.h" // struct ast_state #include "pycore_ast_state.h" // struct ast_state
#include "pycore_ceval.h" // _Py_EnterRecursiveCall #include "pycore_ceval.h" // _Py_EnterRecursiveCall()
#include "pycore_lock.h" // _PyOnceFlag #include "pycore_lock.h" // _PyOnceFlag
#include "pycore_interp.h" // _PyInterpreterState.ast
#include "pycore_modsupport.h" // _PyArg_NoPositional() #include "pycore_modsupport.h" // _PyArg_NoPositional()
#include "pycore_pystate.h" // _PyInterpreterState_GET() #include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "pycore_setobject.h" // _PySet_NextEntry(), _PySet_Update() #include "pycore_runtime.h" // _Py_ID()
#include "pycore_setobject.h" // _PySet_NextEntry()
#include "pycore_unionobject.h" // _Py_union_type_or #include "pycore_unionobject.h" // _Py_union_type_or
#include "structmember.h"
#include <stddef.h> #include <stddef.h> // offsetof()
// Forward declaration // Forward declaration
static int init_types(void *arg); static int init_types(void *arg);

View file

@ -1,8 +1,9 @@
#include "Python.h" #include "Python.h"
#include "pycore_call.h" #include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_import.h" #include "pycore_fileutils.h" // _Py_UniversalNewlineFgetsWithSize()
#include "pycore_fileutils.h" #include "pycore_runtime.h" // _Py_ID()
#include "errcode.h"
#include "errcode.h" // E_NOMEM
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
# include <unistd.h> // lseek(), read() # include <unistd.h> // lseek(), read()
@ -13,6 +14,7 @@
#include "../lexer/lexer.h" #include "../lexer/lexer.h"
#include "../lexer/buffer.h" #include "../lexer/buffer.h"
static int static int
tok_concatenate_interactive_new_line(struct tok_state *tok, const char *line) { tok_concatenate_interactive_new_line(struct tok_state *tok, const char *line) {
assert(tok->fp_interactive); assert(tok->fp_interactive);

11
Python/Python-ast.c generated
View file

@ -3,15 +3,16 @@
#include "Python.h" #include "Python.h"
#include "pycore_ast.h" #include "pycore_ast.h"
#include "pycore_ast_state.h" // struct ast_state #include "pycore_ast_state.h" // struct ast_state
#include "pycore_ceval.h" // _Py_EnterRecursiveCall #include "pycore_ceval.h" // _Py_EnterRecursiveCall()
#include "pycore_lock.h" // _PyOnceFlag #include "pycore_lock.h" // _PyOnceFlag
#include "pycore_interp.h" // _PyInterpreterState.ast
#include "pycore_modsupport.h" // _PyArg_NoPositional() #include "pycore_modsupport.h" // _PyArg_NoPositional()
#include "pycore_pystate.h" // _PyInterpreterState_GET() #include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "pycore_setobject.h" // _PySet_NextEntry(), _PySet_Update() #include "pycore_runtime.h" // _Py_ID()
#include "pycore_setobject.h" // _PySet_NextEntry()
#include "pycore_unionobject.h" // _Py_union_type_or #include "pycore_unionobject.h" // _Py_union_type_or
#include "structmember.h"
#include <stddef.h> #include <stddef.h> // offsetof()
// Forward declaration // Forward declaration
static int init_types(void *arg); static int init_types(void *arg);

View file

@ -5,9 +5,10 @@
#include "Python.h" #include "Python.h"
#include "pycore_ast.h" // asdl_stmt_seq #include "pycore_ast.h" // asdl_stmt_seq
#include "pycore_pystate.h" // _PyThreadState_GET() #include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_unicodeobject.h" // _PyUnicode_EqualToASCIIString()
#include <stdbool.h> // bool
#include <assert.h>
#include <stdbool.h>
#define ENTER_RECURSIVE() \ #define ENTER_RECURSIVE() \
if (Py_EnterRecursiveCall(" during compilation")) { \ if (Py_EnterRecursiveCall(" during compilation")) { \

View file

@ -2,9 +2,8 @@
#include "Python.h" #include "Python.h"
#include "pycore_ast.h" // _PyAST_GetDocString() #include "pycore_ast.h" // _PyAST_GetDocString()
#include "pycore_format.h" // F_LJUST #include "pycore_format.h" // F_LJUST
#include "pycore_long.h" // _PyLong #include "pycore_runtime.h" // _Py_STR()
#include "pycore_pystate.h" // _PyThreadState_GET() #include "pycore_unicodeobject.h" // _PyUnicode_EqualToASCIIString()
#include "pycore_setobject.h" // _PySet_NextEntry()
typedef struct { typedef struct {

View file

@ -11,11 +11,12 @@ Copyright (c) Corporation for National Research Initiatives.
#include "Python.h" #include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs() #include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_interp.h" // PyInterpreterState.codec_search_path #include "pycore_interp.h" // PyInterpreterState.codec_search_path
#include "pycore_lock.h" // PyMutex
#include "pycore_pyerrors.h" // _PyErr_FormatNote() #include "pycore_pyerrors.h" // _PyErr_FormatNote()
#include "pycore_pystate.h" // _PyInterpreterState_GET() #include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "pycore_runtime.h" // _Py_ID()
#include "pycore_ucnhash.h" // _PyUnicode_Name_CAPI #include "pycore_ucnhash.h" // _PyUnicode_Name_CAPI
static const char *codecs_builtin_error_handlers[] = { static const char *codecs_builtin_error_handlers[] = {
"strict", "ignore", "replace", "strict", "ignore", "replace",
"xmlcharrefreplace", "backslashreplace", "namereplace", "xmlcharrefreplace", "backslashreplace", "namereplace",

View file

@ -15,16 +15,20 @@
*/ */
#include "Python.h" #include "Python.h"
#include "pycore_ast.h" // PyAST_Check, _PyAST_GetDocString() #include "pycore_ast.h" // PyAST_Check()
#include "pycore_code.h" // _PyCode_GetFreevars()
#include "pycore_compile.h" #include "pycore_compile.h"
#include "pycore_flowgraph.h" #include "pycore_flowgraph.h" // _PyCfg_FromInstructionSequence()
#include "pycore_pystate.h" // _Py_GetConfig() #include "pycore_pystate.h" // _Py_GetConfig()
#include "pycore_runtime.h" // _Py_ID()
#include "pycore_setobject.h" // _PySet_NextEntry() #include "pycore_setobject.h" // _PySet_NextEntry()
#include "pycore_unicodeobject.h" // _PyUnicode_EqualToASCIIString()
#include "cpython/code.h" #include "cpython/code.h"
#include <stdbool.h> #include <stdbool.h>
#undef SUCCESS #undef SUCCESS
#undef ERROR #undef ERROR
#define SUCCESS 0 #define SUCCESS 0

View file

@ -119,6 +119,7 @@
#include "Python.h" #include "Python.h"
#include "pycore_dtoa.h" // _PY_SHORT_FLOAT_REPR #include "pycore_dtoa.h" // _PY_SHORT_FLOAT_REPR
#include "pycore_interp_structs.h"// struct Bigint
#include "pycore_pystate.h" // _PyInterpreterState_GET() #include "pycore_pystate.h" // _PyInterpreterState_GET()
#include <stdlib.h> // exit() #include <stdlib.h> // exit()

View file

@ -7,9 +7,11 @@
#include "pycore_initconfig.h" // _PyStatus_ERR() #include "pycore_initconfig.h" // _PyStatus_ERR()
#include "pycore_pyerrors.h" // _PyErr_Format() #include "pycore_pyerrors.h" // _PyErr_Format()
#include "pycore_pystate.h" // _PyThreadState_GET() #include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_runtime.h" // _Py_ID()
#include "pycore_structseq.h" // _PyStructSequence_FiniBuiltin() #include "pycore_structseq.h" // _PyStructSequence_FiniBuiltin()
#include "pycore_sysmodule.h" // _PySys_GetOptionalAttr() #include "pycore_sysmodule.h" // _PySys_GetOptionalAttr()
#include "pycore_traceback.h" // _PyTraceBack_FromFrame() #include "pycore_traceback.h" // _PyTraceBack_FromFrame()
#include "pycore_unicodeobject.h" // _PyUnicode_Equal()
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
# include <windows.h> # include <windows.h>
@ -17,6 +19,7 @@
# include <stdlib.h> // _sys_nerr # include <stdlib.h> // _sys_nerr
#endif #endif
/* Forward declarations */ /* Forward declarations */
static PyObject * static PyObject *
_PyErr_FormatV(PyThreadState *tstate, PyObject *exception, _PyErr_FormatV(PyThreadState *tstate, PyObject *exception,

View file

@ -2,13 +2,13 @@
/* Support for dynamic loading of extension modules */ /* Support for dynamic loading of extension modules */
#include "Python.h" #include "Python.h"
#include "pycore_call.h" #include "pycore_call.h" // _PyObject_CallMethod()
#include "pycore_import.h" #include "pycore_import.h" // _PyImport_SwapPackageContext()
#include "pycore_importdl.h" // struct _Py_ext_module_loader_info
#include "pycore_moduleobject.h" // _PyModule_GetDef()
#include "pycore_pyerrors.h" // _PyErr_FormatFromCause() #include "pycore_pyerrors.h" // _PyErr_FormatFromCause()
#include "pycore_pystate.h" #include "pycore_runtime.h" // _Py_ID()
#include "pycore_runtime.h"
#include "pycore_importdl.h"
/* ./configure sets HAVE_DYNAMIC_LOADING if dynamic loading of modules is /* ./configure sets HAVE_DYNAMIC_LOADING if dynamic loading of modules is
supported on this platform. configure will then compile and link in one supported on this platform. configure will then compile and link in one

View file

@ -9,17 +9,19 @@
#include "Python.h" #include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs() #include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_code.h" // _PyCode_New() #include "pycore_code.h" // _PyCode_New()
#include "pycore_critical_section.h" // Py_BEGIN_CRITICAL_SECTION()
#include "pycore_hashtable.h" // _Py_hashtable_t #include "pycore_hashtable.h" // _Py_hashtable_t
#include "pycore_long.h" // _PyLong_DigitCount #include "pycore_long.h" // _PyLong_IsZero()
#include "pycore_setobject.h" // _PySet_NextEntry()
#include "marshal.h" // Py_MARSHAL_VERSION
#include "pycore_pystate.h" // _PyInterpreterState_GET() #include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "pycore_setobject.h" // _PySet_NextEntryRef()
#include "pycore_unicodeobject.h" // _PyUnicode_InternImmortal()
#include "marshal.h" // Py_MARSHAL_VERSION
#ifdef __APPLE__ #ifdef __APPLE__
# include "TargetConditionals.h" # include "TargetConditionals.h"
#endif /* __APPLE__ */ #endif /* __APPLE__ */
/*[clinic input] /*[clinic input]
module marshal module marshal
[clinic start generated code]*/ [clinic start generated code]*/

View file

@ -2,6 +2,7 @@
#include "pycore_ceval.h" // _PyPerf_Callbacks #include "pycore_ceval.h" // _PyPerf_Callbacks
#include "pycore_frame.h" #include "pycore_frame.h"
#include "pycore_interp.h" #include "pycore_interp.h"
#include "pycore_runtime.h" // _PyRuntime
#ifdef PY_HAVE_PERF_TRAMPOLINE #ifdef PY_HAVE_PERF_TRAMPOLINE

View file

@ -133,6 +133,7 @@ any DWARF information available for them).
#include "pycore_ceval.h" // _PyPerf_Callbacks #include "pycore_ceval.h" // _PyPerf_Callbacks
#include "pycore_frame.h" #include "pycore_frame.h"
#include "pycore_interp.h" #include "pycore_interp.h"
#include "pycore_runtime.h" // _PyRuntime
#ifdef PY_HAVE_PERF_TRAMPOLINE #ifdef PY_HAVE_PERF_TRAMPOLINE

View file

@ -32,10 +32,10 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "Python.h" #include "Python.h"
#include "pycore_initconfig.h" // _PyStatus_NO_MEMORY() #include "pycore_interp.h" // PyInterpreterState
#include "pycore_lock.h" // PyMutex_Lock()
#include "pycore_qsbr.h"
#include "pycore_pystate.h" // _PyThreadState_GET() #include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_qsbr.h"
#include "pycore_tstate.h" // _PyThreadStateImpl
// Starting size of the array of qsbr thread states // Starting size of the array of qsbr thread states

View file

@ -2,7 +2,12 @@
#include "pycore_ast.h" // stmt_ty #include "pycore_ast.h" // stmt_ty
#include "pycore_parser.h" // _PyParser_ASTFromString() #include "pycore_parser.h" // _PyParser_ASTFromString()
#include "pycore_pystate.h" // _PyThreadState_GET() #include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_runtime.h" // _Py_ID()
#include "pycore_symtable.h" // PySTEntryObject #include "pycore_symtable.h" // PySTEntryObject
#include "pycore_unicodeobject.h" // _PyUnicode_EqualToASCIIString()
#include <stddef.h> // offsetof()
// Set this to 1 to dump all symtables to stdout for debugging // Set this to 1 to dump all symtables to stdout for debugging
#define _PY_DUMP_SYMTABLE 0 #define _PY_DUMP_SYMTABLE 0

View file

@ -8,8 +8,9 @@
#include "Python.h" #include "Python.h"
#include "pycore_ceval.h" // _PyEval_MakePendingCalls() #include "pycore_ceval.h" // _PyEval_MakePendingCalls()
#include "pycore_pystate.h" // _PyInterpreterState_GET() #include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "pycore_structseq.h" // _PyStructSequence_FiniBuiltin()
#include "pycore_pythread.h" // _POSIX_THREADS #include "pycore_pythread.h" // _POSIX_THREADS
#include "pycore_runtime.h" // _PyRuntime
#include "pycore_structseq.h" // _PyStructSequence_FiniBuiltin()
#ifndef DONT_HAVE_STDIO_H #ifndef DONT_HAVE_STDIO_H
# include <stdio.h> # include <stdio.h>