Closed
Description
In the limited C API 3.14 and newer, I propose to change Py_TYPE() and Py_SET_TYPE() implementation to opaque function calls to hide implementation details. I made a similar change for Py_REFCNT() and Py_SET_REFCNT() in Python 3.12.
The problem is that with Free Threading (PEP 703), the implementation of these functions become less trivial than just getting/setting an object member:
static inline PyTypeObject* Py_TYPE(PyObject *ob) {
return (PyTypeObject *)_Py_atomic_load_ptr_relaxed(&ob->ob_type);
}
static inline void Py_SET_TYPE(PyObject *ob, PyTypeObject *type) {
_Py_atomic_store_ptr(&ob->ob_type, type);
}
_Py_atomic_load_ptr_relaxed()
and _Py_atomic_store_ptr()
must now be called. But I would prefer to not "leak" such implementation detail into the limited C API.