[Python-checkins] bpo-30459: Cast the result of PyList_SET_ITEM() to void (GH-19975)

vstinner webhook-mailer at python.org
Sat Dec 5 05:35:21 EST 2020


https://github.com/python/cpython/commit/556d97f473fa538cef780f84bd29239ecf57d9c5
commit: 556d97f473fa538cef780f84bd29239ecf57d9c5
branch: master
author: Zackery Spytz <zspytz at gmail.com>
committer: vstinner <vstinner at python.org>
date: 2020-12-05T11:34:51+01:00
summary:

bpo-30459: Cast the result of PyList_SET_ITEM() to void (GH-19975)

Do the same for PyTuple_SET_ITEM().

files:
A Misc/NEWS.d/next/C API/2020-05-06-23-54-57.bpo-30459.N9_Jai.rst
M Include/cpython/listobject.h
M Include/cpython/tupleobject.h

diff --git a/Include/cpython/listobject.h b/Include/cpython/listobject.h
index e1b9462d5b361..e3239152c497c 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) (_PyList_CAST(op)->ob_item[i] = (v))
+#define PyList_SET_ITEM(op, i, v) ((void)(_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 51dcd4237be18..7cada8848c49f 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) (_PyTuple_CAST(op)->ob_item[i] = v)
+#define PyTuple_SET_ITEM(op, i, v) ((void)(_PyTuple_CAST(op)->ob_item[i] = v))
 
 PyAPI_FUNC(void) _PyTuple_DebugMallocStats(FILE *out);
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
new file mode 100644
index 0000000000000..e3ee6dccdaa76
--- /dev/null
+++ b/Misc/NEWS.d/next/C API/2020-05-06-23-54-57.bpo-30459.N9_Jai.rst	
@@ -0,0 +1,2 @@
+Cast the result of :c:func:`PyList_SET_ITEM` and :c:func:`PyTuple_SET_ITEM`
+to void.



More information about the Python-checkins mailing list