https://github.com/python/cpython/commit/c4e7d245d61ac4547ecf3362b28f64fc00aa88c0
commit: c4e7d245d61ac4547ecf3362b28f64fc00aa88c0
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2025-10-08T12:10:58+02:00
summary:

gh-138342: Move _PyObject_VisitType() to the internal C API (#139734)

files:
M Include/cpython/object.h
M Include/internal/pycore_object.h
M Modules/_dbmmodule.c
M Modules/_decimal/_decimal.c
M Modules/_gdbmmodule.c
M Modules/_multiprocessing/semaphore.c
M Modules/_sqlite/prepare_protocol.c
M Modules/_sqlite/statement.c
M Modules/blake2module.c
M Modules/md5module.c
M Modules/sha1module.c
M Modules/sha2module.c
M Modules/sha3module.c
M Modules/socketmodule.c
M Modules/unicodedata.c

diff --git a/Include/cpython/object.h b/Include/cpython/object.h
index 4e6f86f29d8473..e2f87524c218b6 100644
--- a/Include/cpython/object.h
+++ b/Include/cpython/object.h
@@ -492,7 +492,3 @@ PyAPI_FUNC(int) PyUnstable_TryIncRef(PyObject *);
 PyAPI_FUNC(void) PyUnstable_EnableTryIncRef(PyObject *);
 
 PyAPI_FUNC(int) PyUnstable_Object_IsUniquelyReferenced(PyObject *);
-
-/* Utility for the tp_traverse slot of mutable heap types that have no other
- * references. */
-PyAPI_FUNC(int) _PyObject_VisitType(PyObject *op, visitproc visit, void *arg);
diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h
index 40f8ca68c00b72..77560e5da66b03 100644
--- a/Include/internal/pycore_object.h
+++ b/Include/internal/pycore_object.h
@@ -1047,6 +1047,10 @@ static inline Py_ALWAYS_INLINE void 
_Py_INCREF_MORTAL(PyObject *op)
 }
 #endif
 
+/* Utility for the tp_traverse slot of mutable heap types that have no other
+ * references. */
+PyAPI_FUNC(int) _PyObject_VisitType(PyObject *op, visitproc visit, void *arg);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/Modules/_dbmmodule.c b/Modules/_dbmmodule.c
index 3fdcf22ffd56d0..06712015418cbc 100644
--- a/Modules/_dbmmodule.c
+++ b/Modules/_dbmmodule.c
@@ -8,6 +8,7 @@
 #endif
 
 #include "Python.h"
+#include "pycore_object.h"        // _PyObject_VisitType()
 
 #include <sys/types.h>
 #include <sys/stat.h>
diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c
index 0696c150cd42fb..04b6695f8af06a 100644
--- a/Modules/_decimal/_decimal.c
+++ b/Modules/_decimal/_decimal.c
@@ -30,9 +30,9 @@
 #endif
 
 #include <Python.h>
+#include "pycore_object.h"        // _PyObject_VisitType()
 #include "pycore_pystate.h"       // _PyThreadState_GET()
 #include "pycore_typeobject.h"
-#include "complexobject.h"
 
 #include <mpdecimal.h>
 
diff --git a/Modules/_gdbmmodule.c b/Modules/_gdbmmodule.c
index a4bc0a0f675530..87b84976f49d61 100644
--- a/Modules/_gdbmmodule.c
+++ b/Modules/_gdbmmodule.c
@@ -8,11 +8,12 @@
 #endif
 
 #include "Python.h"
-#include "pycore_pyerrors.h"        // _PyErr_SetLocaleString()
+#include "pycore_object.h"        // _PyObject_VisitType()
+#include "pycore_pyerrors.h"      // _PyErr_SetLocaleString()
 #include "gdbm.h"
 
 #include <fcntl.h>
-#include <stdlib.h>                 // free()
+#include <stdlib.h>               // free()
 #include <sys/stat.h>
 #include <sys/types.h>
 
diff --git a/Modules/_multiprocessing/semaphore.c 
b/Modules/_multiprocessing/semaphore.c
index d5a1f27e9ff4ff..85cc0ac70a6563 100644
--- a/Modules/_multiprocessing/semaphore.c
+++ b/Modules/_multiprocessing/semaphore.c
@@ -8,6 +8,7 @@
  */
 
 #include "multiprocessing.h"
+#include "pycore_object.h"        // _PyObject_VisitType()
 
 #ifdef HAVE_SYS_TIME_H
 #  include <sys/time.h>           // gettimeofday()
diff --git a/Modules/_sqlite/prepare_protocol.c 
b/Modules/_sqlite/prepare_protocol.c
index d7ac09e3947a77..0e2812e1e4ffa8 100644
--- a/Modules/_sqlite/prepare_protocol.c
+++ b/Modules/_sqlite/prepare_protocol.c
@@ -21,8 +21,15 @@
  * 3. This notice may not be removed or altered from any source distribution.
  */
 
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #include "prepare_protocol.h"
 
