summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2021-09-08 09:59:13 (GMT)
committerGitHub <noreply@github.com>2021-09-08 09:59:13 (GMT)
commitcb15afcccffc6c42cbfb7456ce8db89cd2f77512 (patch)
tree1a0e5510e261f441f1bd3b7027c5ab452967288e /Doc
parent4dc4300c686f543d504ab6fa9fe600eaf11bb695 (diff)
downloadcpython-cb15afcccffc6c42cbfb7456ce8db89cd2f77512.zip
cpython-cb15afcccffc6c42cbfb7456ce8db89cd2f77512.tar.gz
cpython-cb15afcccffc6c42cbfb7456ce8db89cd2f77512.tar.bz2
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.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/c-api/structures.rst13
-rw-r--r--Doc/whatsnew/3.11.rst28
2 files changed, 38 insertions, 3 deletions
diff --git a/Doc/c-api/structures.rst b/Doc/c-api/structures.rst
index 05c54cc..49f2a61 100644
--- a/Doc/c-api/structures.rst
+++ b/Doc/c-api/structures.rst
@@ -99,7 +99,10 @@ the definition of all other Python objects.
Return a :term:`borrowed reference`.
- The :c:func:`Py_SET_TYPE` function must be used to set an object type.
+ Use the :c:func:`Py_SET_TYPE` function to set an object type.
+
+ .. versionchanged:: 3.11
+ :c:func:`Py_TYPE()` is changed to an inline static function.
.. c:function:: int Py_IS_TYPE(PyObject *o, PyTypeObject *type)
@@ -121,9 +124,10 @@ the definition of all other Python objects.
Get the reference count of the Python object *o*.
+ Use the :c:func:`Py_SET_REFCNT()` function to set an object reference count.
+
.. versionchanged:: 3.10
:c:func:`Py_REFCNT()` is changed to the inline static function.
- Use :c:func:`Py_SET_REFCNT()` to set an object reference count.
.. c:function:: void Py_SET_REFCNT(PyObject *o, Py_ssize_t refcnt)
@@ -137,7 +141,10 @@ the definition of all other Python objects.
Get the size of the Python object *o*.
- The :c:func:`Py_SET_SIZE` function must be used to set an object size.
+ Use the :c:func:`Py_SET_SIZE` function to set an object size.
+
+ .. versionchanged:: 3.11
+ :c:func:`Py_SIZE()` is changed to an inline static function.
.. c:function:: void Py_SET_SIZE(PyVarObject *o, Py_ssize_t size)
diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst
index 60ef953..30ee182 100644
--- a/Doc/whatsnew/3.11.rst
+++ b/Doc/whatsnew/3.11.rst
@@ -402,6 +402,34 @@ Porting to Python 3.11
:ref:`static types <static-types>`.
(Contributed by Erlend E. Aasland in :issue:`43908`)
+* Since :c:func:`Py_TYPE()` is changed to a inline static function,
+ ``Py_TYPE(obj) = new_type`` must be replaced with
+ ``Py_SET_TYPE(obj, new_type)``: see the :c:func:`Py_SET_TYPE()` function
+ (available since Python 3.9). For backward compatibility, this macro can be
+ used::
+
+ #if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_TYPE)
+ static inline void _Py_SET_TYPE(PyObject *ob, PyTypeObject *type)
+ { ob->ob_type = type; }
+ #define Py_SET_TYPE(ob, type) _Py_SET_TYPE((PyObject*)(ob), type)
+ #endif
+
+ (Contributed by Victor Stinner in :issue:`39573`.)
+
+* Since :c:func:`Py_SIZE()` is changed to a inline static function,
+ ``Py_SIZE(obj) = new_size`` must be replaced with
+ ``Py_SET_SIZE(obj, new_size)``: see the :c:func:`Py_SET_SIZE()` function
+ (available since Python 3.9). For backward compatibility, this macro can be
+ used::
+
+ #if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_SIZE)
+ static inline void _Py_SET_SIZE(PyVarObject *ob, Py_ssize_t size)
+ { ob->ob_size = size; }
+ #define Py_SET_SIZE(ob, size) _Py_SET_SIZE((PyVarObject*)(ob), size)
+ #endif
+
+ (Contributed by Victor Stinner in :issue:`39573`.)
+
Deprecated
----------