Skip to content

Commit b298b39

Browse files
authored
gh-108765: Cleanup #include in Python/*.c files (#108977)
Mention one symbol imported by each #include.
1 parent 14d6e19 commit b298b39

18 files changed

+57
-48
lines changed

Include/internal/pycore_uops.h

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

11+
#include "pycore_frame.h" // _PyInterpreterFrame
12+
1113
#define _Py_UOP_MAX_TRACE_LENGTH 64
1214

1315
typedef struct {

Python/intrinsics.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
#include "pycore_frame.h"
66
#include "pycore_function.h"
77
#include "pycore_global_objects.h"
8-
#include "pycore_intrinsics.h"
9-
#include "pycore_pyerrors.h"
10-
#include "pycore_runtime.h"
8+
#include "pycore_intrinsics.h" // INTRINSIC_PRINT
9+
#include "pycore_pyerrors.h" // _PyErr_SetString()
10+
#include "pycore_runtime.h" // _Py_ID()
1111
#include "pycore_sysmodule.h" // _PySys_GetAttr()
12-
#include "pycore_typevarobject.h"
12+
#include "pycore_typevarobject.h" // _Py_make_typevar()
1313

1414

1515
/******** Unary functions ********/

Python/legacy_tracing.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
* Provides callables to forward PEP 669 events to legacy events.
33
*/
44

5-
#include <stddef.h>
65
#include "Python.h"
7-
#include "opcode.h"
8-
#include "pycore_ceval.h"
6+
#include "pycore_ceval.h" // export _PyEval_SetProfile()
97
#include "pycore_object.h"
10-
#include "pycore_sysmodule.h"
8+
#include "pycore_sysmodule.h" // _PySys_Audit()
9+
10+
#include "opcode.h"
11+
#include <stddef.h>
1112

1213
typedef struct _PyLegacyEventHandler {
1314
PyObject_HEAD

Python/optimizer.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include "Python.h"
22
#include "opcode.h"
33
#include "pycore_interp.h"
4-
#include "pycore_opcode_metadata.h"
5-
#include "pycore_opcode_utils.h"
6-
#include "pycore_optimizer.h"
4+
#include "pycore_opcode_metadata.h" // _PyOpcode_OpName()
5+
#include "pycore_opcode_utils.h" // MAX_REAL_OPCODE
6+
#include "pycore_optimizer.h" // _Py_uop_analyze_and_optimize()
77
#include "pycore_pystate.h" // _PyInterpreterState_GET()
88
#include "pycore_uops.h"
99
#include "cpython/optimizer.h"

Python/pathconfig.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
/* Path configuration like module_search_path (sys.path) */
22

33
#include "Python.h"
4-
#include "marshal.h" // PyMarshal_ReadObjectFromString
5-
#include "osdefs.h" // DELIM
6-
#include "pycore_initconfig.h"
7-
#include "pycore_fileutils.h"
4+
#include "pycore_initconfig.h" // _PyStatus_OK()
5+
#include "pycore_fileutils.h" // _Py_wgetcwd()
86
#include "pycore_pathconfig.h"
97
#include "pycore_pymem.h" // _PyMem_SetDefaultAllocator()
108
#include <wchar.h>
9+
10+
#include "marshal.h" // PyMarshal_ReadObjectFromString
11+
#include "osdefs.h" // DELIM
12+
1113
#ifdef MS_WINDOWS
1214
# include <windows.h> // GetFullPathNameW(), MAX_PATH
1315
# include <pathcch.h>

Python/perf_trampoline.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ any DWARF information available for them).
130130
*/
131131

132132
#include "Python.h"
133-
#include "pycore_ceval.h"
133+
#include "pycore_ceval.h" // _PyPerf_Callbacks
134134
#include "pycore_frame.h"
135135
#include "pycore_interp.h"
136136
#include "pycore_pyerrors.h" // _PyErr_WriteUnraisableMsg()

Python/pylifecycle.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "pycore_list.h" // _PyList_Fini()
1818
#include "pycore_long.h" // _PyLong_InitTypes()
1919
#include "pycore_object.h" // _PyDebug_PrintTotalRefs()
20-
#include "pycore_pathconfig.h" // _PyConfig_WritePathConfig()
20+
#include "pycore_pathconfig.h" // _PyPathConfig_UpdateGlobal()
2121
#include "pycore_pyerrors.h" // _PyErr_Occurred()
2222
#include "pycore_pylifecycle.h" // _PyErr_Print()
2323
#include "pycore_pymem.h" // _PyObject_DebugMallocStats()
@@ -32,13 +32,14 @@
3232
#include "pycore_typevarobject.h" // _Py_clear_generic_types()
3333
#include "pycore_unicodeobject.h" // _PyUnicode_InitTypes()
3434
#include "pycore_weakref.h" // _PyWeakref_GET_REF()
35+
3536
#include "opcode.h"
3637

3738
#include <locale.h> // setlocale()
3839
#include <stdlib.h> // getenv()
3940

4041
#if defined(__APPLE__)
41-
#include <mach-o/loader.h>
42+
# include <mach-o/loader.h>
4243
#endif
4344

4445
#ifdef HAVE_SIGNAL_H

Python/pystate.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
#include "pycore_code.h" // stats
77
#include "pycore_dtoa.h" // _dtoa_state_INIT()
88
#include "pycore_frame.h"
9-
#include "pycore_initconfig.h"
9+
#include "pycore_initconfig.h" // _PyStatus_OK()
1010
#include "pycore_object.h" // _PyType_InitCache()
11-
#include "pycore_pyerrors.h"
12-
#include "pycore_pylifecycle.h"
11+
#include "pycore_pyerrors.h" // _PyErr_Clear()
12+
#include "pycore_pylifecycle.h" // _PyAST_Fini()
1313
#include "pycore_pymem.h" // _PyMem_SetDefaultAllocator()
1414
#include "pycore_pystate.h"
1515
#include "pycore_runtime_init.h" // _PyRuntimeState_INIT

Python/pystrtod.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
#include <Python.h>
44
#include "pycore_dtoa.h" // _Py_dg_strtod()
55
#include "pycore_pymath.h" // _PY_SHORT_FLOAT_REPR
6-
#include <locale.h>
6+
7+
#include <locale.h> // localeconv()
78

89
/* Case-insensitive string match used for nan and inf detection; t should be
910
lower-case. Returns 1 for a successful match, 0 otherwise. */

Python/pythonrun.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212

1313
#include "Python.h"
1414

15-
#include "pycore_ast.h" // PyAST_mod2obj
16-
#include "pycore_ceval.h" // _Py_EnterRecursiveCall
15+
#include "pycore_ast.h" // PyAST_mod2obj()
16+
#include "pycore_ceval.h" // _Py_EnterRecursiveCall()
1717
#include "pycore_compile.h" // _PyAST_Compile()
1818
#include "pycore_interp.h" // PyInterpreterState.importlib
1919
#include "pycore_object.h" // _PyDebug_PrintTotalRefs()
2020
#include "pycore_parser.h" // _PyParser_ASTFromString()
21-
#include "pycore_pyerrors.h" // _PyErr_GetRaisedException, _Py_Offer_Suggestions
22-
#include "pycore_pylifecycle.h" // _Py_UnhandledKeyboardInterrupt
21+
#include "pycore_pyerrors.h" // _PyErr_GetRaisedException()
22+
#include "pycore_pylifecycle.h" // _Py_FdIsInteractive()
2323
#include "pycore_pystate.h" // _PyInterpreterState_GET()
24-
#include "pycore_pythonrun.h" // define _PyRun_InteractiveLoopObject()
24+
#include "pycore_pythonrun.h" // export _PyRun_InteractiveLoopObject()
2525
#include "pycore_sysmodule.h" // _PySys_Audit()
2626
#include "pycore_traceback.h" // _PyTraceBack_Print_Indented()
2727

Python/specialize.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
#include "pycore_code.h"
66
#include "pycore_descrobject.h" // _PyMethodWrapper_Type
7-
#include "pycore_dict.h"
7+
#include "pycore_dict.h" // DICT_KEYS_UNICODE
88
#include "pycore_function.h" // _PyFunction_GetVersionForCurrentState()
9-
#include "pycore_global_strings.h" // _Py_ID()
10-
#include "pycore_long.h"
9+
#include "pycore_long.h" // _PyLong_IsNonNegativeCompact()
1110
#include "pycore_moduleobject.h"
1211
#include "pycore_object.h"
1312
#include "pycore_opcode_metadata.h" // _PyOpcode_Caches
1413
#include "pycore_pylifecycle.h" // _PyOS_URandomNonblock()
14+
#include "pycore_runtime.h" // _Py_ID()
1515

1616

1717
#include <stdlib.h> // rand()

Python/suggestions.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#include "Python.h"
2+
#include "pycore_code.h" // _PyCode_GetVarnames()
23
#include "pycore_frame.h"
3-
#include "pycore_runtime.h" // _PyRuntime
4-
#include "pycore_global_objects.h" // _Py_ID()
4+
#include "pycore_pyerrors.h" // export _Py_UTF8_Edit_Cost()
5+
#include "pycore_runtime.h" // _Py_ID()
56

6-
#include "pycore_pyerrors.h"
7-
#include "pycore_code.h" // _PyCode_GetVarnames()
87
#include "stdlib_module_names.h" // _Py_stdlib_module_names
98

109
#define MAX_CANDIDATE_ITEMS 750

Python/symtable.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "Python.h"
2-
#include "pycore_ast.h" // identifier, stmt_ty
2+
#include "pycore_ast.h" // stmt_ty
33
#include "pycore_parser.h" // _PyParser_ASTFromString()
44
#include "pycore_pystate.h" // _PyThreadState_GET()
55
#include "pycore_symtable.h" // PySTEntryObject

Python/sysmodule.c

+9-7
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,27 @@ Data members:
2323
#include "pycore_long.h" // _PY_LONG_MAX_STR_DIGITS_THRESHOLD
2424
#include "pycore_modsupport.h" // _PyModule_CreateInitialized()
2525
#include "pycore_namespace.h" // _PyNamespace_New()
26-
#include "pycore_object.h" // _PyObject_IS_GC(), _PyObject_DebugTypeStats()
26+
#include "pycore_object.h" // _PyObject_DebugTypeStats()
2727
#include "pycore_pathconfig.h" // _PyPathConfig_ComputeSysPath0()
2828
#include "pycore_pyerrors.h" // _PyErr_GetRaisedException()
2929
#include "pycore_pylifecycle.h" // _PyErr_WriteUnraisableDefaultHook()
3030
#include "pycore_pymath.h" // _PY_SHORT_FLOAT_REPR
3131
#include "pycore_pymem.h" // _PyMem_SetDefaultAllocator()
3232
#include "pycore_pystate.h" // _PyThreadState_GET()
3333
#include "pycore_structseq.h" // _PyStructSequence_InitBuiltinWithFlags()
34-
#include "pycore_sysmodule.h" // Define _PySys_GetSizeOf()
34+
#include "pycore_sysmodule.h" // export _PySys_GetSizeOf()
3535
#include "pycore_tuple.h" // _PyTuple_FromArray()
3636

3737
#include "frameobject.h" // PyFrame_FastToLocalsWithError()
38-
#include "pydtrace.h"
38+
#include "pydtrace.h" // PyDTrace_AUDIT()
3939
#include "osdefs.h" // DELIM
4040
#include "stdlib_module_names.h" // _Py_stdlib_module_names
41+
4142
#include <locale.h>
4243

4344
#ifdef MS_WINDOWS
44-
#define WIN32_LEAN_AND_MEAN
45-
#include <windows.h>
45+
# define WIN32_LEAN_AND_MEAN
46+
# include <windows.h>
4647
#endif /* MS_WINDOWS */
4748

4849
#ifdef MS_COREDLL
@@ -52,11 +53,11 @@ extern const char *PyWin_DLLVersionString;
5253
#endif
5354

5455
#ifdef __EMSCRIPTEN__
55-
#include <emscripten.h>
56+
# include <emscripten.h>
5657
#endif
5758

5859
#ifdef HAVE_FCNTL_H
59-
#include <fcntl.h>
60+
# include <fcntl.h>
6061
#endif
6162

6263
/*[clinic input]
@@ -66,6 +67,7 @@ module sys
6667

6768
#include "clinic/sysmodule.c.h"
6869

70+
6971
PyObject *
7072
_PySys_GetAttr(PyThreadState *tstate, PyObject *name)
7173
{

Python/thread.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "pycore_pythread.h"
1212

1313
#ifndef DONT_HAVE_STDIO_H
14-
#include <stdio.h>
14+
# include <stdio.h>
1515
#endif
1616

1717
#include <stdlib.h>

Python/thread_pthread_stubs.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pthread_cond_init(pthread_cond_t *restrict cond,
4040
return 0;
4141
}
4242

43-
PyAPI_FUNC(int)pthread_cond_destroy(pthread_cond_t *cond)
43+
PyAPI_FUNC(int) pthread_cond_destroy(pthread_cond_t *cond)
4444
{
4545
return 0;
4646
}

Python/traceback.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
#include "Python.h"
55

6-
#include "pycore_ast.h" // asdl_seq_*
6+
#include "pycore_ast.h" // asdl_seq_GET()
77
#include "pycore_call.h" // _PyObject_CallMethodFormat()
8-
#include "pycore_compile.h" // _PyAST_Optimize
8+
#include "pycore_compile.h" // _PyAST_Optimize()
99
#include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH
1010
#include "pycore_frame.h" // _PyFrame_GetCode()
1111
#include "pycore_interp.h" // PyInterpreterState.gc

Python/tracemalloc.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
#include "pycore_fileutils.h" // _Py_write_noraise()
33
#include "pycore_gc.h" // PyGC_Head
44
#include "pycore_hashtable.h" // _Py_hashtable_t
5-
#include "pycore_object.h" // _PyType_PreHeaderSize
5+
#include "pycore_object.h" // _PyType_PreHeaderSize()
66
#include "pycore_pymem.h" // _Py_tracemalloc_config
77
#include "pycore_runtime.h" // _Py_ID()
8-
#include "pycore_traceback.h"
8+
#include "pycore_traceback.h" // _Py_DumpASCII()
99
#include <pycore_frame.h>
10+
1011
#include "frameobject.h" // _PyInterpreterFrame_GetLine
1112

1213
#include <stdlib.h> // malloc()

0 commit comments

Comments
 (0)