mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-39573: Convert Py_TYPE() and Py_SIZE() back to macros (GH-23366)
This change partically reverts commitad3252bad9
and the commitfe2978b3b9
. Many third party C extension modules rely on the ability of using Py_TYPE() to set an object type: "Py_TYPE(obj) = type;" or to set an object type using: "Py_SIZE(obj) = size;".
This commit is contained in:
parent
2156d964a1
commit
0e2ac21dd4
5 changed files with 35 additions and 26 deletions
|
@ -128,16 +128,11 @@ static inline Py_ssize_t _Py_REFCNT(const PyObject *ob) {
|
|||
#define Py_REFCNT(ob) _Py_REFCNT(_PyObject_CAST_CONST(ob))
|
||||
|
||||
|
||||
static inline Py_ssize_t _Py_SIZE(const PyVarObject *ob) {
|
||||
return ob->ob_size;
|
||||
}
|
||||
#define Py_SIZE(ob) _Py_SIZE(_PyVarObject_CAST_CONST(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 int _Py_IS_TYPE(const PyObject *ob, const PyTypeObject *type) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue