https://github.com/python/cpython/commit/7101cba6bf12639e277f7681b90a70c11368cabb
commit: 7101cba6bf12639e277f7681b90a70c11368cabb
branch: main
author: Victor Stinner <vstin...@python.org>
committer: vstinner <vstin...@python.org>
date: 2025-03-21T23:24:14+01:00
summary:

gh-131238: Move _Py_VISIT_STACKREF() to pycore_stackref.h (#131560)

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

files:
M Include/internal/pycore_gc.h
M Include/internal/pycore_genobject.h
M Include/internal/pycore_stackref.h
M Makefile.pre.in
M Objects/frameobject.c
M Objects/genobject.c
M PCbuild/pythoncore.vcxproj
M PCbuild/pythoncore.vcxproj.filters
M Python/_warnings.c
M Python/frame.c
M Python/intrinsics.c

diff --git a/Include/internal/pycore_gc.h b/Include/internal/pycore_gc.h
index 96b3bc2e6333bc..a6519aa086309d 100644
--- a/Include/internal/pycore_gc.h
+++ b/Include/internal/pycore_gc.h
@@ -352,16 +352,6 @@ union _PyStackRef;
 extern int _PyGC_VisitFrameStack(_PyInterpreterFrame *frame, visitproc visit, 
void *arg);
 extern int _PyGC_VisitStackRef(union _PyStackRef *ref, visitproc visit, void 
*arg);
 
-// Like Py_VISIT but for _PyStackRef fields
-#define _Py_VISIT_STACKREF(ref)                                         \
-    do {                                                                \
-        if (!PyStackRef_IsNull(ref)) {                                  \
-            int vret = _PyGC_VisitStackRef(&(ref), visit, arg);         \
-            if (vret)                                                   \
-                return vret;                                            \
-        }                                                               \
-    } while (0)
-
 #ifdef Py_GIL_DISABLED
 extern void _PyGC_VisitObjectsWorldStopped(PyInterpreterState *interp,
                                            gcvisitobjects_t callback, void 
*arg);
diff --git a/Include/internal/pycore_genobject.h 
b/Include/internal/pycore_genobject.h
index 2947dde71fd676..c1fc3511f849ad 100644
--- a/Include/internal/pycore_genobject.h
+++ b/Include/internal/pycore_genobject.h
@@ -8,9 +8,10 @@ extern "C" {
 #  error "this header requires Py_BUILD_CORE define"
 #endif
 
-#include "pycore_interpframe.h"   // _PyInterpreterFrame
 #include "pycore_interpframe_structs.h" // _PyGenObject
 
+#include <stddef.h>               // offsetof()
+
 
 static inline
 PyGenObject *_PyGen_GetGeneratorFromFrame(_PyInterpreterFrame *frame)
diff --git a/Include/internal/pycore_stackref.h 
b/Include/internal/pycore_stackref.h
index cf7688416b170b..9eba92df5cae55 100644
--- a/Include/internal/pycore_stackref.h
+++ b/Include/internal/pycore_stackref.h
@@ -658,6 +658,16 @@ _Py_TryIncrefCompareStackRef(PyObject **src, PyObject *op, 
_PyStackRef *out)
 
 #endif
 
+// Like Py_VISIT but for _PyStackRef fields
+#define _Py_VISIT_STACKREF(ref)                                         \
+    do {                                                                \
+        if (!PyStackRef_IsNull(ref)) {                                  \
+            int vret = _PyGC_VisitStackRef(&(ref), visit, arg);         \
+            if (vret)                                                   \
+                return vret;                                            \
+        }                                                               \
+    } while (0)
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/Makefile.pre.in b/Makefile.pre.in
index 92f3984fa98b31..9658bfa44b98e4 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -1257,6 +1257,7 @@ PYTHON_HEADERS= \
                $(srcdir)/Include/internal/pycore_interp.h \
                $(srcdir)/Include/internal/pycore_interp_structs.h \
                $(srcdir)/Include/internal/pycore_interpframe.h \
+               $(srcdir)/Include/internal/pycore_interpframe_structs.h \
                $(srcdir)/Include/internal/pycore_intrinsics.h \
                $(srcdir)/Include/internal/pycore_jit.h \
                $(srcdir)/Include/internal/pycore_list.h \
diff --git a/Objects/frameobject.c b/Objects/frameobject.c
index 88893467855ba2..e6a124ef94c3a1 100644
--- a/Objects/frameobject.c
+++ b/Objects/frameobject.c
@@ -1,26 +1,26 @@
 /* Frame object implementation */
 
 #include "Python.h"
+#include "pycore_cell.h"          // PyCell_GetRef()
 #include "pycore_ceval.h"         // _PyEval_SetOpcodeTrace()
-#include "pycore_code.h"          // CO_FAST_LOCAL, etc.
+#include "pycore_code.h"          // CO_FAST_LOCAL
 #include "pycore_dict.h"          // _PyDict_LoadBuiltinsFromGlobals()
+#include "pycore_frame.h"         // PyFrameObject
 #include "pycore_function.h"      // _PyFunction_FromConstructor()
 #include "pycore_genobject.h"     // _PyGen_GetGeneratorFromFrame()
-#include "pycore_moduleobject.h"  // _PyModule_GetDict()
-#include "pycore_cell.h"          // PyCell_GetRef() PyCell_SetTakeRef()
+#include "pycore_interpframe.h"   // _PyFrame_GetLocalsArray()
 #include "pycore_modsupport.h"    // _PyArg_CheckPositional()
 #include "pycore_object.h"        // _PyObject_GC_UNTRACK()
-#include "pycore_opcode_metadata.h" // _PyOpcode_Deopt, _PyOpcode_Caches
+#include "pycore_opcode_metadata.h" // _PyOpcode_Caches
 #include "pycore_optimizer.h"     // _Py_Executors_InvalidateDependency()
 #include "pycore_unicodeobject.h" // _PyUnicode_Equal()
 
-
-#include "frameobject.h"          // PyFrameObject
-#include "pycore_frame.h"
+#include "frameobject.h"          // PyFrameLocalsProxyObject
 #include "opcode.h"               // EXTENDED_ARG
 
 #include "clinic/frameobject.c.h"
 
+
 #define PyFrameObject_CAST(op)  \
     (assert(PyObject_TypeCheck((op), &PyFrame_Type)), (PyFrameObject *)(op))
 
diff --git a/Objects/genobject.c b/Objects/genobject.c
index 13f2bf7808c309..0238613c2a19df 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -6,17 +6,19 @@
 #include "pycore_call.h"          // _PyObject_CallNoArgs()
 #include "pycore_ceval.h"         // _PyEval_EvalFrame()
 #include "pycore_frame.h"         // _PyInterpreterFrame
-#include "pycore_freelist.h"      // _Py_FREELIST_FREE(), _Py_FREELIST_POP()
+#include "pycore_freelist.h"      // _Py_FREELIST_FREE()
 #include "pycore_gc.h"            // _PyGC_CLEAR_FINALIZED()
-#include "pycore_genobject.h"
+#include "pycore_genobject.h"     // _PyGen_SetStopIterationValue()
+#include "pycore_interpframe.h"   // _PyFrame_GetCode()
 #include "pycore_modsupport.h"    // _PyArg_CheckPositional()
 #include "pycore_object.h"        // _PyObject_GC_UNTRACK()
 #include "pycore_opcode_utils.h"  // RESUME_AFTER_YIELD_FROM
-#include "pycore_pyatomic_ft_wrappers.h" // FT_ATOMIC_*
+#include "pycore_pyatomic_ft_wrappers.h" // FT_ATOMIC_LOAD_UINT8_RELAXED()
 #include "pycore_pyerrors.h"      // _PyErr_ClearExcState()
 #include "pycore_pystate.h"       // _PyThreadState_GET()
 #include "pycore_warnings.h"      // _PyErr_WarnUnawaitedCoroutine()
 
+
 // Forward declarations
 static PyObject* gen_close(PyObject *, PyObject *);
 static PyObject* async_gen_asend_new(PyAsyncGenObject *, PyObject *);
diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj
index e876bd44f03942..2e639ddfc320f5 100644
--- a/PCbuild/pythoncore.vcxproj
+++ b/PCbuild/pythoncore.vcxproj
@@ -262,6 +262,7 @@
     <ClInclude Include="..\Include\internal\pycore_interp.h" />
     <ClInclude Include="..\Include\internal\pycore_interp_structs.h" />
     <ClInclude Include="..\Include\internal\pycore_interpframe.h" />
+    <ClInclude Include="..\Include\internal\pycore_interpframe_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 6fcfb02f698c9f..31064f50f5c8d7 100644
--- a/PCbuild/pythoncore.vcxproj.filters
+++ b/PCbuild/pythoncore.vcxproj.filters
@@ -705,6 +705,9 @@
     <ClInclude Include="..\Include\internal\pycore_interpframe.h">
       <Filter>Include\internal</Filter>
     </ClInclude>
+    <ClInclude Include="..\Include\internal\pycore_interpframe_structs.h">
+      <Filter>Include\internal</Filter>
+    </ClInclude>
     <ClInclude Include="..\Include\internal\pycore_intrinsics.h">
       <Filter>Include\cpython</Filter>
     </ClInclude>
diff --git a/Python/_warnings.c b/Python/_warnings.c
index 1e90ef0299c2e2..f9dd00f3ec23aa 100644
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -1,8 +1,8 @@
 #include "Python.h"
-#include "pycore_frame.h"         // PyFrameObject members
+#include "pycore_frame.h"         // PyFrameObject
 #include "pycore_genobject.h"     // PyAsyncGenObject
 #include "pycore_import.h"        // _PyImport_GetModules()
-#include "pycore_interp.h"        // PyInterpreterState.warnings
+#include "pycore_interpframe.h"   // _PyFrame_GetCode()
 #include "pycore_long.h"          // _PyLong_GetZero()
 #include "pycore_pylifecycle.h"   // _Py_IsInterpreterFinalizing()
 #include "pycore_pystate.h"       // _PyThreadState_GET()
diff --git a/Python/frame.c b/Python/frame.c
index 462202451f9f9d..b59cb4bbb5536e 100644
--- a/Python/frame.c
+++ b/Python/frame.c
@@ -1,13 +1,11 @@
-
 #define _PY_INTERPRETER
 
 #include "Python.h"
-#include "frameobject.h"
-#include "pycore_code.h"          // stats
-#include "pycore_frame.h"
-#include "pycore_genobject.h"
-#include "pycore_object.h"        // _PyObject_GC_UNTRACK()
-#include "opcode.h"
+#include "pycore_frame.h"         // _PyFrame_New_NoTrack()
+#include "pycore_interpframe.h"   // _PyFrame_GetCode()
+#include "pycore_genobject.h"     // _PyGen_GetGeneratorFromFrame()
+#include "pycore_stackref.h"      // _Py_VISIT_STACKREF()
+
 
 int
 _PyFrame_Traverse(_PyInterpreterFrame *frame, visitproc visit, void *arg)
diff --git a/Python/intrinsics.c b/Python/intrinsics.c
index f6dfee3e9ab951..1c7d7ee6c12bfc 100644
--- a/Python/intrinsics.c
+++ b/Python/intrinsics.c
@@ -2,18 +2,17 @@
 #define _PY_INTERPRETER
 
 #include "Python.h"
-#include "pycore_frame.h"
-#include "pycore_function.h"
-#include "pycore_global_objects.h"
+#include "pycore_compile.h"       // _PyCompile_GetUnaryIntrinsicName
+#include "pycore_function.h"      // _Py_set_function_type_params()
 #include "pycore_genobject.h"     // _PyAsyncGenValueWrapperNew
-#include "pycore_compile.h"       // _PyCompile_GetUnaryIntrinsicName, etc
+#include "pycore_interpframe.h"   // _PyFrame_GetLocals()
 #include "pycore_intrinsics.h"    // INTRINSIC_PRINT
 #include "pycore_pyerrors.h"      // _PyErr_SetString()
 #include "pycore_runtime.h"       // _Py_ID()
 #include "pycore_sysmodule.h"     // _PySys_GetRequiredAttr()
 #include "pycore_tuple.h"         // _PyTuple_FromArray()
 #include "pycore_typevarobject.h" // _Py_make_typevar()
-#include "pycore_unicodeobject.h" // _PyUnicode_FromASCII
+#include "pycore_unicodeobject.h" // _PyUnicode_FromASCII()
 
 
 /******** Unary functions ********/

_______________________________________________
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

Reply via email to