summaryrefslogtreecommitdiffstats
path: root/Include/object.h
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2024-06-18 14:28:48 (GMT)
committerGitHub <noreply@github.com>2024-06-18 14:28:48 (GMT)
commit16f8e22e7c681d8e8184048ed1bf927d33e11758 (patch)
tree372790588b45c65c63dbb3a16e7cc64911bd8ab2 /Include/object.h
parente8752d7b80775ec2a348cd4bf38cbe26a4a07615 (diff)
downloadcpython-16f8e22e7c681d8e8184048ed1bf927d33e11758.zip
cpython-16f8e22e7c681d8e8184048ed1bf927d33e11758.tar.gz
cpython-16f8e22e7c681d8e8184048ed1bf927d33e11758.tar.bz2
gh-120600: Make Py_TYPE() opaque in limited C API 3.14 (#120601)
In the limited C API 3.14 and newer, Py_TYPE() is now implemented as an opaque function call to hide implementation details.
Diffstat (limited to 'Include/object.h')
-rw-r--r--Include/object.h28
1 files changed, 19 insertions, 9 deletions
diff --git a/Include/object.h b/Include/object.h
index 48f9750..795d4fb 100644
--- a/Include/object.h
+++ b/Include/object.h
@@ -244,16 +244,26 @@ _Py_IsOwnedByCurrentThread(PyObject *ob)
}
#endif
-// bpo-39573: The Py_SET_TYPE() function must be used to set an object type.
-static inline PyTypeObject* Py_TYPE(PyObject *ob) {
-#ifdef Py_GIL_DISABLED
- return (PyTypeObject *)_Py_atomic_load_ptr_relaxed(&ob->ob_type);
+// Py_TYPE() implementation for the stable ABI
+PyAPI_FUNC(PyTypeObject*) Py_TYPE(PyObject *ob);
+
+#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 >= 0x030e0000
+ // Stable ABI implements Py_TYPE() as a function call
+ // on limited C API version 3.14 and newer.
#else
- return ob->ob_type;
-#endif
-}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
-# define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
+ static inline PyTypeObject* _Py_TYPE(PyObject *ob)
+ {
+ #if defined(Py_GIL_DISABLED)
+ return (PyTypeObject *)_Py_atomic_load_ptr_relaxed(&ob->ob_type);
+ #else
+ return ob->ob_type;
+ #endif
+ }
+ #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
+ # define Py_TYPE(ob) _Py_TYPE(_PyObject_CAST(ob))
+ #else
+ # define Py_TYPE(ob) _Py_TYPE(ob)
+ #endif
#endif
PyAPI_DATA(PyTypeObject) PyLong_Type;