From 64cacd4564cb3b364780cc50452649cbabc9f2c5 Mon Sep 17 00:00:00 2001 From: Matt Borgerson Date: Thu, 12 Mar 2020 02:38:24 -0700 Subject: [PATCH] includes: Resolve some minor C++ incompatibilties --- include/qemu/bitmap.h | 10 +++++----- include/qemu/compiler.h | 4 ++++ include/qemu/timer.h | 2 +- include/qom/object.h | 10 ++++++++++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h index 82a1d2f41f..670d3577cc 100644 --- a/include/qemu/bitmap.h +++ b/include/qemu/bitmap.h @@ -70,7 +70,7 @@ unsigned long name[BITS_TO_LONGS(bits)] #define small_nbits(nbits) \ - ((nbits) <= BITS_PER_LONG) + ((unsigned long)(nbits) <= BITS_PER_LONG) int slow_bitmap_empty(const unsigned long *bitmap, long bits); int slow_bitmap_full(const unsigned long *bitmap, long bits); @@ -93,7 +93,7 @@ long slow_bitmap_count_one(const unsigned long *bitmap, long nbits); static inline unsigned long *bitmap_try_new(long nbits) { long len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); - return g_try_malloc0(len); + return (unsigned long *)g_try_malloc0(len); } static inline unsigned long *bitmap_new(long nbits) @@ -265,9 +265,9 @@ static inline unsigned long *bitmap_zero_extend(unsigned long *old, long old_nbits, long new_nbits) { long new_len = BITS_TO_LONGS(new_nbits) * sizeof(unsigned long); - unsigned long *new = g_realloc(old, new_len); - bitmap_clear(new, old_nbits, new_nbits - old_nbits); - return new; + unsigned long *new_ = (unsigned long *)g_realloc(old, new_len); + bitmap_clear(new_, old_nbits, new_nbits - old_nbits); + return new_; } void bitmap_to_le(unsigned long *dst, const unsigned long *src, diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h index c76281f354..f9f040463a 100644 --- a/include/qemu/compiler.h +++ b/include/qemu/compiler.h @@ -90,7 +90,11 @@ * message (but as it remains present in the source code, it can still * be useful when debugging). */ #if defined(CONFIG_STATIC_ASSERT) +#ifdef __cplusplus +#define QEMU_BUILD_BUG_MSG(x, msg) static_assert(!(x), msg) +#else #define QEMU_BUILD_BUG_MSG(x, msg) _Static_assert(!(x), msg) +#endif #elif defined(__COUNTER__) #define QEMU_BUILD_BUG_MSG(x, msg) typedef QEMU_BUILD_BUG_ON_STRUCT(x) \ glue(qemu_build_bug_on__, __COUNTER__) __attribute__((unused)) diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 6a8b48b5a9..a37dc4618c 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -527,7 +527,7 @@ static inline QEMUTimer *timer_new_full(QEMUTimerListGroup *timer_list_group, int scale, int attributes, QEMUTimerCB *cb, void *opaque) { - QEMUTimer *ts = g_malloc0(sizeof(QEMUTimer)); + QEMUTimer *ts = (QEMUTimer *)g_malloc0(sizeof(QEMUTimer)); timer_init_full(ts, timer_list_group, type, scale, attributes, cb, opaque); return ts; } diff --git a/include/qom/object.h b/include/qom/object.h index 784c97c0e1..91b68ba08f 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -14,6 +14,11 @@ #ifndef QEMU_OBJECT_H #define QEMU_OBJECT_H +#ifdef __cplusplus +#define class qom_class +#define typename qom_typename +#endif + #include "qapi/qapi-builtin-types.h" #include "qemu/module.h" @@ -1884,4 +1889,9 @@ char *object_property_help(const char *name, const char *type, G_DEFINE_AUTOPTR_CLEANUP_FUNC(Object, object_unref) +#ifdef __cplusplus +#undef class +#undef typename +#endif + #endif