From b298b395e8ab1725c4f0dd736155b8c818664d42 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 6 Sep 2023 15:56:08 +0200 Subject: [PATCH] gh-108765: Cleanup #include in Python/*.c files (#108977) Mention one symbol imported by each #include. --- Include/internal/pycore_uops.h | 2 ++ Python/intrinsics.c | 8 ++++---- Python/legacy_tracing.c | 9 +++++---- Python/optimizer.c | 6 +++--- Python/pathconfig.c | 10 ++++++---- Python/perf_trampoline.c | 2 +- Python/pylifecycle.c | 5 +++-- Python/pystate.c | 6 +++--- Python/pystrtod.c | 3 ++- Python/pythonrun.c | 10 +++++----- Python/specialize.c | 6 +++--- Python/suggestions.c | 7 +++---- Python/symtable.c | 2 +- Python/sysmodule.c | 16 +++++++++------- Python/thread.c | 2 +- Python/thread_pthread_stubs.h | 2 +- Python/traceback.c | 4 ++-- Python/tracemalloc.c | 5 +++-- 18 files changed, 57 insertions(+), 48 deletions(-) diff --git a/Include/internal/pycore_uops.h b/Include/internal/pycore_uops.h index 254eeca2361bea..249f5c010e0092 100644 --- a/Include/internal/pycore_uops.h +++ b/Include/internal/pycore_uops.h @@ -8,6 +8,8 @@ extern "C" { # error "this header requires Py_BUILD_CORE define" #endif +#include "pycore_frame.h" // _PyInterpreterFrame + #define _Py_UOP_MAX_TRACE_LENGTH 64 typedef struct { diff --git a/Python/intrinsics.c b/Python/intrinsics.c index 8e59c63aea39ff..bbd79ec473f470 100644 --- a/Python/intrinsics.c +++ b/Python/intrinsics.c @@ -5,11 +5,11 @@ #include "pycore_frame.h" #include "pycore_function.h" #include "pycore_global_objects.h" -#include "pycore_intrinsics.h" -#include "pycore_pyerrors.h" -#include "pycore_runtime.h" +#include "pycore_intrinsics.h" // INTRINSIC_PRINT +#include "pycore_pyerrors.h" // _PyErr_SetString() +#include "pycore_runtime.h" // _Py_ID() #include "pycore_sysmodule.h" // _PySys_GetAttr() -#include "pycore_typevarobject.h" +#include "pycore_typevarobject.h" // _Py_make_typevar() /******** Unary functions ********/ diff --git a/Python/legacy_tracing.c b/Python/legacy_tracing.c index 17a13b1361f992..9258091afc7c49 100644 --- a/Python/legacy_tracing.c +++ b/Python/legacy_tracing.c @@ -2,12 +2,13 @@ * Provides callables to forward PEP 669 events to legacy events. */ -#include #include "Python.h" -#include "opcode.h" -#include "pycore_ceval.h" +#include "pycore_ceval.h" // export _PyEval_SetProfile() #include "pycore_object.h" -#include "pycore_sysmodule.h" +#include "pycore_sysmodule.h" // _PySys_Audit() + +#include "opcode.h" +#include typedef struct _PyLegacyEventHandler { PyObject_HEAD diff --git a/Python/optimizer.c b/Python/optimizer.c index 7472f52c50b766..8aaf9f9fd7cb14 100644 --- a/Python/optimizer.c +++ b/Python/optimizer.c @@ -1,9 +1,9 @@ #include "Python.h" #include "opcode.h" #include "pycore_interp.h" -#include "pycore_opcode_metadata.h" -#include "pycore_opcode_utils.h" -#include "pycore_optimizer.h" +#include "pycore_opcode_metadata.h" // _PyOpcode_OpName() +#include "pycore_opcode_utils.h" // MAX_REAL_OPCODE +#include "pycore_optimizer.h" // _Py_uop_analyze_and_optimize() #include "pycore_pystate.h" // _PyInterpreterState_GET() #include "pycore_uops.h" #include "cpython/optimizer.h" diff --git a/Python/pathconfig.c b/Python/pathconfig.c index afffa134e893ba..0ac64ec8110259 100644 --- a/Python/pathconfig.c +++ b/Python/pathconfig.c @@ -1,13 +1,15 @@ /* Path configuration like module_search_path (sys.path) */ #include "Python.h" -#include "marshal.h" // PyMarshal_ReadObjectFromString -#include "osdefs.h" // DELIM -#include "pycore_initconfig.h" -#include "pycore_fileutils.h" +#include "pycore_initconfig.h" // _PyStatus_OK() +#include "pycore_fileutils.h" // _Py_wgetcwd() #include "pycore_pathconfig.h" #include "pycore_pymem.h" // _PyMem_SetDefaultAllocator() #include + +#include "marshal.h" // PyMarshal_ReadObjectFromString +#include "osdefs.h" // DELIM + #ifdef MS_WINDOWS # include // GetFullPathNameW(), MAX_PATH # include diff --git a/Python/perf_trampoline.c b/Python/perf_trampoline.c index 0f1af30226d9fb..209a23b6c1cbc7 100644 --- a/Python/perf_trampoline.c +++ b/Python/perf_trampoline.c @@ -130,7 +130,7 @@ any DWARF information available for them). */ #include "Python.h" -#include "pycore_ceval.h" +#include "pycore_ceval.h" // _PyPerf_Callbacks #include "pycore_frame.h" #include "pycore_interp.h" #include "pycore_pyerrors.h" // _PyErr_WriteUnraisableMsg() diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 64c74f433f222c..92eef6d50712bb 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -17,7 +17,7 @@ #include "pycore_list.h" // _PyList_Fini() #include "pycore_long.h" // _PyLong_InitTypes() #include "pycore_object.h" // _PyDebug_PrintTotalRefs() -#include "pycore_pathconfig.h" // _PyConfig_WritePathConfig() +#include "pycore_pathconfig.h" // _PyPathConfig_UpdateGlobal() #include "pycore_pyerrors.h" // _PyErr_Occurred() #include "pycore_pylifecycle.h" // _PyErr_Print() #include "pycore_pymem.h" // _PyObject_DebugMallocStats() @@ -32,13 +32,14 @@ #include "pycore_typevarobject.h" // _Py_clear_generic_types() #include "pycore_unicodeobject.h" // _PyUnicode_InitTypes() #include "pycore_weakref.h" // _PyWeakref_GET_REF() + #include "opcode.h" #include // setlocale() #include // getenv() #if defined(__APPLE__) -#include +# include #endif #ifdef HAVE_SIGNAL_H diff --git a/Python/pystate.c b/Python/pystate.c index 46ea2c4f678db8..b2b9b9f8776c33 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -6,10 +6,10 @@ #include "pycore_code.h" // stats #include "pycore_dtoa.h" // _dtoa_state_INIT() #include "pycore_frame.h" -#include "pycore_initconfig.h" +#include "pycore_initconfig.h" // _PyStatus_OK() #include "pycore_object.h" // _PyType_InitCache() -#include "pycore_pyerrors.h" -#include "pycore_pylifecycle.h" +#include "pycore_pyerrors.h" // _PyErr_Clear() +#include "pycore_pylifecycle.h" // _PyAST_Fini() #include "pycore_pymem.h" // _PyMem_SetDefaultAllocator() #include "pycore_pystate.h" #include "pycore_runtime_init.h" // _PyRuntimeState_INIT diff --git a/Python/pystrtod.c b/Python/pystrtod.c index 9bb060e3d11979..16bf06f0e6cca2 100644 --- a/Python/pystrtod.c +++ b/Python/pystrtod.c @@ -3,7 +3,8 @@ #include #include "pycore_dtoa.h" // _Py_dg_strtod() #include "pycore_pymath.h" // _PY_SHORT_FLOAT_REPR -#include + +#include // localeconv() /* Case-insensitive string match used for nan and inf detection; t should be lower-case. Returns 1 for a successful match, 0 otherwise. */ diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 231ac78146a0e6..ddd8951cedb1f1 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -12,16 +12,16 @@ #include "Python.h" -#include "pycore_ast.h" // PyAST_mod2obj -#include "pycore_ceval.h" // _Py_EnterRecursiveCall +#include "pycore_ast.h" // PyAST_mod2obj() +#include "pycore_ceval.h" // _Py_EnterRecursiveCall() #include "pycore_compile.h" // _PyAST_Compile() #include "pycore_interp.h" // PyInterpreterState.importlib #include "pycore_object.h" // _PyDebug_PrintTotalRefs() #include "pycore_parser.h" // _PyParser_ASTFromString() -#include "pycore_pyerrors.h" // _PyErr_GetRaisedException, _Py_Offer_Suggestions -#include "pycore_pylifecycle.h" // _Py_UnhandledKeyboardInterrupt +#include "pycore_pyerrors.h" // _PyErr_GetRaisedException() +#include "pycore_pylifecycle.h" // _Py_FdIsInteractive() #include "pycore_pystate.h" // _PyInterpreterState_GET() -#include "pycore_pythonrun.h" // define _PyRun_InteractiveLoopObject() +#include "pycore_pythonrun.h" // export _PyRun_InteractiveLoopObject() #include "pycore_sysmodule.h" // _PySys_Audit() #include "pycore_traceback.h" // _PyTraceBack_Print_Indented() diff --git a/Python/specialize.c b/Python/specialize.c index a794f146c188ec..aa40b3343f3add 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -4,14 +4,14 @@ #include "pycore_code.h" #include "pycore_descrobject.h" // _PyMethodWrapper_Type -#include "pycore_dict.h" +#include "pycore_dict.h" // DICT_KEYS_UNICODE #include "pycore_function.h" // _PyFunction_GetVersionForCurrentState() -#include "pycore_global_strings.h" // _Py_ID() -#include "pycore_long.h" +#include "pycore_long.h" // _PyLong_IsNonNegativeCompact() #include "pycore_moduleobject.h" #include "pycore_object.h" #include "pycore_opcode_metadata.h" // _PyOpcode_Caches #include "pycore_pylifecycle.h" // _PyOS_URandomNonblock() +#include "pycore_runtime.h" // _Py_ID() #include // rand() diff --git a/Python/suggestions.c b/Python/suggestions.c index 12097f793e3575..9247da4c7037a2 100644 --- a/Python/suggestions.c +++ b/Python/suggestions.c @@ -1,10 +1,9 @@ #include "Python.h" +#include "pycore_code.h" // _PyCode_GetVarnames() #include "pycore_frame.h" -#include "pycore_runtime.h" // _PyRuntime -#include "pycore_global_objects.h" // _Py_ID() +#include "pycore_pyerrors.h" // export _Py_UTF8_Edit_Cost() +#include "pycore_runtime.h" // _Py_ID() -#include "pycore_pyerrors.h" -#include "pycore_code.h" // _PyCode_GetVarnames() #include "stdlib_module_names.h" // _Py_stdlib_module_names #define MAX_CANDIDATE_ITEMS 750 diff --git a/Python/symtable.c b/Python/symtable.c index e9adbd5d29b1f9..f157d4c170314a 100644 --- a/Python/symtable.c +++ b/Python/symtable.c @@ -1,5 +1,5 @@ #include "Python.h" -#include "pycore_ast.h" // identifier, stmt_ty +#include "pycore_ast.h" // stmt_ty #include "pycore_parser.h" // _PyParser_ASTFromString() #include "pycore_pystate.h" // _PyThreadState_GET() #include "pycore_symtable.h" // PySTEntryObject diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 0ec763c7aa7cf8..3835f760072ef9 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -23,7 +23,7 @@ Data members: #include "pycore_long.h" // _PY_LONG_MAX_STR_DIGITS_THRESHOLD #include "pycore_modsupport.h" // _PyModule_CreateInitialized() #include "pycore_namespace.h" // _PyNamespace_New() -#include "pycore_object.h" // _PyObject_IS_GC(), _PyObject_DebugTypeStats() +#include "pycore_object.h" // _PyObject_DebugTypeStats() #include "pycore_pathconfig.h" // _PyPathConfig_ComputeSysPath0() #include "pycore_pyerrors.h" // _PyErr_GetRaisedException() #include "pycore_pylifecycle.h" // _PyErr_WriteUnraisableDefaultHook() @@ -31,18 +31,19 @@ Data members: #include "pycore_pymem.h" // _PyMem_SetDefaultAllocator() #include "pycore_pystate.h" // _PyThreadState_GET() #include "pycore_structseq.h" // _PyStructSequence_InitBuiltinWithFlags() -#include "pycore_sysmodule.h" // Define _PySys_GetSizeOf() +#include "pycore_sysmodule.h" // export _PySys_GetSizeOf() #include "pycore_tuple.h" // _PyTuple_FromArray() #include "frameobject.h" // PyFrame_FastToLocalsWithError() -#include "pydtrace.h" +#include "pydtrace.h" // PyDTrace_AUDIT() #include "osdefs.h" // DELIM #include "stdlib_module_names.h" // _Py_stdlib_module_names + #include #ifdef MS_WINDOWS -#define WIN32_LEAN_AND_MEAN -#include +# define WIN32_LEAN_AND_MEAN +# include #endif /* MS_WINDOWS */ #ifdef MS_COREDLL @@ -52,11 +53,11 @@ extern const char *PyWin_DLLVersionString; #endif #ifdef __EMSCRIPTEN__ -#include +# include #endif #ifdef HAVE_FCNTL_H -#include +# include #endif /*[clinic input] @@ -66,6 +67,7 @@ module sys #include "clinic/sysmodule.c.h" + PyObject * _PySys_GetAttr(PyThreadState *tstate, PyObject *name) { diff --git a/Python/thread.c b/Python/thread.c index 7fc53f9b61360b..1ac2db2937e373 100644 --- a/Python/thread.c +++ b/Python/thread.c @@ -11,7 +11,7 @@ #include "pycore_pythread.h" #ifndef DONT_HAVE_STDIO_H -#include +# include #endif #include diff --git a/Python/thread_pthread_stubs.h b/Python/thread_pthread_stubs.h index 56e5b6141924b4..48bad36ec449ab 100644 --- a/Python/thread_pthread_stubs.h +++ b/Python/thread_pthread_stubs.h @@ -40,7 +40,7 @@ pthread_cond_init(pthread_cond_t *restrict cond, return 0; } -PyAPI_FUNC(int)pthread_cond_destroy(pthread_cond_t *cond) +PyAPI_FUNC(int) pthread_cond_destroy(pthread_cond_t *cond) { return 0; } diff --git a/Python/traceback.c b/Python/traceback.c index 657ddab1cbf615..2fcfa7ca56c140 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -3,9 +3,9 @@ #include "Python.h" -#include "pycore_ast.h" // asdl_seq_* +#include "pycore_ast.h" // asdl_seq_GET() #include "pycore_call.h" // _PyObject_CallMethodFormat() -#include "pycore_compile.h" // _PyAST_Optimize +#include "pycore_compile.h" // _PyAST_Optimize() #include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH #include "pycore_frame.h" // _PyFrame_GetCode() #include "pycore_interp.h" // PyInterpreterState.gc diff --git a/Python/tracemalloc.c b/Python/tracemalloc.c index 7d294ea5fe744c..19b64c619feb6a 100644 --- a/Python/tracemalloc.c +++ b/Python/tracemalloc.c @@ -2,11 +2,12 @@ #include "pycore_fileutils.h" // _Py_write_noraise() #include "pycore_gc.h" // PyGC_Head #include "pycore_hashtable.h" // _Py_hashtable_t -#include "pycore_object.h" // _PyType_PreHeaderSize +#include "pycore_object.h" // _PyType_PreHeaderSize() #include "pycore_pymem.h" // _Py_tracemalloc_config #include "pycore_runtime.h" // _Py_ID() -#include "pycore_traceback.h" +#include "pycore_traceback.h" // _Py_DumpASCII() #include + #include "frameobject.h" // _PyInterpreterFrame_GetLine #include // malloc()