Skip to content

Commit 0dd3fc2

Browse files
authored
gh-108216: Cleanup #include in internal header files (#108228)
* Add missing includes. * Remove unused includes. * Update old include/symbol names to newer names. * Mention at least one included symbol. * Sort includes. * Update Tools/cases_generator/generate_cases.py used to generated pycore_opcode_metadata.h. * Update Parser/asdl_c.py used to generate pycore_ast.h. * Cleanup also includes in _testcapimodule.c and _testinternalcapi.c.
1 parent b16ecb8 commit 0dd3fc2

32 files changed

+92
-95
lines changed

Include/internal/pycore_ast.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_atomic.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

11-
#include "dynamic_annotations.h" /* _Py_ANNOTATE_MEMORY_ORDER */
12-
#include "pyconfig.h"
11+
#include "pyconfig.h" // HAVE_STD_ATOMIC
12+
#include "dynamic_annotations.h" // _Py_ANNOTATE_MEMORY_ORDER
1313

1414
#ifdef HAVE_STD_ATOMIC
15-
# include <stdatomic.h>
15+
# include <stdatomic.h> // atomic_store_explicit()
1616
#endif
1717

1818

1919
#if defined(_MSC_VER)
20-
#include <intrin.h>
21-
#if defined(_M_IX86) || defined(_M_X64)
22-
# include <immintrin.h>
23-
#endif
20+
# include <intrin.h> // _InterlockedExchange64()
21+
# if defined(_M_IX86) || defined(_M_X64)
22+
# include <immintrin.h> // _InterlockedExchange_HLEAcquire()
23+
# endif
2424
#endif
2525

2626
/* This is modeled after the atomics interface from C1x, according to

Include/internal/pycore_bitutils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ extern "C" {
2626
#endif
2727

2828
#ifdef _MSC_VER
29-
/* Get _byteswap_ushort(), _byteswap_ulong(), _byteswap_uint64() */
30-
# include <intrin.h>
29+
# include <intrin.h> // _byteswap_uint64()
3130
#endif
3231

32+
3333
static inline uint16_t
3434
_Py_bswap16(uint16_t word)
3535
{

Include/internal/pycore_ceval.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

11+
#include "pycore_interp.h" // PyInterpreterState.eval_frame
12+
#include "pycore_pystate.h" // _PyThreadState_GET()
13+
1114
/* Forward declarations */
1215
struct pyruntimestate;
1316
struct _ceval_runtime_state;
@@ -16,10 +19,6 @@ struct _ceval_runtime_state;
1619
# define Py_DEFAULT_RECURSION_LIMIT 1000
1720
#endif
1821

19-
#include "pycore_interp.h" // PyInterpreterState.eval_frame
20-
#include "pycore_pystate.h" // _PyThreadState_GET()
21-
22-
2322
extern void _Py_FinishPendingCalls(PyThreadState *tstate);
2423
extern void _PyEval_InitState(PyInterpreterState *, PyThread_type_lock);
2524
extern void _PyEval_FiniState(struct _ceval_state *ceval);

Include/internal/pycore_ceval_state.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

11-
12-
#include "pycore_atomic.h" /* _Py_atomic_address */
1311
#include "pycore_gil.h" // struct _gil_runtime_state
1412

1513

Include/internal/pycore_condvar.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
not present in unistd.h. But they still can be implemented as an external
1111
library (e.g. gnu pth in pthread emulation) */
1212
# ifdef HAVE_PTHREAD_H
13-
# include <pthread.h> /* _POSIX_THREADS */
13+
# include <pthread.h> // _POSIX_THREADS
1414
# endif
1515
#endif
1616

@@ -21,7 +21,7 @@
2121
#define Py_HAVE_CONDVAR
2222

2323
#ifdef HAVE_PTHREAD_H
24-
# include <pthread.h>
24+
# include <pthread.h> // pthread_mutex_t
2525
#endif
2626

2727
#define PyMUTEX_T pthread_mutex_t
@@ -38,7 +38,7 @@
3838

3939
/* include windows if it hasn't been done before */
4040
#define WIN32_LEAN_AND_MEAN
41-
#include <windows.h>
41+
#include <windows.h> // CRITICAL_SECTION
4242

4343
/* options */
4444
/* non-emulated condition variables are provided for those that want

Include/internal/pycore_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# error "this header requires Py_BUILD_CORE define"
66
#endif
77

8-
#include "pycore_hamt.h" /* PyHamtObject */
8+
#include "pycore_hamt.h" // PyHamtObject
99

1010

1111
extern PyTypeObject _PyContextTokenMissing_Type;

Include/internal/pycore_dict.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ extern "C" {
99
# error "this header requires Py_BUILD_CORE define"
1010
#endif
1111

12-
#include "pycore_dict_state.h"
13-
#include "pycore_object.h"
14-
#include "pycore_runtime.h" // _PyRuntime
12+
#include "pycore_object.h" // PyDictOrValues
1513

1614
// Unsafe flavor of PyDict_GetItemWithError(): no error checking
1715
extern PyObject* _PyDict_GetItemWithError(PyObject *dp, PyObject *key);

Include/internal/pycore_faulthandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ extern "C" {
99
#endif
1010

1111
#ifdef HAVE_SIGACTION
12-
# include <signal.h>
12+
# include <signal.h> // sigaction
1313
#endif
1414

1515

Include/internal/pycore_fileutils.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

11-
#include <locale.h> /* struct lconv */
11+
#include <locale.h> // struct lconv
12+
1213

1314
/* A routine to check if a file descriptor can be select()-ed. */
1415
#ifdef _MSC_VER
@@ -268,7 +269,7 @@ extern wchar_t *_Py_normpath_and_size(wchar_t *path, Py_ssize_t size, Py_ssize_t
268269
// so provide our own implementations. Remove them in case they get added
269270
// to the Games API family
270271
#if defined(MS_WINDOWS_GAMES) && !defined(MS_WINDOWS_DESKTOP)
271-
#include <winerror.h>
272+
#include <winerror.h> // HRESULT
272273

273274
extern HRESULT PathCchSkipRoot(const wchar_t *pszPath, const wchar_t **ppszRootEnd);
274275
#endif /* defined(MS_WINDOWS_GAMES) && !defined(MS_WINDOWS_DESKTOP) */

0 commit comments

Comments
 (0)