Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
bpo-39573: Convert Py_TYPE() to a static inline function
  • Loading branch information
corona10 committed May 21, 2020
commit 21dd58e80a9808419c2401402ac7b6bf41a734e2
8 changes: 4 additions & 4 deletions Doc/c-api/structures.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ the definition of all other Python objects.
See documentation of :c:type:`PyVarObject` above.


.. c:macro:: Py_TYPE(o)
.. c:function:: PyTypeObject* Py_TYPE(PyObject *o)
Comment thread
corona10 marked this conversation as resolved.
Outdated

This macro is used to access the :attr:`ob_type` member of a Python object.
It expands to::
This function is used to access the :attr:`ob_type` member of a Python object.
Comment thread
corona10 marked this conversation as resolved.
Outdated

(((PyObject*)(o))->ob_type)
.. versionchanged:: 3.10
:c:func:`Py_TYPE()` is changed to the inline static function.
Comment thread
corona10 marked this conversation as resolved.


.. c:function:: int Py_IS_TYPE(PyObject *o, PyTypeObject *type)
Expand Down
6 changes: 5 additions & 1 deletion Include/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,13 @@ typedef struct {
#define _PyVarObject_CAST(op) ((PyVarObject*)(op))

#define Py_REFCNT(ob) (_PyObject_CAST(ob)->ob_refcnt)
#define Py_TYPE(ob) (_PyObject_CAST(ob)->ob_type)
#define Py_SIZE(ob) (_PyVarObject_CAST(ob)->ob_size)

static inline PyTypeObject* _Py_TYPE(const PyObject *ob) {
return ob->ob_type;
}
#define Py_TYPE(ob) _Py_TYPE(_PyObject_CAST_CONST(ob))
Comment thread
corona10 marked this conversation as resolved.

static inline int _Py_IS_TYPE(const PyObject *ob, const PyTypeObject *type) {
return ob->ob_type == type;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:c:func:`Py_TYPE()` is changed to the inline static function. Patch by
Dong-hee Na.