Skip to content

Commit 21dd58e

Browse files
committed
bpo-39573: Convert Py_TYPE() to a static inline function
1 parent e16d2f7 commit 21dd58e

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

Doc/c-api/structures.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ the definition of all other Python objects.
6262
See documentation of :c:type:`PyVarObject` above.
6363

6464

65-
.. c:macro:: Py_TYPE(o)
65+
.. c:function:: PyTypeObject* Py_TYPE(PyObject *o)
6666
67-
This macro is used to access the :attr:`ob_type` member of a Python object.
68-
It expands to::
67+
This function is used to access the :attr:`ob_type` member of a Python object.
6968
70-
(((PyObject*)(o))->ob_type)
69+
.. versionchanged:: 3.10
70+
:c:func:`Py_TYPE()` is changed to the inline static function.
7171
7272
7373
.. c:function:: int Py_IS_TYPE(PyObject *o, PyTypeObject *type)

Include/object.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,13 @@ typedef struct {
121121
#define _PyVarObject_CAST(op) ((PyVarObject*)(op))
122122

123123
#define Py_REFCNT(ob) (_PyObject_CAST(ob)->ob_refcnt)
124-
#define Py_TYPE(ob) (_PyObject_CAST(ob)->ob_type)
125124
#define Py_SIZE(ob) (_PyVarObject_CAST(ob)->ob_size)
126125

126+
static inline PyTypeObject* _Py_TYPE(const PyObject *ob) {
127+
return ob->ob_type;
128+
}
129+
#define Py_TYPE(ob) _Py_TYPE(_PyObject_CAST_CONST(ob))
130+
127131
static inline int _Py_IS_TYPE(const PyObject *ob, const PyTypeObject *type) {
128132
return ob->ob_type == type;
129133
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:c:func:`Py_TYPE()` is changed to the inline static function. Patch by
2+
Dong-hee Na.

0 commit comments

Comments
 (0)