diff options
author | Victor Stinner <vstinner@python.org> | 2020-12-07 10:56:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-07 10:56:20 (GMT) |
commit | 0ef96c2b2a291c9d2d9c0ba42bbc1900a21e65f3 (patch) | |
tree | b7f921c6b76994932e2845ceff1853a6149f4fb3 | |
parent | c266736ec1f9ebef38b134ceb4832df015711b38 (diff) | |
download | cpython-0ef96c2b2a291c9d2d9c0ba42bbc1900a21e65f3.zip cpython-0ef96c2b2a291c9d2d9c0ba42bbc1900a21e65f3.tar.gz cpython-0ef96c2b2a291c9d2d9c0ba42bbc1900a21e65f3.tar.bz2 |
bpo-30459: Cast the result of PyCell_SET to void (GH-23654)
-rw-r--r-- | Doc/whatsnew/3.10.rst | 7 | ||||
-rw-r--r-- | Include/cellobject.h | 2 | ||||
-rw-r--r-- | Misc/NEWS.d/next/C API/2020-05-06-23-54-57.bpo-30459.N9_Jai.rst | 8 |
3 files changed, 14 insertions, 3 deletions
diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst index 019dd18..a5cb4e3 100644 --- a/Doc/whatsnew/3.10.rst +++ b/Doc/whatsnew/3.10.rst @@ -611,6 +611,13 @@ Porting to Python 3.10 :ref:`Python Path Configuration. <init-path-config>`. (Contributed by Victor Stinner in :issue:`42260`.) +* :c:func:`PyList_SET_ITEM`, :c:func:`PyTuple_SET_ITEM` and + :c:func:`PyCell_SET` macros can no longer be used as l-value or r-value. + For example, ``x = PyList_SET_ITEM(a, b, c)`` and + ``PyList_SET_ITEM(a, b, c) = x`` now fail with a compiler error. It prevents + bugs like ``if (PyList_SET_ITEM (a, b, c) < 0) ...`` test. + (Contributed by Zackery Spytz and Victor Stinner in :issue:`30459`.) + Deprecated ---------- diff --git a/Include/cellobject.h b/Include/cellobject.h index f12aa90..81bc784 100644 --- a/Include/cellobject.h +++ b/Include/cellobject.h @@ -20,7 +20,7 @@ PyAPI_FUNC(PyObject *) PyCell_Get(PyObject *); PyAPI_FUNC(int) PyCell_Set(PyObject *, PyObject *); #define PyCell_GET(op) (((PyCellObject *)(op))->ob_ref) -#define PyCell_SET(op, v) (((PyCellObject *)(op))->ob_ref = v) +#define PyCell_SET(op, v) ((void)(((PyCellObject *)(op))->ob_ref = v)) #ifdef __cplusplus } diff --git a/Misc/NEWS.d/next/C API/2020-05-06-23-54-57.bpo-30459.N9_Jai.rst b/Misc/NEWS.d/next/C API/2020-05-06-23-54-57.bpo-30459.N9_Jai.rst index e3ee6dc..092d457 100644 --- a/Misc/NEWS.d/next/C API/2020-05-06-23-54-57.bpo-30459.N9_Jai.rst +++ b/Misc/NEWS.d/next/C API/2020-05-06-23-54-57.bpo-30459.N9_Jai.rst @@ -1,2 +1,6 @@ -Cast the result of :c:func:`PyList_SET_ITEM` and :c:func:`PyTuple_SET_ITEM` -to void. +:c:func:`PyList_SET_ITEM`, :c:func:`PyTuple_SET_ITEM` and :c:func:`PyCell_SET` +macros can no longer be used as l-value or r-value. For example, +``x = PyList_SET_ITEM(a, b, c)`` and ``PyList_SET_ITEM(a, b, c) = x`` now fail +with a compiler error. It prevents bugs like +``if (PyList_SET_ITEM (a, b, c) < 0) ...`` test. +Patch by Zackery Spytz and Victor Stinner. |