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.
This commit is contained in:
Victor Stinner 2025-03-19 17:33:24 +01:00 committed by GitHub
parent 0a54bd6dd7
commit 4b54031323
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 46 additions and 28 deletions

View file

@ -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"

View file

@ -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

View file

@ -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 **************/

View file

@ -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"

View file

@ -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.

View file

@ -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);

View file

@ -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 \

View file

@ -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)

View file

@ -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"

View file

@ -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" />

View file

@ -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>

View file

@ -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, ...)

View file

@ -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

View file

@ -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()

View file

@ -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>

View file

@ -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