Skip to content

bpo-30459: Cast the result of PyCell_SET to void #23654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions Doc/whatsnew/3.10.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------

Expand Down
2 changes: 1 addition & 1 deletion Include/cellobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.