qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Emilio G . Cota" <cota@braap.org>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Fam Zheng <famz@redhat.com>
Subject: [Qemu-devel] [PATCH 1/5] compiler: add a helper for C99 inline functions
Date: Fri,  8 Dec 2017 11:55:49 +0100	[thread overview]
Message-ID: <20171208105553.12249-2-pbonzini@redhat.com> (raw)
In-Reply-To: <20171208105553.12249-1-pbonzini@redhat.com>

C99 inline functions are useful whenever a function provide an
abstraction that is generally expected to be inlined away, but
yet a function pointer might be needed.  One such case is function
passed to GCC's cleanup attribute.

Unfortunately, C99 inline functions clash a bit with -Wredundant-decls.
Provide a helper macro to hide the ugliness.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 include/qemu/compiler.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
index 340e5fdc09..e02b73b9e2 100644
--- a/include/qemu/compiler.h
+++ b/include/qemu/compiler.h
@@ -94,6 +94,21 @@
 #define QEMU_BUILD_BUG_ON_ZERO(x) (sizeof(QEMU_BUILD_BUG_ON_STRUCT(x)) - \
                                    sizeof(QEMU_BUILD_BUG_ON_STRUCT(x)))
 
+/* Provide an extern declaration for a C99 inline function.  This can
+ * be simply placed in a C file but, unfortunately, this means the
+ * declaration comes after the inline definition, and GCC thus
+ * stubbornly raises a -Wredundant-decls warning.
+ *
+ * Putting the declaration before the header would be uglier (it couldn't
+ * just use typeof) and not always possible if the function requires types
+ * that are defined in the header.  Therefore, we just shut up the warning.
+ */
+#define QEMU_EXTERN_INLINE(func)                             \
+    _Pragma("GCC diagnostic push");                          \
+    _Pragma("GCC diagnostic ignored \"-Wredundant-decls\""); \
+    extern typeof(func) func;                                \
+    _Pragma("GCC diagnostic pop")                            \
+
 #if defined __GNUC__
 # if !QEMU_GNUC_PREREQ(4, 4)
    /* gcc versions before 4.4.x don't support gnu_printf, so use printf. */
-- 
2.14.3

  reply	other threads:[~2017-12-08 10:56 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-08 10:55 [Qemu-devel] [RFC PATCH 0/5] Scoped locks using attribute((cleanup)) Paolo Bonzini
2017-12-08 10:55 ` Paolo Bonzini [this message]
2017-12-08 10:55 ` [Qemu-devel] [PATCH 2/5] lock-guard: add scoped lock implementation Paolo Bonzini
2017-12-08 15:30   ` Stefan Hajnoczi
2017-12-08 17:56     ` Paolo Bonzini
2017-12-08 20:12       ` Eric Blake
2017-12-11 10:16       ` Stefan Hajnoczi
2017-12-11 13:51         ` Eric Blake
2017-12-12  9:16           ` Stefan Hajnoczi
2017-12-08 10:55 ` [Qemu-devel] [PATCH 3/5] qemu-timer: convert to use lock guards Paolo Bonzini
2017-12-08 14:26   ` Stefan Hajnoczi
2017-12-08 10:55 ` [Qemu-devel] [PATCH 4/5] qht: " Paolo Bonzini
2017-12-08 14:27   ` Stefan Hajnoczi
2017-12-08 10:55 ` [Qemu-devel] [PATCH 5/5] thread-pool: " Paolo Bonzini
2017-12-08 15:13   ` Stefan Hajnoczi
2017-12-08 18:12     ` Paolo Bonzini
2017-12-08 20:02       ` Eric Blake
2017-12-11 10:23         ` Stefan Hajnoczi
2017-12-11 22:03           ` Paolo Bonzini
2017-12-08 19:50     ` Eric Blake
2017-12-11  6:35     ` Peter Xu
2017-12-08 19:40 ` [Qemu-devel] [RFC PATCH 0/5] Scoped locks using attribute((cleanup)) Eric Blake
2017-12-11  9:38   ` Peter Maydell
2017-12-11 14:11     ` Eric Blake
2017-12-11 21:32       ` Paolo Bonzini
2017-12-12 20:41         ` Eric Blake
2017-12-15 15:50           ` Richard Henderson
2017-12-11  6:40 ` no-reply
2017-12-11  6:40 ` no-reply
2017-12-11  6:46 ` no-reply
2017-12-11 22:06 ` Emilio G. Cota

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171208105553.12249-2-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=cota@braap.org \
    --cc=famz@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).