qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 02/17] meson: do not use set10


From: Richard Henderson
Subject: Re: [PATCH 02/17] meson: do not use set10
Date: Wed, 18 Oct 2023 17:06:43 -0700
User-agent: Mozilla Thunderbird

On 10/15/23 23:31, Paolo Bonzini wrote:
Make all items of config-host.h consistent.  To keep the 
--disable-coroutine-pool
code visible to the compiler, mutuate the IS_ENABLED() macro from Linux.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
  include/qemu/compiler.h     | 15 +++++++++++++++
  meson.build                 |  2 +-
  tests/unit/test-coroutine.c |  2 +-
  util/qemu-coroutine.c       |  4 ++--
  4 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
index 1109482a000..c797f0d4572 100644
--- a/include/qemu/compiler.h
+++ b/include/qemu/compiler.h
@@ -212,4 +212,19 @@
  # define QEMU_USED
  #endif
+/*
+ * Ugly CPP trick that is like "defined FOO", but also works in C
+ * code.  Useful to replace #ifdef with "if" statements; assumes
+ * the symbol was defined with Meson's "config.set()", so it is empty
+ * if defined.
+ */
+#define IS_ENABLED(x)                  IS_EMPTY(x)
+
+#define IS_EMPTY_JUNK_                 junk,
+#define IS_EMPTY(value)                IS_EMPTY_(IS_EMPTY_JUNK_##value)
+
+/* Expands to either SECOND_ARG(junk, 1, 0) or 
SECOND_ARG(IS_EMPTY_JUNK_CONFIG_FOO 1, 0)  */
+#define SECOND_ARG(first, second, ...) second
+#define IS_EMPTY_(junk_maybecomma)     SECOND_ARG(junk_maybecomma 1, 0)

Clever that.

However, if I had a preference I would go the other way and model after glibc:

Convert everything away from ifdef and always use set01.
Then enable -Wundef so that you catch typos in the usage of these macros.

But this is an improvement of a sort so,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~




reply via email to

[Prev in Thread] Current Thread [Next in Thread]