diff options
author | Philip Withnall <philip@tecnocode.co.uk> | 2018-07-17 09:27:12 +0000 |
---|---|---|
committer | Philip Withnall <philip@tecnocode.co.uk> | 2018-07-17 09:27:12 +0000 |
commit | 16c6a735866c63abaef78d5fdb2bad84be5a5a03 (patch) | |
tree | a6fb5ab4a25940d5aa3f8f246535fda8ad9bbc06 | |
parent | 4dc6a01241f4313f8fad866cbcb5a3fd703b9974 (diff) | |
parent | 4c621fb7eeadb389c22c8ad17f736c70d56ee3e0 (diff) | |
download | glib-16c6a735866c63abaef78d5fdb2bad84be5a5a03.tar.gz |
Merge branch 'add-g-has-typeof-1440' into 'master'
gmacros: Add new private g_has_typeof to abstract __typeof__ checks
Closes #1440
See merge request GNOME/glib!172
-rw-r--r-- | glib/gmacros.h | 12 | ||||
-rw-r--r-- | glib/gmem.h | 2 | ||||
-rw-r--r-- | glib/grcbox.h | 2 | ||||
-rw-r--r-- | gobject/gobject.h | 2 |
4 files changed, 15 insertions, 3 deletions
diff --git a/glib/gmacros.h b/glib/gmacros.h index cfeb9a00b..9b8ef0e89 100644 --- a/glib/gmacros.h +++ b/glib/gmacros.h @@ -111,6 +111,18 @@ #endif /* + * We can only use __typeof__ on GCC >= 4.8, and not when compiling C++. Since + * __typeof__ is used in a few places in GLib, provide a pre-processor symbol + * to factor the check out from callers. + * + * This symbol is private. + */ +#undef g_has_typeof +#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)) && !defined(__cplusplus) +#define g_has_typeof +#endif + +/* * Clang feature detection: http://clang.llvm.org/docs/LanguageExtensions.html * These are not available on GCC, but since the pre-processor doesn't do * operator short-circuiting, we can't use it in a statement or we'll get: diff --git a/glib/gmem.h b/glib/gmem.h index 302809478..1860d014f 100644 --- a/glib/gmem.h +++ b/glib/gmem.h @@ -110,7 +110,7 @@ gpointer g_try_realloc_n (gpointer mem, gsize n_blocks, gsize n_block_bytes) G_GNUC_WARN_UNUSED_RESULT; -#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)) && !defined(__cplusplus) && GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_58 +#if defined(g_has_typeof) && GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_58 #define g_clear_pointer(pp, destroy) \ G_STMT_START { \ G_STATIC_ASSERT (sizeof *(pp) == sizeof (gpointer)); \ diff --git a/glib/grcbox.h b/glib/grcbox.h index 23b417f09..e66f1ff6d 100644 --- a/glib/grcbox.h +++ b/glib/grcbox.h @@ -71,7 +71,7 @@ gsize g_atomic_rc_box_get_size (gpointer mem_block); #define g_atomic_rc_box_new0(type) \ ((type *) g_atomic_rc_box_alloc0 (sizeof (type))) -#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)) && !defined(_cplusplus) +#ifdef g_has_typeof /* Type check to avoid assigning references to different types */ # define g_rc_box_acquire(mem_block) \ ((__typeof__(mem_block)) (g_rc_box_acquire) (mem_block)) diff --git a/gobject/gobject.h b/gobject/gobject.h index 9abe87330..b5648f137 100644 --- a/gobject/gobject.h +++ b/gobject/gobject.h @@ -507,7 +507,7 @@ GLIB_AVAILABLE_IN_ALL void g_object_remove_weak_pointer (GObject *object, gpointer *weak_pointer_location); -#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)) && !defined(__cplusplus) && GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_56 +#if defined(g_has_typeof) && GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_56 /* Make reference APIs type safe with macros */ #define g_object_ref(Obj) ((__typeof__(Obj)) (g_object_ref) (Obj)) #define g_object_ref_sink(Obj) ((__typeof__(Obj)) (g_object_ref_sink) (Obj)) |