]> granicus.if.org Git - python/commitdiff
bpo-38353: Cleanup includes in the internal C API (GH-16548)
authorVictor Stinner <vstinner@redhat.com>
Wed, 2 Oct 2019 21:51:20 +0000 (23:51 +0200)
committerGitHub <noreply@github.com>
Wed, 2 Oct 2019 21:51:20 +0000 (23:51 +0200)
Use forward declaration of types to avoid includes in the internal C
API. Add also comment to justify other includes.

16 files changed:
Include/internal/pycore_atomic.h
Include/internal/pycore_ceval.h
Include/internal/pycore_context.h
Include/internal/pycore_gil.h
Include/internal/pycore_initconfig.h
Include/internal/pycore_object.h
Include/internal/pycore_pylifecycle.h
Include/internal/pycore_pymem.h
Include/internal/pycore_pystate.h
Include/internal/pycore_traceback.h
Include/internal/pycore_tupleobject.h
Include/internal/pycore_warnings.h
Modules/main.c
Objects/unicodeobject.c
PC/getpathp.c
Python/import.c

index 336bc3fec27e5d9f85df21418597a9e34c15802c..1d5c5621677eb3706e9fe09010dcf7ee1f9a701f 100644 (file)
@@ -8,8 +8,7 @@ extern "C" {
 #  error "this header requires Py_BUILD_CORE define"
 #endif
 
-#include "dynamic_annotations.h"
-
+#include "dynamic_annotations.h"   /* _Py_ANNOTATE_MEMORY_ORDER */
 #include "pyconfig.h"
 
 #if defined(HAVE_STD_ATOMIC)
index 30cd6c9e09e44da9174a6ba0ef240ba3f0f76ccf..65537b1bae4a19ad1f25ad90961c9d89027a808c 100644 (file)
@@ -8,9 +8,9 @@ extern "C" {
 #  error "this header requires Py_BUILD_CORE define"
 #endif
 
-#include "pycore_atomic.h"
-#include "pycore_pystate.h"
-#include "pythread.h"
+/* Forward declarations */
+typedef struct pyruntimestate _PyRuntimeState;
+struct _ceval_runtime_state;
 
 PyAPI_FUNC(void) _Py_FinishPendingCalls(_PyRuntimeState *runtime);
 PyAPI_FUNC(void) _PyEval_Initialize(struct _ceval_runtime_state *);
index 5e1ba0d0393f4a690e0e2857ea13222fe777028d..f665ad5c115b07ac839917db3271ade9b4663475 100644 (file)
@@ -5,7 +5,7 @@
 #  error "this header requires Py_BUILD_CORE define"
 #endif
 
-#include "pycore_hamt.h"
+#include "pycore_hamt.h"   /* PyHamtObject */
 
 struct _pycontextobject {
     PyObject_HEAD
index 7de316397b15e8ac9bbbc5ddb280bff19519f786..8ebad37b686cd4c9cdfd4236b2bd9387497f489e 100644 (file)
@@ -8,8 +8,8 @@ extern "C" {
 #  error "this header requires Py_BUILD_CORE define"
 #endif
 
-#include "pycore_condvar.h"
-#include "pycore_atomic.h"
+#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!
index 40831c44b2fa674be62fe60eafbe16b842eb1f34..4a1a111af68347aa76eeda51a84cebdb5a143019 100644 (file)
@@ -8,7 +8,8 @@ extern "C" {
 #  error "this header requires Py_BUILD_CORE define"
 #endif
 
-#include "pycore_pystate.h"   /* _PyRuntimeState */
+/* Forward declaration */
+typedef struct pyruntimestate _PyRuntimeState;
 
 /* --- PyStatus ----------------------------------------------- */
 
@@ -60,7 +61,7 @@ PyAPI_FUNC(PyObject*) _PyWideStringList_AsList(const PyWideStringList *list);
 
 /* --- _PyArgv ---------------------------------------------------- */
 
-typedef struct {
+typedef struct _PyArgv {
     Py_ssize_t argc;
     int use_bytes_argv;
     char * const *bytes_argv;
index 81548f819198e375839ceb9ee060ffb5f5170ff2..500078d4a1dab12aca008bf78c7e27446b980032 100644 (file)
@@ -8,7 +8,7 @@ extern "C" {
 #  error "this header requires Py_BUILD_CORE define"
 #endif
 
-#include "pycore_pystate.h"   /* _PyRuntime */
+#include "pycore_pystate.h"   /* _PyRuntime.gc */
 
 PyAPI_FUNC(int) _PyType_CheckConsistency(PyTypeObject *type);
 PyAPI_FUNC(int) _PyUnicode_CheckConsistency(PyObject *op, int check_content);
index b0a98f5d25971f81699f272148a6ee38775a1881..d6f9ecc8b4872d6612102b2c5d96f01d72d344ca 100644 (file)
@@ -8,8 +8,9 @@ extern "C" {
 #  error "this header requires Py_BUILD_CORE define"
 #endif
 
-#include "pycore_initconfig.h"   /* _PyArgv */
-#include "pycore_pystate.h"      /* _PyRuntimeState */
+/* Forward declarations */
+typedef struct _PyArgv _PyArgv;
+typedef struct pyruntimestate _PyRuntimeState;
 
 /* True if the main interpreter thread exited due to an unhandled
  * KeyboardInterrupt exception, suggesting the user pressed ^C. */
index 22677d373855ca9dfa18d0710cdeba4216a9c843..cba4b235c3aaac5c50e863e75dc79e36a9b41e56 100644 (file)
@@ -8,8 +8,7 @@ extern "C" {
 #  error "this header requires Py_BUILD_CORE define"
 #endif
 
-#include "objimpl.h"
-#include "pymem.h"
+#include "pymem.h"   /* PyMemAllocatorName */
 
 
 /* GC runtime state */
index 8e5a022b4a09aade68fb3c1fe16d24118dd80575..91003dbead0545da04258f567ad00e443b690c08 100644 (file)
@@ -8,16 +8,9 @@ extern "C" {
 #  error "this header requires Py_BUILD_CORE define"
 #endif
 
-#include "cpython/initconfig.h"
-#include "fileobject.h"
-#include "pystate.h"
-#include "pythread.h"
-#include "sysmodule.h"
-
-#include "pycore_gil.h"   /* _gil_runtime_state  */
-#include "pycore_pathconfig.h"
-#include "pycore_pymem.h"
-#include "pycore_warnings.h"
+#include "pycore_gil.h"       /* struct _gil_runtime_state  */
+#include "pycore_pymem.h"     /* struct _gc_runtime_state */
+#include "pycore_warnings.h"  /* struct _warnings_runtime_state */
 
 
 /* ceval state */
index bf4d7fe5851f96fa58170068ba23955926fcc2a4..8e58184c87ec9d79de3035ed343b87ed91657a81 100644 (file)
@@ -8,7 +8,8 @@ extern "C" {
 #  error "this header requires Py_BUILD_CORE define"
 #endif
 
-#include "pystate.h"   /* PyInterpreterState */
+/* Forward declaration */
+typedef struct _is PyInterpreterState;
 
 /* Write the Python traceback into the file 'fd'. For example:
 
index 9fcfc5c6ec71960ca97387469b7c001ec4c89293..f95f16c0ed02f2d201ea5809bbb604c048e03778 100644 (file)
@@ -8,7 +8,7 @@ extern "C" {
 #  error "this header requires Py_BUILD_CORE define"
 #endif
 
-#include "tupleobject.h"
+#include "tupleobject.h"   /* _PyTuple_CAST() */
 
 #define _PyTuple_ITEMS(op) (_PyTuple_CAST(op)->ob_item)
 PyAPI_FUNC(PyObject *) _PyTuple_FromArray(PyObject *const *, Py_ssize_t);
index 73e5350aff1451e01accdab1d63559d58276f2b7..9a72526279b872af4771da5aec47560eee6db459 100644 (file)
@@ -8,8 +8,6 @@ extern "C" {
 #  error "this header requires Py_BUILD_CORE define"
 #endif
 
-#include "object.h"
-
 struct _warnings_runtime_state {
     /* Both 'filters' and 'onceregistry' can be set in warnings.py;
        get_warnings_attr() will reset these variables accordingly. */
index 929417fe775f28cc2d0ad857d4643c07da71d6aa..0288f17324d804932dc9fdcc3d516bd3fa0092aa 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "Python.h"
 #include "pycore_initconfig.h"
+#include "pycore_pathconfig.h"
 #include "pycore_pylifecycle.h"
 #include "pycore_pymem.h"
 #include "pycore_pystate.h"
index 55b25191817362af6935e33d4c69f0af730746c7..0526225ca3e440f09f9a637da18149181e0058fc 100644 (file)
@@ -40,9 +40,10 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
 #define PY_SSIZE_T_CLEAN
 #include "Python.h"
-#include "pycore_initconfig.h"
 #include "pycore_fileutils.h"
+#include "pycore_initconfig.h"
 #include "pycore_object.h"
+#include "pycore_pathconfig.h"
 #include "pycore_pylifecycle.h"
 #include "pycore_pystate.h"
 #include "ucnhash.h"
index 04f24d986f667c0c7d73d5d8b13110dcadc5a295..b17c002f25c8efca46e026f856860cbc72e0b2a6 100644 (file)
@@ -80,7 +80,8 @@
 
 
 #include "Python.h"
-#include "pycore_initconfig.h"
+#include "pycore_initconfig.h"   /* PyStatus */
+#include "pycore_pathconfig.h"   /* _PyPathConfig */
 #include "pycore_pystate.h"
 #include "osdefs.h"
 #include <wchar.h>
index 6eb079d2a4715469e66c680b8619f436eefff60b..cbd0fa86fb58f4223262e520c47aca2c1ba9098f 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "Python-ast.h"
 #undef Yield   /* undefine macro conflicting with <winbase.h> */
+#include "pycore_initconfig.h"
 #include "pycore_pyerrors.h"
 #include "pycore_pyhash.h"
 #include "pycore_pylifecycle.h"