Skip to content

Commit 1ff810d

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 pycore_typeobject.h internal header. * Add 3 new header files to PCbuild/pythoncore.vcxproj
1 parent 978e37b commit 1ff810d

9 files changed

+51
-15
lines changed

Include/internal/pycore_call.h

Lines changed: 1 addition & 0 deletions
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

1314
/* Suggested size (number of positional arguments) for arrays of PyObject*

Include/internal/pycore_interp_structs.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
extern "C" {
55
#endif
66

7-
#include "pycore_structs.h"
8-
#include "pycore_pymath.h" // _PY_SHORT_FLOAT_REPR
9-
#include "pycore_llist.h"
107
#include "pycore_ast_state.h" // struct ast_state
8+
#include "pycore_llist.h" // struct llist_node
9+
#include "pycore_pymath.h" // _PY_SHORT_FLOAT_REPR
10+
#include "pycore_structs.h" // PyHamtObject
11+
#include "pycore_tstate.h" // _PyThreadStateImpl
1112

1213

1314
/* This file contains the struct definitions for interpreter state
@@ -245,13 +246,6 @@ struct _gc_runtime_state {
245246
#endif
246247
};
247248

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

257251
/****** Thread state **************/

Include/internal/pycore_pystate.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +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
14-
#include "pycore_interp.h" // _PyInterpreterState_GetConfig
11+
#include "pycore_typedefs.h" // _PyRuntimeState
12+
1513

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

Include/internal/pycore_tstate.h

Lines changed: 7 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Include/internal/pycore_typedefs.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef Py_INTERNAL_TYPEDEFS_H
2+
#define Py_INTERNAL_TYPEDEFS_H
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif
6+
7+
#ifndef Py_BUILD_CORE
8+
# error "this header requires Py_BUILD_CORE define"
9+
#endif
10+
11+
typedef struct pyruntimestate _PyRuntimeState;
12+
13+
14+
#ifdef __cplusplus
15+
}
16+
#endif
17+
#endif /* !Py_INTERNAL_TYPEDEFS_H */

Makefile.pre.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1315,13 +1315,14 @@ PYTHON_HEADERS= \
13151315
$(srcdir)/Include/internal/pycore_tracemalloc.h \
13161316
$(srcdir)/Include/internal/pycore_tstate.h \
13171317
$(srcdir)/Include/internal/pycore_tuple.h \
1318-
$(srcdir)/Include/internal/pycore_uniqueid.h \
1318+
$(srcdir)/Include/internal/pycore_typedefs.h \
13191319
$(srcdir)/Include/internal/pycore_typeobject.h \
13201320
$(srcdir)/Include/internal/pycore_typevarobject.h \
13211321
$(srcdir)/Include/internal/pycore_ucnhash.h \
13221322
$(srcdir)/Include/internal/pycore_unicodeobject.h \
13231323
$(srcdir)/Include/internal/pycore_unicodeobject_generated.h \
13241324
$(srcdir)/Include/internal/pycore_unionobject.h \
1325+
$(srcdir)/Include/internal/pycore_uniqueid.h \
13251326
$(srcdir)/Include/internal/pycore_uop_ids.h \
13261327
$(srcdir)/Include/internal/pycore_uop_metadata.h \
13271328
$(srcdir)/Include/internal/pycore_warnings.h \

