bpo-39573: Py_TYPE becomes a static inline function (GH-28128)

Convert the Py_TYPE() and Py_SIZE() macros to static inline
functions. The Py_SET_TYPE() and Py_SET_SIZE() functions must now be
used to set an object type and size.
This commit is contained in:
Victor Stinner 2021-09-08 11:59:13 +02:00 committed by GitHub
parent 4dc4300c68
commit cb15afcccf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 9 deletions

View file

@ -134,10 +134,16 @@ static inline Py_ssize_t _Py_REFCNT(const PyObject *ob) {
// bpo-39573: The Py_SET_TYPE() function must be used to set an object type.
#define Py_TYPE(ob) (_PyObject_CAST(ob)->ob_type)
static inline PyTypeObject* _Py_TYPE(const PyObject *ob) {
return ob->ob_type;
}
#define Py_TYPE(ob) _Py_TYPE(_PyObject_CAST_CONST(ob))
// bpo-39573: The Py_SET_SIZE() function must be used to set an object size.
#define Py_SIZE(ob) (_PyVarObject_CAST(ob)->ob_size)
static inline Py_ssize_t _Py_SIZE(const PyVarObject *ob) {
return ob->ob_size;
}
#define Py_SIZE(ob) _Py_SIZE(_PyVarObject_CAST_CONST(ob))
static inline int _Py_IS_TYPE(const PyObject *ob, const PyTypeObject *type) {