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.
This commit is contained in:
Victor Stinner 2021-11-30 12:14:45 +01:00 committed by GitHub
parent f97ec09baf
commit c19c3a0961
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 11 additions and 7 deletions

View file

@ -129,4 +129,8 @@
Py_FatalError("Unreachable C code path reached")
#endif
// Prevent using an expression as a l-value.
// For example, "int x; _Py_RVALUE(x) = 1;" fails with a compiler error.
#define _Py_RVALUE(EXPR) ((void)0, (EXPR))
#endif /* Py_PYMACRO_H */