https://github.com/python/cpython/commit/4b540313238de9d53bd9d9866eb481e954ad508f commit: 4b540313238de9d53bd9d9866eb481e954ad508f branch: main author: Victor Stinner <vstin...@python.org> committer: vstinner <vstin...@python.org> date: 2025-03-19T17:33:24+01:00 summary:
gh-131238: Remove pycore_runtime.h from pycore_pystate.h (#131356) * Remove includes from pycore_pystate.h: * pycore_runtime_structs.h * pycore_runtime.h * pycore_tstate.h * pycore_interp.h * Reorganize internal headers. Move _gc_thread_state from pycore_interp_structs.h to pycore_tstate.h. * Add 3 new header files to PCbuild/pythoncore.vcxproj. files: M Include/internal/pycore_call.h M Include/internal/pycore_interp.h M Include/internal/pycore_interp_structs.h M Include/internal/pycore_pystate.h M Include/internal/pycore_tstate.h M Include/internal/pycore_tuple.h M Makefile.pre.in M Modules/_testinternalcapi/test_critical_sections.c M Modules/_winapi.c M PCbuild/pythoncore.vcxproj M PCbuild/pythoncore.vcxproj.filters M Parser/action_helpers.c M Parser/myreadline.c M Python/bltinmodule.c M Python/dynload_win.c M Python/pytime.c diff --git a/Include/internal/pycore_call.h b/Include/internal/pycore_call.h index 38d005c039f7a3..32ac3d17f22077 100644 --- a/Include/internal/pycore_call.h +++ b/Include/internal/pycore_call.h @@ -8,6 +8,7 @@ extern "C" { # error "this header requires Py_BUILD_CORE define" #endif +#include "pycore_code.h" // EVAL_CALL_STAT_INC_IF_FUNCTION() #include "pycore_pystate.h" // _PyThreadState_GET() #include "pycore_stats.h" diff --git a/Include/internal/pycore_interp.h b/Include/internal/pycore_interp.h index a5502629769e8e..740b0c7ec46093 100644 --- a/Include/internal/pycore_interp.h +++ b/Include/internal/pycore_interp.h @@ -42,7 +42,6 @@ extern "C" { #include "pycore_warnings.h" // struct _warnings_runtime_state - /* interpreter state */ #define _PyInterpreterState_WHENCE_NOTSET -1 @@ -134,6 +133,9 @@ PyAPI_FUNC(PyStatus) _PyInterpreterState_New( PyThreadState *tstate, PyInterpreterState **pinterp); +extern const PyConfig* _PyInterpreterState_GetConfig( + PyInterpreterState *interp); + #ifdef __cplusplus } #endif diff --git a/Include/internal/pycore_interp_structs.h b/Include/internal/pycore_interp_structs.h index bdeb7f0199853b..de1b41da369161 100644 --- a/Include/internal/pycore_interp_structs.h +++ b/Include/internal/pycore_interp_structs.h @@ -5,9 +5,10 @@ extern "C" { #endif #include "pycore_ast_state.h" // struct ast_state -#include "pycore_llist.h" +#include "pycore_llist.h" // struct llist_node #include "pycore_pymath.h" // _PY_SHORT_FLOAT_REPR -#include "pycore_structs.h" +#include "pycore_structs.h" // PyHamtObject +#include "pycore_tstate.h" // _PyThreadStateImpl #include "pycore_typedefs.h" // _PyRuntimeState @@ -246,13 +247,6 @@ struct _gc_runtime_state { #endif }; -#ifdef Py_GIL_DISABLED -struct _gc_thread_state { - /* Thread-local allocation count. */ - Py_ssize_t alloc_count; -}; -#endif - #include "pycore_gil.h" /****** Thread state **************/ diff --git a/Include/internal/pycore_pystate.h b/Include/internal/pycore_pystate.h index 2fad2c64b6f5b5..864e0f5d1db289 100644 --- a/Include/internal/pycore_pystate.h +++ b/Include/internal/pycore_pystate.h @@ -8,11 +8,8 @@ extern "C" { # error "this header requires Py_BUILD_CORE define" #endif -#include "pycore_runtime_structs.h" // _PyRuntime -#include "pycore_runtime.h" // _PyRuntimeState_GetFinalizing -#include "pycore_tstate.h" // _PyThreadStateImpl +#include "pycore_typedefs.h" // _PyRuntimeState -extern const PyConfig* _PyInterpreterState_GetConfig(PyInterpreterState *interp); // Values for PyThreadState.state. A thread must be in the "attached" state // before calling most Python APIs. If the GIL is enabled, then "attached" diff --git a/Include/internal/pycore_tstate.h b/Include/internal/pycore_tstate.h index 6f50bb2f26307a..b73cd6828b5199 100644 --- a/Include/internal/pycore_tstate.h +++ b/Include/internal/pycore_tstate.h @@ -14,6 +14,13 @@ extern "C" { #include "pycore_qsbr.h" // struct qsbr +#ifdef Py_GIL_DISABLED +struct _gc_thread_state { + /* Thread-local allocation count. */ + Py_ssize_t alloc_count; +}; +#endif + // Every PyThreadState is actually allocated as a _PyThreadStateImpl. The // PyThreadState fields are exposed as part of the C API, although most fields // are intended to be private. The _PyThreadStateImpl fields not exposed. diff --git a/Include/internal/pycore_tuple.h b/Include/internal/pycore_tuple.h index dc68d6648b9ec8..da6754ff7dbd4f 100644 --- a/Include/internal/pycore_tuple.h +++ b/Include/internal/pycore_tuple.h @@ -8,6 +8,8 @@ extern "C" { # error "this header requires Py_BUILD_CORE define" #endif +#include "pycore_structs.h" // _PyStackRef + extern void _PyTuple_MaybeUntrack(PyObject *); extern void _PyTuple_DebugMallocStats(FILE *out); diff --git a/Makefile.pre.in b/Makefile.pre.in index 076312807f3cc7..db84eb61a780a7 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -1305,11 +1305,11 @@ PYTHON_HEADERS= \ $(srcdir)/Include/internal/pycore_sliceobject.h \ $(srcdir)/Include/internal/pycore_stats.h \ $(srcdir)/Include/internal/pycore_strhex.h \ + $(srcdir)/Include/internal/pycore_stackref.h \ $(srcdir)/Include/internal/pycore_structs.h \ $(srcdir)/Include/internal/pycore_structseq.h \ $(srcdir)/Include/internal/pycore_symtable.h \ $(srcdir)/Include/internal/pycore_sysmodule.h \ - $(srcdir)/Include/internal/pycore_stackref.h \ $(srcdir)/Include/internal/pycore_time.h \ $(srcdir)/Include/internal/pycore_token.h \ $(srcdir)/Include/internal/pycore_traceback.h \ @@ -1317,13 +1317,13 @@ PYTHON_HEADERS= \ $(srcdir)/Include/internal/pycore_tstate.h \ $(srcdir)/Include/internal/pycore_tuple.h \ $(srcdir)/Include/internal/pycore_typedefs.h \ - $(srcdir)/Include/internal/pycore_uniqueid.h \ $(srcdir)/Include/internal/pycore_typeobject.h \ $(srcdir)/Include/internal/pycore_typevarobject.h \ $(srcdir)/Include/internal/pycore_ucnhash.h \ $(srcdir)/Include/internal/pycore_unicodeobject.h \ $(srcdir)/Include/internal/pycore_unicodeobject_generated.h \ $(srcdir)/Include/internal/pycore_unionobject.h \ + $(srcdir)/Include/internal/pycore_uniqueid.h \ $(srcdir)/Include/internal/pycore_uop_ids.h \ $(srcdir)/Include/internal/pycore_uop_metadata.h \ $(srcdir)/Include/internal/pycore_warnings.h \ diff --git a/Modules/_testinternalcapi/test_critical_sections.c b/Modules/_testinternalcapi/test_critical_sections.c index 1df960f9881f70..e0ba37abcdd332 100644 --- a/Modules/_testinternalcapi/test_critical_sections.c +++ b/Modules/_testinternalcapi/test_critical_sections.c @@ -3,9 +3,12 @@ */ #include "parts.h" - #include "pycore_critical_section.h" +#ifdef MS_WINDOWS +# include <windows.h> // Sleep() +#endif + #ifdef Py_GIL_DISABLED #define assert_nogil assert #define assert_gil(x) diff --git a/Modules/_winapi.c b/Modules/_winapi.c index fd518212717c40..9aff28173a5042 100644 --- a/Modules/_winapi.c +++ b/Modules/_winapi.c @@ -38,14 +38,13 @@ #include "pycore_moduleobject.h" // _PyModule_GetState() #include "pycore_pylifecycle.h" // _Py_IsInterpreterFinalizing() #include "pycore_pystate.h" // _PyInterpreterState_GET -#include "pycore_unicodeobject.h" // _PyUnicode_WideCharString_Opt_Converter - +#include "pycore_unicodeobject.h" // for Argument Clinic #ifndef WINDOWS_LEAN_AND_MEAN -#define WINDOWS_LEAN_AND_MEAN +# define WINDOWS_LEAN_AND_MEAN #endif -#include "windows.h" +#include <windows.h> #include <winioctl.h> #include <crtdbg.h> #include "winreparse.h" diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj index 2a245e931fc9b8..d2c9664b08a755 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -259,6 +259,7 @@ <ClInclude Include="..\Include\internal\pycore_initconfig.h" /> <ClInclude Include="..\Include\internal\pycore_instruction_sequence.h" /> <ClInclude Include="..\Include\internal\pycore_interp.h" /> + <ClInclude Include="..\Include\internal\pycore_interp_structs.h" /> <ClInclude Include="..\Include\internal\pycore_intrinsics.h" /> <ClInclude Include="..\Include\internal\pycore_jit.h" /> <ClInclude Include="..\Include\internal\pycore_list.h" /> diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters index 28cd3ec507ac33..816bde53ffbc8a 100644 --- a/PCbuild/pythoncore.vcxproj.filters +++ b/PCbuild/pythoncore.vcxproj.filters @@ -699,6 +699,9 @@ <ClInclude Include="..\Include\internal\pycore_interp.h"> <Filter>Include\internal</Filter> </ClInclude> + <ClInclude Include="..\Include\internal\pycore_interp_structs.h"> + <Filter>Include\internal</Filter> + </ClInclude> <ClInclude Include="..\Include\internal\pycore_intrinsics.h"> <Filter>Include\cpython</Filter> </ClInclude> @@ -801,6 +804,9 @@ <ClInclude Include="..\Include\internal\pycore_runtime_init_generated.h"> <Filter>Include\internal</Filter> </ClInclude> + <ClInclude Include="..\Include\internal\pycore_runtime_structs.h"> + <Filter>Include\internal</Filter> + </ClInclude> <ClInclude Include="..\Include\internal\pycore_semaphore.h"> <Filter>Include\internal</Filter> </ClInclude> @@ -816,6 +822,9 @@ <ClInclude Include="..\Include\internal\pycore_strhex.h"> <Filter>Include\internal</Filter> </ClInclude> + <ClInclude Include="..\Include\internal\pycore_structs.h"> + <Filter>Include\internal</Filter> + </ClInclude> <ClInclude Include="..\Include\internal\pycore_sysmodule.h"> <Filter>Include\internal</Filter> </ClInclude> diff --git a/Parser/action_helpers.c b/Parser/action_helpers.c index 0baec5b93afd7a..b72a69c242328a 100644 --- a/Parser/action_helpers.c +++ b/Parser/action_helpers.c @@ -1,12 +1,11 @@ #include <Python.h> +#include "pycore_pystate.h" // _PyInterpreterState_GET() +#include "pycore_runtime.h" // _PyRuntime +#include "pycore_unicodeobject.h" // _PyUnicode_InternImmortal() #include "pegen.h" #include "string_parser.h" // _PyPegen_decode_string() -#include "pycore_pystate.h" // _PyInterpreterState_GET() -#include "pycore_unicodeobject.h" // _PyUnicode_InternImmortal() -#include "pycore_unicodeobject.h" // _PyUnicode_InternImmortal() - void * _PyPegen_dummy_name(Parser *p, ...) diff --git a/Parser/myreadline.c b/Parser/myreadline.c index 74c44ff77717f5..99c5760cd51442 100644 --- a/Parser/myreadline.c +++ b/Parser/myreadline.c @@ -11,7 +11,8 @@ #include "Python.h" #include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH -#include "pycore_pystate.h" // _PyThreadState_GET() +#include "pycore_interp.h" // _PyInterpreterState_GetConfig() +#include "pycore_pystate.h" // _PyThreadState_GET() #ifdef MS_WINDOWS # ifndef WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 3174105fbe32e2..1b87e6e0b6c7e4 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -6,6 +6,7 @@ #include "pycore_ceval.h" // _PyEval_Vector() #include "pycore_compile.h" // _PyAST_Compile() #include "pycore_fileutils.h" // _PyFile_Flush +#include "pycore_interp.h" // _PyInterpreterState_GetConfig() #include "pycore_long.h" // _PyLong_CompactValue #include "pycore_modsupport.h" // _PyArg_NoKwnames() #include "pycore_object.h" // _Py_AddToAllObjects() diff --git a/Python/dynload_win.c b/Python/dynload_win.c index a0ac31c80a5f6e..6324063401e51f 100644 --- a/Python/dynload_win.c +++ b/Python/dynload_win.c @@ -3,9 +3,10 @@ #include "Python.h" #include "pycore_fileutils.h" // _Py_add_relfile() +#include "pycore_importdl.h" // dl_funcptr +#include "pycore_interp.h" // _PyInterpreterState_GetConfig() #include "pycore_pystate.h" // _PyInterpreterState_GET() -#include "pycore_importdl.h" // dl_funcptr #include "patchlevel.h" // PY_MAJOR_VERSION #include <windows.h> diff --git a/Python/pytime.c b/Python/pytime.c index 23e1608633940e..67cf6437264490 100644 --- a/Python/pytime.c +++ b/Python/pytime.c @@ -1,7 +1,8 @@ #include "Python.h" #include "pycore_initconfig.h" // _PyStatus_ERR -#include "pycore_time.h" // PyTime_t #include "pycore_pystate.h" // _Py_AssertHoldsTstate() +#include "pycore_runtime.h" // _PyRuntime +#include "pycore_time.h" // PyTime_t #include <time.h> // gmtime_r() #ifdef HAVE_SYS_TIME_H _______________________________________________ Python-checkins mailing list -- python-checkins@python.org To unsubscribe send an email to python-checkins-le...@python.org https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: arch...@mail-archive.com