From 028a69bbbb8e6bab38f40d54768a7fa02c378da2 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 8 Oct 2025 00:43:28 +0200 Subject: [PATCH 1/2] gh-138342: Move _PyObject_VisitType() to the internal C API --- Include/cpython/object.h | 4 ---- Include/internal/pycore_object.h | 4 ++++ Modules/_dbmmodule.c | 1 + Modules/_gdbmmodule.c | 5 +++-- Modules/_multiprocessing/semaphore.c | 1 + Modules/_sqlite/prepare_protocol.c | 7 +++++++ Modules/_sqlite/statement.c | 7 +++++++ Modules/blake2module.c | 5 +++-- Modules/md5module.c | 3 ++- Modules/sha1module.c | 1 + Modules/sha2module.c | 3 ++- Modules/sha3module.c | 1 + Modules/socketmodule.c | 1 + Modules/unicodedata.c | 1 + 14 files changed, 34 insertions(+), 10 deletions(-) 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 #include 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 -#include // free() +#include // free() #include #include 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 // 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 From 0ff14098e82de5ec836a48af22af449423a1d37d Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 8 Oct 2025 00:53:46 +0200 Subject: [PATCH 2/2] Update _decimal extension --- Modules/_decimal/_decimal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 +#include "pycore_object.h" // _PyObject_VisitType() #include "pycore_pystate.h" // _PyThreadState_GET() #include "pycore_typeobject.h" -#include "complexobject.h" #include