summaryrefslogtreecommitdiffstats
path: root/Include/cpython
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2021-11-30 11:14:45 (GMT)
committerGitHub <noreply@github.com>2021-11-30 11:14:45 (GMT)
commitc19c3a09618ac400538ee412f84be4c1196c7bab (patch)
tree538842c2c053a4f62123ad5244b77aef64ec14c6 /Include/cpython
parentf97ec09baf8431494fd2ef5133090c7b0afd0551 (diff)
downloadcpython-c19c3a09618ac400538ee412f84be4c1196c7bab.zip
cpython-c19c3a09618ac400538ee412f84be4c1196c7bab.tar.gz
cpython-c19c3a09618ac400538ee412f84be4c1196c7bab.tar.bz2
bpo-45476: Add _Py_RVALUE() macro (GH-29860)
Add a new _Py_RVALUE() macro to prevent using an expression as an l-value. Replace a "(void)" cast with the _Py_RVALUE() macro in the following macros: * PyCell_SET() * PyList_SET_ITEM() * PyTuple_SET_ITEM() * _PyGCHead_SET_FINALIZED() * _PyGCHead_SET_NEXT() * asdl_seq_SET() * asdl_seq_SET_UNTYPED() Add also parentheses around macro arguments in PyCell_SET() and PyTuple_SET_ITEM() macros.
Diffstat (limited to 'Include/cpython')
-rw-r--r--Include/cpython/cellobject.h2
-rw-r--r--Include/cpython/listobject.h2
-rw-r--r--Include/cpython/tupleobject.h2
3 files changed, 3 insertions, 3 deletions
diff --git a/Include/cpython/cellobject.h b/Include/cpython/cellobject.h
index 8dc7b8f..e07f9d1 100644
--- a/Include/cpython/cellobject.h
+++ b/Include/cpython/cellobject.h
@@ -22,7 +22,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) ((void)(((PyCellObject *)(op))->ob_ref = v))
+#define PyCell_SET(op, v) _Py_RVALUE(((PyCellObject *)(op))->ob_ref = (v))
#ifdef __cplusplus
}
diff --git a/Include/cpython/listobject.h b/Include/cpython/listobject.h
index e323915..51687d8 100644
--- a/Include/cpython/listobject.h
+++ b/Include/cpython/listobject.h
@@ -30,5 +30,5 @@ PyAPI_FUNC(void) _PyList_DebugMallocStats(FILE *out);
#define _PyList_CAST(op) (assert(PyList_Check(op)), (PyListObject *)(op))
#define PyList_GET_ITEM(op, i) (_PyList_CAST(op)->ob_item[i])
-#define PyList_SET_ITEM(op, i, v) ((void)(_PyList_CAST(op)->ob_item[i] = (v)))
+#define PyList_SET_ITEM(op, i, v) _Py_RVALUE(_PyList_CAST(op)->ob_item[i] = (v))
#define PyList_GET_SIZE(op) Py_SIZE(_PyList_CAST(op))
diff --git a/Include/cpython/tupleobject.h b/Include/cpython/tupleobject.h
index 7cada88..fc37c4e 100644
--- a/Include/cpython/tupleobject.h
+++ b/Include/cpython/tupleobject.h
@@ -23,6 +23,6 @@ PyAPI_FUNC(void) _PyTuple_MaybeUntrack(PyObject *);
#define PyTuple_GET_ITEM(op, i) (_PyTuple_CAST(op)->ob_item[i])
/* Macro, *only* to be used to fill in brand new tuples */
-#define PyTuple_SET_ITEM(op, i, v) ((void)(_PyTuple_CAST(op)->ob_item[i] = v))
+#define PyTuple_SET_ITEM(op, i, v) _Py_RVALUE(_PyTuple_CAST(op)->ob_item[i] = (v))
PyAPI_FUNC(void) _PyTuple_DebugMallocStats(FILE *out);