+#include "pycore_object.h"        // _PyObject_VisitType()
+
+
 static int
 pysqlite_prepare_protocol_init(PyObject *self, PyObject *args, PyObject 
*kwargs)
 {
diff --git a/Modules/_sqlite/statement.c b/Modules/_sqlite/statement.c
index 77181104eda10b..c551ca59b3381f 100644
--- a/Modules/_sqlite/statement.c
+++ b/Modules/_sqlite/statement.c
@@ -21,10 +21,17 @@
  * 3. This notice may not be removed or altered from any source distribution.
  */
 
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #include "connection.h"
 #include "statement.h"
 #include "util.h"
 
+#include "pycore_object.h"        // _PyObject_VisitType()
+
+
 #define _pysqlite_Statement_CAST(op)    ((pysqlite_Statement *)(op))
 
 /* prototypes */
diff --git a/Modules/blake2module.c b/Modules/blake2module.c
index 4921e8f945ef37..89b0ebd516f693 100644
--- a/Modules/blake2module.c
+++ b/Modules/blake2module.c
@@ -16,9 +16,10 @@
 
 #include "Python.h"
 #include "hashlib.h"
-#include "pycore_strhex.h"       // _Py_strhex()
-#include "pycore_typeobject.h"
 #include "pycore_moduleobject.h"
+#include "pycore_object.h"        // _PyObject_VisitType()
+#include "pycore_strhex.h"        // _Py_strhex()
+#include "pycore_typeobject.h"
 
 // QUICK CPU AUTODETECTION
 //
diff --git a/Modules/md5module.c b/Modules/md5module.c
index 6b6457427b6b5e..56e9faf4c62002 100644
--- a/Modules/md5module.c
+++ b/Modules/md5module.c
@@ -22,7 +22,8 @@
 #endif
 
 #include "Python.h"
-#include "pycore_strhex.h" // _Py_strhex()
+#include "pycore_object.h"        // _PyObject_VisitType()
+#include "pycore_strhex.h"        // _Py_strhex()
 
 #include "hashlib.h"
 
diff --git a/Modules/sha1module.c b/Modules/sha1module.c
index d64eb91458cae8..89e66240d1d11f 100644
--- a/Modules/sha1module.c
+++ b/Modules/sha1module.c
@@ -21,6 +21,7 @@
 
 #include "Python.h"
 #include "hashlib.h"
+#include "pycore_object.h"        // _PyObject_VisitType()
 #include "pycore_strhex.h"        // _Py_strhex()
 #include "pycore_typeobject.h"    // _PyType_GetModuleState()
 
diff --git a/Modules/sha2module.c b/Modules/sha2module.c
index 66259fe47a0fd3..9453b0be512555 100644
--- a/Modules/sha2module.c
+++ b/Modules/sha2module.c
@@ -22,8 +22,9 @@
 
 #include "Python.h"
 #include "pycore_moduleobject.h"  // _PyModule_GetState()
-#include "pycore_typeobject.h"    // _PyType_GetModuleState()
+#include "pycore_object.h"        // _PyObject_VisitType()
 #include "pycore_strhex.h"        // _Py_strhex()
+#include "pycore_typeobject.h"    // _PyType_GetModuleState()
 
 #include "hashlib.h"
 
diff --git a/Modules/sha3module.c b/Modules/sha3module.c
index 14c543b86415d5..38c9bc0405be60 100644
--- a/Modules/sha3module.c
+++ b/Modules/sha3module.c
@@ -21,6 +21,7 @@
 #endif
 
 #include "Python.h"
+#include "pycore_object.h"        // _PyObject_VisitType()
 #include "pycore_strhex.h"        // _Py_strhex()
 #include "pycore_typeobject.h"    // _PyType_GetModuleState()
 #include "hashlib.h"
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index ec8b53273bc083..fa153efd8b72ec 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -109,6 +109,7 @@ Local naming conventions:
 #include "pycore_capsule.h"       // _PyCapsule_SetTraverse()
 #include "pycore_fileutils.h"     // _Py_set_inheritable()
 #include "pycore_moduleobject.h"  // _PyModule_GetState
+#include "pycore_object.h"        // _PyObject_VisitType()
 #include "pycore_time.h"          // _PyTime_AsMilliseconds()
 #include "pycore_pystate.h"       // _Py_AssertHoldsTstate()
 
diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c
index 3c9bc35fa35c8f..a3699beff7da01 100644
--- a/Modules/unicodedata.c
+++ b/Modules/unicodedata.c
@@ -17,6 +17,7 @@
 #endif
 
 #include "Python.h"
+#include "pycore_object.h"        // _PyObject_VisitType()
 #include "pycore_ucnhash.h"       // _PyUnicode_Name_CAPI
 
 #include <stdbool.h>

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to