Skip to content

Commit 22b8497

Browse files
committed
gh-131238: Move _Py_VISIT_STACKREF() to pycore_stackref.h
* Move _Py_VISIT_STACKREF() from pycore_gc.h to pycore_stackref.h. * Remove pycore_interpframe.h include from pycore_genobject.h. * Remove now useless includes from C files. * Add pycore_interpframe_structs.h to Makefile.pre.in and pythoncore.vcxproj.
1 parent 4cc82ff commit 22b8497

11 files changed

+40
-35
lines changed

Include/internal/pycore_gc.h

-10
Original file line numberDiff line numberDiff line change
@@ -352,16 +352,6 @@ union _PyStackRef;
352352
extern int _PyGC_VisitFrameStack(_PyInterpreterFrame *frame, visitproc visit, void *arg);
353353
extern int _PyGC_VisitStackRef(union _PyStackRef *ref, visitproc visit, void *arg);
354354

355-
// Like Py_VISIT but for _PyStackRef fields
356-
#define _Py_VISIT_STACKREF(ref) \
357-
do { \
358-
if (!PyStackRef_IsNull(ref)) { \
359-
int vret = _PyGC_VisitStackRef(&(ref), visit, arg); \
360-
if (vret) \
361-
return vret; \
362-
} \
363-
} while (0)
364-
365355
#ifdef Py_GIL_DISABLED
366356
extern void _PyGC_VisitObjectsWorldStopped(PyInterpreterState *interp,
367357
gcvisitobjects_t callback, void *arg);

Include/internal/pycore_genobject.h

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

11-
#include "pycore_interpframe.h" // _PyInterpreterFrame
1211
#include "pycore_interpframe_structs.h" // _PyGenObject
1312

13+
#include <stddef.h> // offsetof()
14+
1415

1516
static inline
1617
PyGenObject *_PyGen_GetGeneratorFromFrame(_PyInterpreterFrame *frame)

Include/internal/pycore_stackref.h

+10
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,16 @@ _Py_TryIncrefCompareStackRef(PyObject **src, PyObject *op, _PyStackRef *out)
658658

659659
#endif
660660

661+
// Like Py_VISIT but for _PyStackRef fields
662+
#define _Py_VISIT_STACKREF(ref) \
663+
do { \
664+
if (!PyStackRef_IsNull(ref)) { \
665+
int vret = _PyGC_VisitStackRef(&(ref), visit, arg); \
666+
if (vret) \
667+
return vret; \
668+
} \
669+
} while (0)
670+
661671
#ifdef __cplusplus
662672
}
663673
#endif

Makefile.pre.in

+1
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,7 @@ PYTHON_HEADERS= \
12571257
$(srcdir)/Include/internal/pycore_interp.h \
12581258
$(srcdir)/Include/internal/pycore_interp_structs.h \
12591259
$(srcdir)/Include/internal/pycore_interpframe.h \
1260+
$(srcdir)/Include/internal/pycore_interpframe_structs.h \
12601261
$(srcdir)/Include/internal/pycore_intrinsics.h \
12611262
$(srcdir)/Include/internal/pycore_jit.h \
12621263
$(srcdir)/Include/internal/pycore_list.h \

Objects/frameobject.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
/* Frame object implementation */
22

33
#include "Python.h"
4+
#include "pycore_cell.h" // PyCell_GetRef()
45
#include "pycore_ceval.h" // _PyEval_SetOpcodeTrace()
5-
#include "pycore_code.h" // CO_FAST_LOCAL, etc.
6+
#include "pycore_code.h" // CO_FAST_LOCAL
67
#include "pycore_dict.h" // _PyDict_LoadBuiltinsFromGlobals()
8+
#include "pycore_frame.h" // PyFrameObject
79
#include "pycore_function.h" // _PyFunction_FromConstructor()
810
#include "pycore_genobject.h" // _PyGen_GetGeneratorFromFrame()
9-
#include "pycore_moduleobject.h" // _PyModule_GetDict()
10-
#include "pycore_cell.h" // PyCell_GetRef() PyCell_SetTakeRef()
11+
#include "pycore_interpframe.h" // _PyFrame_GetLocalsArray()
1112
#include "pycore_modsupport.h" // _PyArg_CheckPositional()
1213
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
13-
#include "pycore_opcode_metadata.h" // _PyOpcode_Deopt, _PyOpcode_Caches
14+
#include "pycore_opcode_metadata.h" // _PyOpcode_Caches
1415
#include "pycore_optimizer.h" // _Py_Executors_InvalidateDependency()
1516
#include "pycore_unicodeobject.h" // _PyUnicode_Equal()
1617

17-
18-
#include "frameobject.h" // PyFrameObject
19-
#include "pycore_frame.h"
18+
#include "frameobject.h" // PyFrameLocalsProxyObject
2019
#include "opcode.h" // EXTENDED_ARG
2120

2221
#include "clinic/frameobject.c.h"
2322

23+
2424
#define PyFrameObject_CAST(op) \
2525
(assert(PyObject_TypeCheck((op), &PyFrame_Type)), (PyFrameObject *)(op))
2626