PCbuild/pythoncore.vcxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@
258258
<ClInclude Include="..\Include\internal\pycore_initconfig.h" />
259259
<ClInclude Include="..\Include\internal\pycore_instruction_sequence.h" />
260260
<ClInclude Include="..\Include\internal\pycore_interp.h" />
261+
<ClInclude Include="..\Include\internal\pycore_interp_structs.h" />
261262
<ClInclude Include="..\Include\internal\pycore_intrinsics.h" />
262263
<ClInclude Include="..\Include\internal\pycore_jit.h" />
263264
<ClInclude Include="..\Include\internal\pycore_list.h" />
@@ -292,11 +293,13 @@
292293
<ClInclude Include="..\Include\internal\pycore_runtime.h" />
293294
<ClInclude Include="..\Include\internal\pycore_runtime_init.h" />
294295
<ClInclude Include="..\Include\internal\pycore_runtime_init_generated.h" />
296+
<ClInclude Include="..\Include\internal\pycore_runtime_structs.h" />
295297
<ClInclude Include="..\Include\internal\pycore_semaphore.h" />
296298
<ClInclude Include="..\Include\internal\pycore_setobject.h" />
297299
<ClInclude Include="..\Include\internal\pycore_signal.h" />
298300
<ClInclude Include="..\Include\internal\pycore_sliceobject.h" />
299301
<ClInclude Include="..\Include\internal\pycore_strhex.h" />
302+
<ClInclude Include="..\Include\internal\pycore_structs.h" />
300303
<ClInclude Include="..\Include\internal\pycore_structseq.h" />
301304
<ClInclude Include="..\Include\internal\pycore_sysmodule.h" />
302305
<ClInclude Include="..\Include\internal\pycore_symtable.h" />
@@ -307,6 +310,7 @@
307310
<ClInclude Include="..\Include\internal\pycore_tracemalloc.h" />
308311
<ClInclude Include="..\Include\internal\pycore_tstate.h" />
309312
<ClInclude Include="..\Include\internal\pycore_tuple.h" />
313+
<ClInclude Include="..\Include\internal\pycore_typedefs.h" />
310314
<ClInclude Include="..\Include\internal\pycore_typeobject.h" />
311315
<ClInclude Include="..\Include\internal\pycore_typevarobject.h" />
312316
<ClInclude Include="..\Include\internal\pycore_ucnhash.h" />

PCbuild/pythoncore.vcxproj.filters

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,9 @@
690690
<ClInclude Include="..\Include\internal\pycore_interp.h">
691691
<Filter>Include\internal</Filter>
692692
</ClInclude>
693+
<ClInclude Include="..\Include\internal\pycore_interp_structs.h">
694+
<Filter>Include\internal</Filter>
695+
</ClInclude>
693696
<ClInclude Include="..\Include\internal\pycore_intrinsics.h">
694697
<Filter>Include\cpython</Filter>
695698
</ClInclude>
@@ -792,6 +795,9 @@
792795
<ClInclude Include="..\Include\internal\pycore_runtime_init_generated.h">
793796
<Filter>Include\internal</Filter>
794797
</ClInclude>
798+
<ClInclude Include="..\Include\internal\pycore_runtime_structs.h">
799+
<Filter>Include\internal</Filter>
800+
</ClInclude>
795801
<ClInclude Include="..\Include\internal\pycore_semaphore.h">
796802
<Filter>Include\internal</Filter>
797803
</ClInclude>
@@ -807,6 +813,9 @@
807813
<ClInclude Include="..\Include\internal\pycore_strhex.h">
808814
<Filter>Include\internal</Filter>
809815
</ClInclude>
816+
<ClInclude Include="..\Include\internal\pycore_structs.h">
817+
<Filter>Include\internal</Filter>
818+
</ClInclude>
810819
<ClInclude Include="..\Include\internal\pycore_sysmodule.h">
811820
<Filter>Include\internal</Filter>
812821
</ClInclude>
@@ -834,6 +843,9 @@
834843
<ClInclude Include="..\Include\internal\pycore_tuple.h">
835844
<Filter>Include\internal</Filter>
836845
</ClInclude>
846+
<ClInclude Include="..\Include\internal\pycore_typedefs.h">
847+
<Filter>Include\internal</Filter>
848+
</ClInclude>
837849
<ClInclude Include="..\Include\internal\pycore_typeobject.h">
838850
<Filter>Include\internal</Filter>
839851
</ClInclude>

0 commit comments

Comments
 (0)