diff options
| author | Paolo Bonzini <pbonzini@redhat.com> | 2024-06-25 13:12:20 +0200 |
|---|---|---|
| committer | Paolo Bonzini <pbonzini@redhat.com> | 2024-06-28 14:44:52 +0200 |
| commit | eb350d1d01d9b9df0ce174e2e1681699b071bab3 (patch) | |
| tree | 5391a9913aeefb22dc09fc702b1461d84298e241 /include/qapi/util.h | |
| parent | 7246c4cc470409bc77ae607463d1fcd026149d6a (diff) | |
| download | focaccia-qemu-eb350d1d01d9b9df0ce174e2e1681699b071bab3.tar.gz focaccia-qemu-eb350d1d01d9b9df0ce174e2e1681699b071bab3.zip | |
include: move typeof_strip_qual to compiler.h, use it in QAPI_LIST_LENGTH()
The typeof_strip_qual() is most useful for the atomic fetch-and-modify
operations in atomic.h, but it can be used elsewhere as well. For example,
QAPI_LIST_LENGTH() assumes that the argument is not const, which is not a
requirement.
Move the macro to compiler.h and, while at it, move it under #ifndef
__cplusplus to emphasize that it uses C-only constructs. A C++ version
of typeof_strip_qual() using type traits is possible[1], but beyond the
scope of this patch because the little C++ code that is in QEMU does not
use QAPI.
The patch was tested by changing the declaration of strv_from_str_list()
in qapi/qapi-type-helpers.c to:
char **strv_from_str_list(const strList *const list)
This is valid C code, and it fails to compile without this change.
[1] https://lore.kernel.org/qemu-devel/20240624205647.112034-1-flwu@google.com/
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Tested-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'include/qapi/util.h')
| -rw-r--r-- | include/qapi/util.h | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/include/qapi/util.h b/include/qapi/util.h index 20dfea8a54..b8254247b8 100644 --- a/include/qapi/util.h +++ b/include/qapi/util.h @@ -62,7 +62,7 @@ int parse_qapi_name(const char *name, bool complete); #define QAPI_LIST_LENGTH(list) \ ({ \ size_t _len = 0; \ - typeof(list) _tail; \ + typeof_strip_qual(list) _tail; \ for (_tail = list; _tail != NULL; _tail = _tail->next) { \ _len++; \ } \ |