Objects/genobject.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@
66
#include "pycore_call.h" // _PyObject_CallNoArgs()
77
#include "pycore_ceval.h" // _PyEval_EvalFrame()
88
#include "pycore_frame.h" // _PyInterpreterFrame
9-
#include "pycore_freelist.h" // _Py_FREELIST_FREE(), _Py_FREELIST_POP()
9+
#include "pycore_freelist.h" // _Py_FREELIST_FREE()
1010
#include "pycore_gc.h" // _PyGC_CLEAR_FINALIZED()
11-
#include "pycore_genobject.h"
11+
#include "pycore_genobject.h" // _PyGen_SetStopIterationValue()
12+
#include "pycore_interpframe.h" // _PyFrame_GetCode()
1213
#include "pycore_modsupport.h" // _PyArg_CheckPositional()
1314
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
1415
#include "pycore_opcode_utils.h" // RESUME_AFTER_YIELD_FROM
15-
#include "pycore_pyatomic_ft_wrappers.h" // FT_ATOMIC_*
16+
#include "pycore_pyatomic_ft_wrappers.h" // FT_ATOMIC_LOAD_UINT8_RELAXED()
1617
#include "pycore_pyerrors.h" // _PyErr_ClearExcState()
1718
#include "pycore_pystate.h" // _PyThreadState_GET()
1819
#include "pycore_warnings.h" // _PyErr_WarnUnawaitedCoroutine()
1920

21+
2022
// Forward declarations
2123
static PyObject* gen_close(PyObject *, PyObject *);
2224
static PyObject* async_gen_asend_new(PyAsyncGenObject *, PyObject *);

PCbuild/pythoncore.vcxproj

+1
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@
262262
<ClInclude Include="..\Include\internal\pycore_interp.h" />
263263
<ClInclude Include="..\Include\internal\pycore_interp_structs.h" />
264264
<ClInclude Include="..\Include\internal\pycore_interpframe.h" />
265+
<ClInclude Include="..\Include\internal\pycore_interpframe_structs.h" />
265266
<ClInclude Include="..\Include\internal\pycore_intrinsics.h" />
266267
<ClInclude Include="..\Include\internal\pycore_jit.h" />
267268
<ClInclude Include="..\Include\internal\pycore_list.h" />

PCbuild/pythoncore.vcxproj.filters

+3
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,9 @@
705705
<ClInclude Include="..\Include\internal\pycore_interpframe.h">
706706
<Filter>Include\internal</Filter>
707707
</ClInclude>
708+
<ClInclude Include="..\Include\internal\pycore_interpframe_structs.h">
709+
<Filter>Include\internal</Filter>
710+
</ClInclude>
708711
<ClInclude Include="..\Include\internal\pycore_intrinsics.h">
709712
<Filter>Include\cpython</Filter>
710713
</ClInclude>

Python/_warnings.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include "Python.h"
2-
#include "pycore_frame.h" // PyFrameObject members
2+
#include "pycore_frame.h" // PyFrameObject
33
#include "pycore_genobject.h" // PyAsyncGenObject
44
#include "pycore_import.h" // _PyImport_GetModules()
5-
#include "pycore_interp.h" // PyInterpreterState.warnings
5+
#include "pycore_interpframe.h" // _PyFrame_GetCode()
66
#include "pycore_long.h" // _PyLong_GetZero()
77
#include "pycore_pylifecycle.h" // _Py_IsInterpreterFinalizing()
88
#include "pycore_pystate.h" // _PyThreadState_GET()

Python/frame.c

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
21
#define _PY_INTERPRETER
32

43
#include "Python.h"
5-
#include "frameobject.h"
6-
#include "pycore_code.h" // stats
7-
#include "pycore_frame.h"
8-
#include "pycore_genobject.h"
9-
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
10-
#include "opcode.h"
4+
#include "pycore_frame.h" // _PyFrame_New_NoTrack()
5+
#include "pycore_interpframe.h" // _PyFrame_GetCode()
6+
#include "pycore_genobject.h" // _PyGen_GetGeneratorFromFrame()
7+
#include "pycore_stackref.h" // _Py_VISIT_STACKREF()
8+
119

1210
int
1311
_PyFrame_Traverse(_PyInterpreterFrame *frame, visitproc visit, void *arg)

Python/intrinsics.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22
#define _PY_INTERPRETER
33

44
#include "Python.h"
5-
#include "pycore_frame.h"
6-
#include "pycore_function.h"
7-
#include "pycore_global_objects.h"
5+
#include "pycore_compile.h" // _PyCompile_GetUnaryIntrinsicName
6+
#include "pycore_function.h" // _Py_set_function_type_params()
87
#include "pycore_genobject.h" // _PyAsyncGenValueWrapperNew
9-
#include "pycore_compile.h" // _PyCompile_GetUnaryIntrinsicName, etc
8+
#include "pycore_interpframe.h" // _PyFrame_GetLocals()
109
#include "pycore_intrinsics.h" // INTRINSIC_PRINT
1110
#include "pycore_pyerrors.h" // _PyErr_SetString()
1211
#include "pycore_runtime.h" // _Py_ID()
1312
#include "pycore_sysmodule.h" // _PySys_GetRequiredAttr()
1413
#include "pycore_tuple.h" // _PyTuple_FromArray()
1514
#include "pycore_typevarobject.h" // _Py_make_typevar()
16-
#include "pycore_unicodeobject.h" // _PyUnicode_FromASCII
15+
#include "pycore_unicodeobject.h" // _PyUnicode_FromASCII()
1716

1817

1918
/******** Unary functions ********/

0 commit comments

Comments
 (0)