[Python-checkins] Support Py_UNUSED() on clang (GH-13544)

Victor Stinner webhook-mailer at python.org
Fri May 24 09:16:15 EDT 2019


https://github.com/python/cpython/commit/b3a9843cd19039808a812ca11206881c94c64e3b
commit: b3a9843cd19039808a812ca11206881c94c64e3b
branch: master
author: Victor Stinner <vstinner at redhat.com>
committer: GitHub <noreply at github.com>
date: 2019-05-24T15:16:08+02:00
summary:

Support Py_UNUSED() on clang (GH-13544)

files:
M Doc/c-api/intro.rst
M Include/pymacro.h

diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst
index b003bbaeff2f..672936a458f4 100644
--- a/Doc/c-api/intro.rst
+++ b/Doc/c-api/intro.rst
@@ -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
 
diff --git a/Include/pymacro.h b/Include/pymacro.h
index 546f9c6e7020..1890619099a3 100644
--- a/Include/pymacro.h
+++ b/Include/pymacro.h
@@ -89,10 +89,15 @@
 /* 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__
-#define Py_UNUSED(name) _unused_ ## name __attribute__((unused))
+/* 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
+#  define Py_UNUSED(name) _unused_ ## name
 #endif
 
 #define Py_UNREACHABLE() abort()



More information about the Python-checkins mailing list