Skip to content

Commit

Permalink
pythongh-108216: Cleanup #include in internal header files
Browse files Browse the repository at this point in the history
* Add missing includes
* Remove unused includes
* Mention at least once included symbol
* Sort includes
  • Loading branch information
vstinner committed Aug 21, 2023
1 parent 21c0844 commit dff2218
Show file tree
Hide file tree
Showing 32 changed files with 92 additions and 95 deletions.
2 changes: 1 addition & 1 deletion Include/internal/pycore_ast.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions Include/internal/pycore_atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif

#include "dynamic_annotations.h" /* _Py_ANNOTATE_MEMORY_ORDER */
#include "pyconfig.h"
#include "pyconfig.h" // HAVE_STD_ATOMIC
#include "dynamic_annotations.h" // _Py_ANNOTATE_MEMORY_ORDER

#ifdef HAVE_STD_ATOMIC
# include <stdatomic.h>
# include <stdatomic.h> // atomic_store_explicit()
#endif


#if defined(_MSC_VER)
#include <intrin.h>
#if defined(_M_IX86) || defined(_M_X64)
# include <immintrin.h>
#endif
# include <intrin.h> // _InterlockedExchange64()
# if defined(_M_IX86) || defined(_M_X64)
# include <immintrin.h> // _InterlockedExchange_HLEAcquire()
# endif
#endif

/* This is modeled after the atomics interface from C1x, according to
Expand Down
4 changes: 2 additions & 2 deletions Include/internal/pycore_bitutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ extern "C" {
#endif

#ifdef _MSC_VER
/* Get _byteswap_ushort(), _byteswap_ulong(), _byteswap_uint64() */
# include <intrin.h>
# include <intrin.h> // _byteswap_uint64()
#endif


