summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-05-27 12:55:10 (GMT)
committerGitHub <noreply@github.com>2020-05-27 12:55:10 (GMT)
commitfe2978b3b940fe2478335e3a2ca5ad22338cdf9c (patch)
tree046e4e97f50b96d62239f8081f7ce6263ef02d78 /Doc
parent20941de0ddc39ce9f07e29b4cc770e8a9ef14d41 (diff)
downloadcpython-fe2978b3b940fe2478335e3a2ca5ad22338cdf9c.zip
cpython-fe2978b3b940fe2478335e3a2ca5ad22338cdf9c.tar.gz
cpython-fe2978b3b940fe2478335e3a2ca5ad22338cdf9c.tar.bz2
bpo-39573: Convert Py_REFCNT and Py_SIZE to functions (GH-20429)
Convert Py_REFCNT() and Py_SIZE() macros to static inline functions. They cannot be used as l-value anymore: use Py_SET_REFCNT() and Py_SET_SIZE() to set an object reference count and size. Replace &Py_SIZE(self) with &((PyVarObject*)self)->ob_size in arraymodule.c. This change is backward incompatible on purpose, to prepare the C API for an opaque PyObject structure.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/c-api/structures.rst19
-rw-r--r--Doc/whatsnew/3.10.rst9
2 files changed, 19 insertions, 9 deletions
diff --git a/Doc/c-api/structures.rst b/Doc/c-api/structures.rst
index 5535f42..b2392fa 100644
--- a/Doc/c-api/structures.rst
+++ b/Doc/c-api/structures.rst
@@ -88,13 +88,13 @@ the definition of all other Python objects.
.. versionadded:: 3.9
-.. c:macro:: Py_REFCNT(o)
+.. c:function:: Py_ssize_t Py_REFCNT(const PyObject *o)
- This macro is used to access the :attr:`ob_refcnt` member of a Python
- object.
- It expands to::
+ Get the reference count of the Python object *o*.
- (((PyObject*)(o))->ob_refcnt)
+ .. 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)
@@ -104,12 +104,13 @@ the definition of all other Python objects.
.. versionadded:: 3.9
-.. c:macro:: Py_SIZE(o)
+.. c:function:: Py_ssize_t Py_SIZE(const PyVarObject *o)
- This macro is used to access the :attr:`ob_size` member of a Python object.
- It expands to::
+ Get the size of the Python object *o*.
- (((PyVarObject*)(o))->ob_size)
+ .. versionchanged:: 3.10
+ :c:func:`Py_SIZE()` is changed to the inline static function.
+ Use :c:func:`Py_SET_SIZE()` to set an object size.
.. c:function:: void Py_SET_SIZE(PyVarObject *o, Py_ssize_t size)
diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst
index fabd9a2..9edef1e 100644
--- a/Doc/whatsnew/3.10.rst
+++ b/Doc/whatsnew/3.10.rst
@@ -138,6 +138,15 @@ Porting to Python 3.10
see :c:func:`Py_SET_TYPE()` (available since Python 3.9).
(Contributed by Dong-hee Na in :issue:`39573`.)
+* Since :c:func:`Py_REFCNT()` is changed to the inline static function,
+ ``Py_REFCNT(obj) = new_refcnt`` must be replaced with ``Py_SET_REFCNT(obj, new_refcnt)``:
+ see :c:func:`Py_SET_REFCNT()` (available since Python 3.9).
+ (Contributed by Victor Stinner in :issue:`39573`.)
+
+* Since :c:func:`Py_SIZE()` is changed to the inline static function,
+ ``Py_SIZE(obj) = new_size`` must be replaced with ``Py_SET_SIZE(obj, new_size)``:
+ see :c:func:`Py_SET_SIZE()` (available since Python 3.9).
+ (Contributed by Victor Stinner in :issue:`39573`.)
Removed
-------