Support Py_UNUSED() on clang (GH-13544)

This commit is contained in:
Victor Stinner 2019-05-24 15:16:08 +02:00 committed by GitHub
parent b4bdecd0fc
commit b3a9843cd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View File

@ -156,7 +156,7 @@ complete listing.
.. c:macro:: Py_UNUSED(arg)
Use this for unused arguments in a function definition to silence compiler
warnings, e.g. ``PyObject* func(PyObject *Py_UNUSED(ignored))``.
warnings. Example: ``int func(int a, int Py_UNUSED(b)) { return a; }``.
.. versionadded:: 3.4

View File

@ -89,7 +89,12 @@
/* Check if pointer "p" is aligned to "a"-bytes boundary. */
#define _Py_IS_ALIGNED(p, a) (!((uintptr_t)(p) & (uintptr_t)((a) - 1)))
#ifdef __GNUC__
/* Use this for unused arguments in a function definition to silence compiler
* warnings. Example:
*
* int func(int a, int Py_UNUSED(b)) { return a; }
*/
#if defined(__GNUC__) || defined(__clang__)
# define Py_UNUSED(name) _unused_ ## name __attribute__((unused))
#else
# define Py_UNUSED(name) _unused_ ## name