static inline uint16_t
_Py_bswap16(uint16_t word)
{
Expand Down
7 changes: 3 additions & 4 deletions Include/internal/pycore_ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif

#include "pycore_interp.h" // PyInterpreterState.eval_frame
#include "pycore_pystate.h" // _PyThreadState_GET()

/* Forward declarations */
struct pyruntimestate;
struct _ceval_runtime_state;
Expand All @@ -16,10 +19,6 @@ struct _ceval_runtime_state;
# define Py_DEFAULT_RECURSION_LIMIT 1000
#endif

#include "pycore_interp.h" // PyInterpreterState.eval_frame
#include "pycore_pystate.h" // _PyThreadState_GET()


extern void _Py_FinishPendingCalls(PyThreadState *tstate);
extern void _PyEval_InitState(PyInterpreterState *, PyThread_type_lock);
extern void _PyEval_FiniState(struct _ceval_state *ceval);
Expand Down
2 changes: 0 additions & 2 deletions Include/internal/pycore_ceval_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif


#include "pycore_atomic.h" /* _Py_atomic_address */
#include "pycore_gil.h" // struct _gil_runtime_state


Expand Down
6 changes: 3 additions & 3 deletions Include/internal/pycore_condvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
not present in unistd.h. But they still can be implemented as an external
library (e.g. gnu pth in pthread emulation) */
# ifdef HAVE_PTHREAD_H
# include <pthread.h> /* _POSIX_THREADS */
# include <pthread.h> // _POSIX_THREADS
# endif
#endif

Expand All @@ -21,7 +21,7 @@
#define Py_HAVE_CONDVAR

#ifdef HAVE_PTHREAD_H
# include <pthread.h>
# include <pthread.h> // pthread_mutex_t
#endif

#define PyMUTEX_T pthread_mutex_t
Expand All @@ -38,7 +38,7 @@

/* include windows if it hasn't been done before */
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windows.h> // CRITICAL_SECTION

/* options */
/* non-emulated condition variables are provided for those that want
Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# error "this header requires Py_BUILD_CORE define"
#endif

#include "pycore_hamt.h" /* PyHamtObject */
#include "pycore_hamt.h" // PyHamtObject


extern PyTypeObject _PyContextTokenMissing_Type;
Expand Down
4 changes: 1 addition & 3 deletions Include/internal/pycore_dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif

#include "pycore_dict_state.h"
#include "pycore_object.h"
#include "pycore_runtime.h" // _PyRuntime
#include "pycore_object.h" // PyDictOrValues

// Unsafe flavor of PyDict_GetItemWithError(): no error checking
extern PyObject* _PyDict_GetItemWithError(PyObject *dp, PyObject *key);
Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_faulthandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extern "C" {
#endif

#ifdef HAVE_SIGACTION
# include <signal.h>
# include <signal.h> // sigaction
#endif


Expand Down
5 changes: 3 additions & 2 deletions Include/internal/pycore_fileutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif

#include <locale.h> /* struct lconv */
#include <locale.h> // struct lconv


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

extern HRESULT PathCchSkipRoot(const wchar_t *pszPath, const wchar_t **ppszRootEnd);
#endif /* defined(MS_WINDOWS_GAMES) && !defined(MS_WINDOWS_DESKTOP) */
Expand Down
4 changes: 2 additions & 2 deletions Include/internal/pycore_gil.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif

#include "pycore_atomic.h" /* _Py_atomic_address */
#include "pycore_condvar.h" /* PyCOND_T */
#include "pycore_atomic.h" // _Py_atomic_address
#include "pycore_condvar.h" // PyCOND_T

#ifndef Py_HAVE_CONDVAR
# error You need either a POSIX-compatible or a Windows system!
Expand Down
6 changes: 3 additions & 3 deletions Include/internal/pycore_global_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif

#include "pycore_hashtable.h" // _Py_hashtable_t
#include "pycore_gc.h" // PyGC_Head
#include "pycore_context.h" // _PyContextTokenMissing
#include "pycore_gc.h" // _PyGC_Head_UNUSED
#include "pycore_global_strings.h" // struct _Py_global_strings
#include "pycore_hamt.h" // PyHamtNode_Bitmap
#include "pycore_context.h" // _PyContextTokenMissing
#include "pycore_hashtable.h" // _Py_hashtable_t
#include "pycore_typeobject.h" // pytype_slotdef


Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_import.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ struct _import_state {
};

#ifdef HAVE_DLOPEN
# include <dlfcn.h>
# include <dlfcn.h> // RTLD_NOW, RTLD_LAZY
# if HAVE_DECL_RTLD_NOW
# define _Py_DLOPEN_FLAGS RTLD_NOW
# else
Expand Down
4 changes: 1 addition & 3 deletions Include/internal/pycore_instruments.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
#endif

#include "pycore_bitutils.h" // _Py_popcount32
#include "pycore_frame.h"

#include "cpython/code.h"
#include "pycore_frame.h" // _PyInterpreterFrame

#ifdef __cplusplus
extern "C" {
Expand Down
12 changes: 6 additions & 6 deletions Include/internal/pycore_interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif

#include <stdbool.h>
#include <stdbool.h> // bool

#include "pycore_ast_state.h" // struct ast_state
#include "pycore_atexit.h" // struct atexit_state
Expand All @@ -21,16 +21,16 @@ extern "C" {
#include "pycore_exceptions.h" // struct _Py_exc_state
#include "pycore_floatobject.h" // struct _Py_float_state
#include "pycore_function.h" // FUNC_MAX_WATCHERS
#include "pycore_genobject.h" // struct _Py_async_gen_state
#include "pycore_gc.h" // struct _gc_runtime_state
#include "pycore_global_objects.h" // struct _Py_interp_static_objects
#include "pycore_genobject.h" // struct _Py_async_gen_state
#include "pycore_global_objects.h"// struct _Py_interp_cached_objects
#include "pycore_import.h" // struct _import_state
#include "pycore_instruments.h" // _PY_MONITORING_EVENTS
#include "pycore_list.h" // struct _Py_list_state
#include "pycore_object_state.h" // struct _py_object_state
#include "pycore_obmalloc.h" // struct obmalloc_state
#include "pycore_object_state.h" // struct _py_object_state
#include "pycore_obmalloc.h" // struct _obmalloc_state
#include "pycore_tuple.h" // struct _Py_tuple_state
#include "pycore_typeobject.h" // struct type_cache
#include "pycore_typeobject.h" // struct types_state
#include "pycore_unicodeobject.h" // struct _Py_unicode_state
#include "pycore_warnings.h" // struct _warnings_runtime_state

Expand Down
1 change: 0 additions & 1 deletion Include/internal/pycore_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ extern "C" {
#include "pycore_gc.h" // _PyObject_GC_IS_TRACKED()
#include "pycore_interp.h" // PyInterpreterState.gc
#include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "pycore_runtime.h" // _PyRuntime

/* Check if an object is consistent. For example, ensure that the reference
counter is greater than or equal to 1, and ensure that ob_type is not NULL.
Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_opcode_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Include/internal/pycore_opcode_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif

#include "pycore_opcode.h" // _PyOpcode_Jump
#include "pycore_opcode.h" // JUMP_FORWARD


#define MAX_REAL_OPCODE 254
Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_optimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif

#include "pycore_uops.h"
#include "pycore_uops.h" // _PyUOpInstruction

int _Py_uop_analyze_and_optimize(PyCodeObject *code,
_PyUOpInstruction *trace, int trace_len, int curr_stackentries);
Expand Down
2 changes: 0 additions & 2 deletions Include/internal/pycore_pymem_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif

#include "pycore_pymem.h"


/********************************/
/* the allocators' initializers */
Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif

#include "pycore_runtime.h" /* PyRuntimeState */
#include "pycore_runtime.h" // _PyRuntime


/* Check if the current thread is the main thread.
Expand Down
10 changes: 5 additions & 5 deletions Include/internal/pycore_pythread.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ extern "C" {
/* 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
library (e.g. gnu pth in pthread emulation) */
# ifdef HAVE_PTHREAD_H
# include <pthread.h> /* _POSIX_THREADS */
# endif
# ifdef HAVE_PTHREAD_H
# include <pthread.h> // _POSIX_THREADS
# endif
# ifndef _POSIX_THREADS
/* Check if we're running on HP-UX and _SC_THREADS is defined. If so, then
enough of the Posix threads package is implemented to support python
Expand All @@ -34,12 +34,12 @@ extern "C" {
#endif /* _POSIX_THREADS */

#if defined(_POSIX_THREADS) || defined(HAVE_PTHREAD_STUBS)
# define _USE_PTHREADS
# define _USE_PTHREADS
#endif

#if defined(_USE_PTHREADS) && defined(HAVE_PTHREAD_CONDATTR_SETCLOCK) && defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
// monotonic is supported statically. It doesn't mean it works on runtime.
# define CONDATTR_MONOTONIC
# define CONDATTR_MONOTONIC
#endif


Expand Down
13 changes: 6 additions & 7 deletions Include/internal/pycore_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,23 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif

#include "pycore_atexit.h" // struct atexit_runtime_state
#include "pycore_atomic.h" /* _Py_atomic_address */
#include "pycore_atexit.h" // struct _atexit_runtime_state
#include "pycore_atomic.h" // _Py_atomic_address
#include "pycore_ceval_state.h" // struct _ceval_runtime_state
#include "pycore_floatobject.h" // struct _Py_float_runtime_state
#include "pycore_faulthandler.h" // struct _faulthandler_runtime_state
#include "pycore_global_objects.h" // struct _Py_global_objects
#include "pycore_floatobject.h" // struct _Py_float_runtime_state
#include "pycore_import.h" // struct _import_runtime_state
#include "pycore_interp.h" // PyInterpreterState
#include "pycore_object_state.h" // struct _py_object_runtime_state
#include "pycore_parser.h" // struct _parser_runtime_state
#include "pycore_pymem.h" // struct _pymem_allocators
#include "pycore_pyhash.h" // struct pyhash_runtime_state
#include "pycore_pymem.h" // struct _pymem_allocators
#include "pycore_pythread.h" // struct _pythread_runtime_state
#include "pycore_signal.h" // struct _signals_runtime_state
#include "pycore_time.h" // struct _time_runtime_state
#include "pycore_tracemalloc.h" // struct _tracemalloc_runtime_state
#include "pycore_typeobject.h" // struct types_runtime_state
#include "pycore_unicodeobject.h" // struct _Py_unicode_runtime_ids
#include "pycore_typeobject.h" // struct _types_runtime_state
#include "pycore_unicodeobject.h" // struct _Py_unicode_runtime_state

struct _getargs_runtime_state {
PyThread_type_lock mutex;
Expand Down
16 changes: 11 additions & 5 deletions Include/internal/pycore_runtime_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif

#include "pycore_long.h"
#include "pycore_object.h"
#include "pycore_parser.h"
#include "pycore_pymem_init.h"
#include "pycore_obmalloc_init.h"
#include "pycore_ceval_state.h" // _PyEval_RUNTIME_PERF_INIT
#include "pycore_faulthandler.h" // _faulthandler_runtime_state_INIT
#include "pycore_floatobject.h" // _py_float_format_unknown
#include "pycore_object.h" // _PyObject_HEAD_INIT
#include "pycore_obmalloc_init.h" // _obmalloc_global_state_INIT
#include "pycore_parser.h" // _parser_runtime_state_INIT
#include "pycore_pyhash.h" // pyhash_state_INIT
#include "pycore_pymem_init.h" // _pymem_allocators_standard_INIT
#include "pycore_runtime_init_generated.h" // _Py_bytes_characters_INIT
#include "pycore_signal.h" // _signals_RUNTIME_INIT
#include "pycore_tracemalloc.h" // _tracemalloc_runtime_state_INIT


extern PyTypeObject _PyExc_MemoryError;
Expand Down
3 changes: 3 additions & 0 deletions Include/internal/pycore_runtime_init_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Include/internal/pycore_signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif

#include "pycore_atomic.h" // _Py_atomic_address
#include <signal.h> // NSIG
#include "pycore_atomic.h" // _Py_atomic_address
#include <signal.h> // NSIG


// Restore signals that the interpreter has called SIG_IGN on to SIG_DFL.
Expand Down
Loading

0 comments on commit dff2218

Please sign in to comment.