Skip to content

Commit aedc7f0

Browse files
committed
pythongh-131238: Remove pycore_runtime.h from pycore_pystate.h
* 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
1 parent b8367e7 commit aedc7f0

16 files changed

+46
-28
lines changed

Include/internal/pycore_call.h

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

11+
#include "pycore_code.h" // EVAL_CALL_STAT_INC_IF_FUNCTION()
1112
#include "pycore_pystate.h" // _PyThreadState_GET()
1213
#include "pycore_stats.h"
1314

Include/internal/pycore_interp.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ extern "C" {
4242
#include "pycore_warnings.h" // struct _warnings_runtime_state
4343

4444

45-
4645
/* interpreter state */
4746

4847
#define _PyInterpreterState_WHENCE_NOTSET -1
@@ -134,6 +133,9 @@ PyAPI_FUNC(PyStatus) _PyInterpreterState_New(
134133
PyThreadState *tstate,
135134
PyInterpreterState **pinterp);
136135

136+
extern const PyConfig* _PyInterpreterState_GetConfig(
137+
PyInterpreterState *interp);
138+
137139
#ifdef __cplusplus
138140
}
139141
#endif

Include/internal/pycore_interp_structs.h

+3-9
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ extern "C" {
55
#endif
66

77
#include "pycore_ast_state.h" // struct ast_state
8-
#include "pycore_llist.h"
8+
#include "pycore_llist.h" // struct llist_node
99
#include "pycore_pymath.h" // _PY_SHORT_FLOAT_REPR
10-
#include "pycore_structs.h"
10+
#include "pycore_structs.h" // PyHamtObject
11+
#include "pycore_tstate.h" // _PyThreadStateImpl
1112
#include "pycore_typedefs.h" // _PyRuntimeState
1213

1314

@@ -246,13 +247,6 @@ struct _gc_runtime_state {
246247
#endif
247248
};
248249

249-
#ifdef Py_GIL_DISABLED
250-
struct _gc_thread_state {
251-
/* Thread-local allocation count. */
252-
Py_ssize_t alloc_count;
253-
};
254-
#endif
255-
256250
#include "pycore_gil.h"
257251

258252
/****** Thread state **************/

Include/internal/pycore_pystate.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

11-
#include "pycore_runtime_structs.h" // _PyRuntime
12-
#include "pycore_runtime.h" // _PyRuntimeState_GetFinalizing
13-
#include "pycore_tstate.h" // _PyThreadStateImpl
11+
#include "pycore_typedefs.h" // _PyRuntimeState
1412

15-
extern const PyConfig* _PyInterpreterState_GetConfig(PyInterpreterState *interp);
1613

1714
// Values for PyThreadState.state. A thread must be in the "attached" state
1815
// before calling most Python APIs. If the GIL is enabled, then "attached"

Include/internal/pycore_tstate.h

+7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ extern "C" {
1414
#include "pycore_qsbr.h" // struct qsbr
1515

1616

17+
#ifdef Py_GIL_DISABLED
18+
struct _gc_thread_state {
19+
/* Thread-local allocation count. */
20+
Py_ssize_t alloc_count;
21+
};
22+
#endif
23+
1724
// Every PyThreadState is actually allocated as a _PyThreadStateImpl. The
1825
// PyThreadState fields are exposed as part of the C API, although most fields
1926
// are intended to be private. The _PyThreadStateImpl fields not exposed.

Include/internal/pycore_tuple.h

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

11+
#include "pycore_structs.h" // _PyStackRef
12+
1113
extern void _PyTuple_MaybeUntrack(PyObject *);
1214
extern void _PyTuple_DebugMallocStats(FILE *out);
1315

Makefile.pre.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -1305,25 +1305,25 @@ PYTHON_HEADERS= \
13051305
$(srcdir)/Include/internal/pycore_sliceobject.h \
13061306
$(srcdir)/Include/internal/pycore_stats.h \
13071307
$(srcdir)/Include/internal/pycore_strhex.h \
1308+
$(srcdir)/Include/internal/pycore_stackref.h \
13081309
$(srcdir)/Include/internal/pycore_structs.h \
13091310
$(srcdir)/Include/internal/pycore_structseq.h \
13101311
$(srcdir)/Include/internal/pycore_symtable.h \
13111312
$(srcdir)/Include/internal/pycore_sysmodule.h \
1312-
$(srcdir)/Include/internal/pycore_stackref.h \
13131313
$(srcdir)/Include/internal/pycore_time.h \
13141314
$(srcdir)/Include/internal/pycore_token.h \
13151315
$(srcdir)/Include/internal/pycore_traceback.h \
13161316
$(srcdir)/Include/internal/pycore_tracemalloc.h \
13171317
$(srcdir)/Include/internal/pycore_tstate.h \
13181318
$(srcdir)/Include/internal/pycore_tuple.h \
13191319
$(srcdir)/Include/internal/pycore_typedefs.h \
1320-
$(srcdir)/Include/internal/pycore_uniqueid.h \
13211320
$(srcdir)/Include/internal/pycore_typeobject.h \
13221321
$(srcdir)/Include/internal/pycore_typevarobject.h \
13231322
$(srcdir)/Include/internal/pycore_ucnhash.h \
13241323
$(srcdir)/Include/internal/pycore_unicodeobject.h \
13251324
$(srcdir)/Include/internal/pycore_unicodeobject_generated.h \
13261325
$(srcdir)/Include/internal/pycore_unionobject.h \
1326+
$(srcdir)/Include/internal/pycore_uniqueid.h \
13271327
$(srcdir)/Include/internal/pycore_uop_ids.h \
13281328
$(srcdir)/Include/internal/pycore_uop_metadata.h \
13291329
$(srcdir)/Include/internal/pycore_warnings.h \

Modules/_testinternalcapi/test_critical_sections.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
*/
44

55
#include "parts.h"
6-
76
#include "pycore_critical_section.h"
87

8+
#ifdef MS_WINDOWS
9+
# include <windows.h> // Sleep()
10+
#endif
11+
912
#ifdef Py_GIL_DISABLED
1013
#define assert_nogil assert
1114
#define assert_gil(x)

Modules/_winapi.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@
3838
#include "pycore_moduleobject.h" // _PyModule_GetState()
3939
#include "pycore_pylifecycle.h" // _Py_IsInterpreterFinalizing()
4040
#include "pycore_pystate.h" // _PyInterpreterState_GET
41-
#include "pycore_unicodeobject.h" // _PyUnicode_WideCharString_Opt_Converter
42-
41+
#include "pycore_unicodeobject.h" // for Argument Clinic
4342

4443

4544
#ifndef WINDOWS_LEAN_AND_MEAN
46-
#define WINDOWS_LEAN_AND_MEAN
45+
# define WINDOWS_LEAN_AND_MEAN
4746
#endif
48-
#include "windows.h"
47+
#include <windows.h>
4948
#include <winioctl.h>
5049
#include <crtdbg.h>
5150
#include "winreparse.h"

PCbuild/pythoncore.vcxproj

+1
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@
259259
<ClInclude Include="..\Include\internal\pycore_initconfig.h" />
260260
<ClInclude Include="..\Include\internal\pycore_instruction_sequence.h" />
261261
<ClInclude Include="..\Include\internal\pycore_interp.h" />
262+
<ClInclude Include="..\Include\internal\pycore_interp_structs.h" />
262263
<ClInclude Include="..\Include\internal\pycore_intrinsics.h" />
263264
<ClInclude Include="..\Include\internal\pycore_jit.h" />
264265
<ClInclude Include="..\Include\internal\pycore_list.h" />

PCbuild/pythoncore.vcxproj.filters

+9
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,9 @@
699699
<ClInclude Include="..\Include\internal\pycore_interp.h">
700700
<Filter>Include\internal</Filter>
701701
</ClInclude>
702+
<ClInclude Include="..\Include\internal\pycore_interp_structs.h">
703+
<Filter>Include\internal</Filter>
704+
</ClInclude>
702705
<ClInclude Include="..\Include\internal\pycore_intrinsics.h">
703706
<Filter>Include\cpython</Filter>
704707
</ClInclude>
@@ -801,6 +804,9 @@
801804
<ClInclude Include="..\Include\internal\pycore_runtime_init_generated.h">
802805
<Filter>Include\internal</Filter>
803806
</ClInclude>
807+
<ClInclude Include="..\Include\internal\pycore_runtime_structs.h">
808+
<Filter>Include\internal</Filter>
809+
</ClInclude>
804810
<ClInclude Include="..\Include\internal\pycore_semaphore.h">
805811
<Filter>Include\internal</Filter>
806812
</ClInclude>
@@ -816,6 +822,9 @@
816822
<ClInclude Include="..\Include\internal\pycore_strhex.h">
817823
<Filter>Include\internal</Filter>
818824
</ClInclude>
825+
<ClInclude Include="..\Include\internal\pycore_structs.h">
826+
<Filter>Include\internal</Filter>
827+
</ClInclude>
819828
<ClInclude Include="..\Include\internal\pycore_sysmodule.h">
820829
<Filter>Include\internal</Filter>
821830
</ClInclude>

Parser/action_helpers.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#include <Python.h>
2+
#include "pycore_pystate.h" // _PyInterpreterState_GET()
3+
#include "pycore_runtime.h" // _PyRuntime
4+
#include "pycore_unicodeobject.h" // _PyUnicode_InternImmortal()
25

36
#include "pegen.h"
47
#include "string_parser.h" // _PyPegen_decode_string()
58

6-
#include "pycore_pystate.h" // _PyInterpreterState_GET()
7-
#include "pycore_unicodeobject.h" // _PyUnicode_InternImmortal()
8-
#include "pycore_unicodeobject.h" // _PyUnicode_InternImmortal()
9-
109

1110
void *
1211
_PyPegen_dummy_name(Parser *p, ...)

Parser/myreadline.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
#include "Python.h"
1313
#include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH
14-
#include "pycore_pystate.h" // _PyThreadState_GET()
14+
#include "pycore_interp.h" // _PyInterpreterState_GetConfig()
15+
#include "pycore_pystate.h" // _PyThreadState_GET()
1516
#ifdef MS_WINDOWS
1617
# ifndef WIN32_LEAN_AND_MEAN
1718
# define WIN32_LEAN_AND_MEAN

Python/bltinmodule.c

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "pycore_ceval.h" // _PyEval_Vector()
77
#include "pycore_compile.h" // _PyAST_Compile()
88
#include "pycore_fileutils.h" // _PyFile_Flush
9+
#include "pycore_interp.h" // _PyInterpreterState_GetConfig()
910
#include "pycore_long.h" // _PyLong_CompactValue
1011
#include "pycore_modsupport.h" // _PyArg_NoKwnames()
1112
#include "pycore_object.h" // _Py_AddToAllObjects()

Python/dynload_win.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44
#include "Python.h"
55
#include "pycore_fileutils.h" // _Py_add_relfile()
6+
#include "pycore_importdl.h" // dl_funcptr
7+
#include "pycore_interp.h" // _PyInterpreterState_GetConfig()
68
#include "pycore_pystate.h" // _PyInterpreterState_GET()
79

8-
#include "pycore_importdl.h" // dl_funcptr
910
#include "patchlevel.h" // PY_MAJOR_VERSION
1011
#include <windows.h>
1112

Python/pytime.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#include "Python.h"
22
#include "pycore_initconfig.h" // _PyStatus_ERR
3-
#include "pycore_time.h" // PyTime_t
43
#include "pycore_pystate.h" // _Py_AssertHoldsTstate()
4+
#include "pycore_runtime.h" // _PyRuntime
5+
#include "pycore_time.h" // PyTime_t
56

67
#include <time.h> // gmtime_r()
78
#ifdef HAVE_SYS_TIME_H

0 commit comments

Comments
 (0)