mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
bpo-39573: Convert Py_TYPE() to a static inline function (GH-20290)
This commit is contained in:
parent
e50883ccc4
commit
ad3252bad9
4 changed files with 37 additions and 12 deletions
|
@ -62,12 +62,15 @@ the definition of all other Python objects.
|
||||||
See documentation of :c:type:`PyVarObject` above.
|
See documentation of :c:type:`PyVarObject` above.
|
||||||
|
|
||||||
|
|
||||||
.. c:macro:: Py_TYPE(o)
|
.. c:function:: PyTypeObject* Py_TYPE(const PyObject *o)
|
||||||
|
|
||||||
This macro is used to access the :attr:`ob_type` member of a Python object.
|
Get the type of the Python object *o*.
|
||||||
It expands to::
|
|
||||||
|
|
||||||
(((PyObject*)(o))->ob_type)
|
Return a borrowed reference.
|
||||||
|
|
||||||
|
.. versionchanged:: 3.10
|
||||||
|
:c:func:`Py_TYPE()` is changed to the inline static function.
|
||||||
|
Use :c:func:`Py_SET_TYPE()` to set an object type.
|
||||||
|
|
||||||
|
|
||||||
.. c:function:: int Py_IS_TYPE(PyObject *o, PyTypeObject *type)
|
.. c:function:: int Py_IS_TYPE(PyObject *o, PyTypeObject *type)
|
||||||
|
|
|
@ -97,21 +97,14 @@ Optimizations
|
||||||
=============
|
=============
|
||||||
|
|
||||||
|
|
||||||
Build and C API Changes
|
|
||||||
=======================
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Deprecated
|
Deprecated
|
||||||
==========
|
==========
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Removed
|
Removed
|
||||||
=======
|
=======
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Porting to Python 3.10
|
Porting to Python 3.10
|
||||||
======================
|
======================
|
||||||
|
|
||||||
|
@ -119,3 +112,26 @@ This section lists previously described changes and other bugfixes
|
||||||
that may require changes to your code.
|
that may require changes to your code.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Build Changes
|
||||||
|
=============
|
||||||
|
|
||||||
|
|
||||||
|
C API Changes
|
||||||
|
=============
|
||||||
|
|
||||||
|
New Features
|
||||||
|
------------
|
||||||
|
|
||||||
|
|
||||||
|
Porting to Python 3.10
|
||||||
|
----------------------
|
||||||
|
|
||||||
|
* Since :c:func:`Py_TYPE()` is changed to the inline static function,
|
||||||
|
``Py_TYPE(obj) = new_type`` must be replaced with ``Py_SET_TYPE(obj, new_type)``:
|
||||||
|
see :c:func:`Py_SET_TYPE()` (available since Python 3.9).
|
||||||
|
(Contributed by Dong-hee Na in :issue:`39573`.)
|
||||||
|
|
||||||
|
|
||||||
|
Removed
|
||||||
|
-------
|
||||||
|
|
|
@ -121,9 +121,13 @@ typedef struct {
|
||||||
#define _PyVarObject_CAST(op) ((PyVarObject*)(op))
|
#define _PyVarObject_CAST(op) ((PyVarObject*)(op))
|
||||||
|
|
||||||
#define Py_REFCNT(ob) (_PyObject_CAST(ob)->ob_refcnt)
|
#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)
|
#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))
|
||||||
|
|
||||||
static inline int _Py_IS_TYPE(const PyObject *ob, const PyTypeObject *type) {
|
static inline int _Py_IS_TYPE(const PyObject *ob, const PyTypeObject *type) {
|
||||||
return ob->ob_type == type;
|
return ob->ob_type == type;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
:c:func:`Py_TYPE()` is changed to the inline static function. Patch by
|
||||||
|
Dong-hee Na.
|
Loading…
Add table
Add a link
Reference in a new issue