[glib: 1/5] Replace __typeof__ with glib_typeof macro




commit 5b2bee3f539056b42c802608f9f00cc9ddd64b79
Author: Xavier Claessens <xavier claessens collabora com>
Date:   Sat Jul 25 15:05:51 2020 -0400

    Replace __typeof__ with glib_typeof macro
    
    g_has_typeof macro is wrongly in the public g_ namespace, internaly
    symbols are usually in the glib_ namespace. This will also allow to
    define glib_typeof differently on non-GNUC compilers (e.g. c++11
    decltype).

 docs/reference/glib/glib-sections.txt |  2 +-
 gio/gcredentials.c                    |  2 +-
 glib/gatomic.h                        | 42 +++++++++++++++++------------------
 glib/gmacros.h                        |  4 ++--
 glib/gmem.h                           | 24 +++++++++++---------
 glib/grcbox.h                         | 18 +++++++--------
 gobject/gobject.h                     |  6 ++---
 7 files changed, 50 insertions(+), 48 deletions(-)
---
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index 6c1c86198..dc229b394 100644
--- a/docs/reference/glib/glib-sections.txt
+++ b/docs/reference/glib/glib-sections.txt
@@ -730,7 +730,7 @@ GLIB_UNAVAILABLE_TYPE
 G_ANALYZER_ANALYZING
 G_ANALYZER_NORETURN
 g_autoptr_cleanup_generic_gfree
-g_has_typeof
+glib_typeof
 g_macro__has_attribute
 g_macro__has_builtin
 g_macro__has_feature
diff --git a/gio/gcredentials.c b/gio/gcredentials.c
index 146829e7c..9423f9ef9 100644
--- a/gio/gcredentials.c
+++ b/gio/gcredentials.c
@@ -225,7 +225,7 @@ g_credentials_to_string (GCredentials *credentials)
 {
   GString *ret;
 #if G_CREDENTIALS_USE_APPLE_XUCRED
-  __typeof__(credentials->native.cr_ngroups) i;
+  glib_typeof (credentials->native.cr_ngroups) i;
 #endif
 
   g_return_val_if_fail (G_IS_CREDENTIALS (credentials), NULL);
diff --git a/glib/gatomic.h b/glib/gatomic.h
index 6bf41bb74..7ab11a5d0 100644
--- a/glib/gatomic.h
+++ b/glib/gatomic.h
@@ -103,24 +103,24 @@ G_END_DECLS
     __atomic_store ((gint *)(atomic), &gais_temp, __ATOMIC_SEQ_CST);         \
   }))
 
-#if defined(g_has_typeof)
-#define g_atomic_pointer_get(atomic) \
-  (G_GNUC_EXTENSION ({                                                       \
-    G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer));                 \
-    __typeof__(*(atomic)) gapg_temp_newval;                                  \
-    __typeof__((atomic)) gapg_temp_atomic = (atomic);                        \
-    __atomic_load (gapg_temp_atomic, &gapg_temp_newval, __ATOMIC_SEQ_CST);   \
-    gapg_temp_newval;                                                        \
-  }))
-#define g_atomic_pointer_set(atomic, newval) \
-  (G_GNUC_EXTENSION ({                                                       \
-    G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer));                 \
-    __typeof__((atomic)) gaps_temp_atomic = (atomic);                        \
-    __typeof__(*(atomic)) gaps_temp_newval = (newval);                       \
-    (void) (0 ? (gpointer) *(atomic) : NULL);                                \
-    __atomic_store (gaps_temp_atomic, &gaps_temp_newval, __ATOMIC_SEQ_CST);  \
-  }))
-#else  /* if !defined(g_has_typeof) */
+#if defined(glib_typeof)
+#define g_atomic_pointer_get(atomic)                                       \
+  (G_GNUC_EXTENSION ({                                                     \
+    G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer));               \
+    glib_typeof (*(atomic)) gapg_temp_newval;                              \
+    glib_typeof ((atomic)) gapg_temp_atomic = (atomic);                    \
+    __atomic_load (gapg_temp_atomic, &gapg_temp_newval, __ATOMIC_SEQ_CST); \
+    gapg_temp_newval;                                                      \
+  }))
+#define g_atomic_pointer_set(atomic, newval)                                \
+  (G_GNUC_EXTENSION ({                                                      \
+    G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer));                \
+    glib_typeof ((atomic)) gaps_temp_atomic = (atomic);                     \
+    glib_typeof (*(atomic)) gaps_temp_newval = (newval);                    \
+    (void) (0 ? (gpointer) * (atomic) : NULL);                              \
+    __atomic_store (gaps_temp_atomic, &gaps_temp_newval, __ATOMIC_SEQ_CST); \
+  }))
+#else /* if !defined(glib_typeof) */
 #define g_atomic_pointer_get(atomic) \
   (G_GNUC_EXTENSION ({                                                       \
     G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer));                 \
@@ -137,7 +137,7 @@ G_END_DECLS
     (void) (0 ? (gpointer) *(atomic) : NULL);                                \
     __atomic_store (gaps_temp_atomic, &gaps_temp_newval, __ATOMIC_SEQ_CST);  \
   }))
-#endif  /* !defined(g_has_typeof) */
+#endif /* !defined(glib_typeof) */
 
 #define g_atomic_int_inc(atomic) \
   (G_GNUC_EXTENSION ({                                                       \
@@ -186,7 +186,7 @@ G_END_DECLS
 #define g_atomic_pointer_compare_and_exchange(atomic, oldval, newval) \
   (G_GNUC_EXTENSION ({                                                       \
     G_STATIC_ASSERT (sizeof (oldval) == sizeof (gpointer));                  \
-    __typeof__ ((oldval)) gapcae_oldval = (oldval);                          \
+    glib_typeof ((oldval)) gapcae_oldval = (oldval);                         \
     G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer));                 \
     (void) (0 ? (gpointer) *(atomic) : NULL);                                \
     __atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, 
__ATOMIC_SEQ_CST) ? TRUE : FALSE; \
@@ -289,7 +289,7 @@ G_END_DECLS
     (void) (0 ? (gpointer) *(atomic) : NULL);                                \
     __sync_synchronize ();                                                   \
     __asm__ __volatile__ ("" : : : "memory");                                \
-    *(atomic) = (__typeof__ (*(atomic))) (gsize) (newval);                   \
+    *(atomic) = (glib_typeof (*(atomic))) (gsize) (newval);                  \
   }))
 
 #define g_atomic_int_inc(atomic) \
diff --git a/glib/gmacros.h b/glib/gmacros.h
index d953de4c8..01139b271 100644
--- a/glib/gmacros.h
+++ b/glib/gmacros.h
@@ -231,9 +231,9 @@
  *
  * This symbol is private.
  */
-#undef g_has_typeof
+#undef glib_typeof
 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)) && !defined(__cplusplus)
-#define g_has_typeof
+#define glib_typeof(t) __typeof__ (t)
 #endif
 
 /*
diff --git a/glib/gmem.h b/glib/gmem.h
index 45671073b..10879d1ea 100644
--- a/glib/gmem.h
+++ b/glib/gmem.h
@@ -110,16 +110,18 @@ gpointer g_try_realloc_n  (gpointer        mem,
                           gsize         n_blocks,
                           gsize         n_block_bytes) G_GNUC_WARN_UNUSED_RESULT;
 
-#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));                       \
-    __typeof__((pp)) _pp = (pp);                                               \
-    __typeof__(*(pp)) _ptr = *_pp;                                             \
-    *_pp = NULL;                                                               \
-    if (_ptr)                                                                  \
-      (destroy) (_ptr);                                                        \
-  } G_STMT_END                                                                 \
+#if defined(glib_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)); \
+    glib_typeof ((pp)) _pp = (pp);                       \
+    glib_typeof (*(pp)) _ptr = *_pp;                     \
+    *_pp = NULL;                                         \
+    if (_ptr)                                            \
+      (destroy) (_ptr);                                  \
+  }                                                      \
+  G_STMT_END                                             \
   GLIB_AVAILABLE_MACRO_IN_2_34
 #else /* __GNUC__ */
 #define g_clear_pointer(pp, destroy) \
@@ -212,7 +214,7 @@ g_steal_pointer (gpointer pp)
 
 /* type safety */
 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)) && !defined(__cplusplus) 
&& GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_58
-#define g_steal_pointer(pp) ((__typeof__(*pp)) (g_steal_pointer) (pp))
+#define g_steal_pointer(pp) ((glib_typeof (*pp)) (g_steal_pointer) (pp))
 #else  /* __GNUC__ */
 /* This version does not depend on gcc extensions, but gcc does not warn
  * about incompatible-pointer-types: */
diff --git a/glib/grcbox.h b/glib/grcbox.h
index c92791260..f78f5cb3b 100644
--- a/glib/grcbox.h
+++ b/glib/grcbox.h
@@ -71,18 +71,18 @@ 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)))
 
-#ifdef g_has_typeof
+#ifdef glib_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))
-# define g_atomic_rc_box_acquire(mem_block) \
-  ((__typeof__(mem_block)) (g_atomic_rc_box_acquire) (mem_block))
+#define g_rc_box_acquire(mem_block) \
+  ((glib_typeof (mem_block)) (g_rc_box_acquire) (mem_block))
+#define g_atomic_rc_box_acquire(mem_block) \
+  ((glib_typeof (mem_block)) (g_atomic_rc_box_acquire) (mem_block))
 
 /* Type check to avoid duplicating data to different types */
-# define g_rc_box_dup(block_size,mem_block) \
-  ((__typeof__(mem_block)) (g_rc_box_dup) (block_size,mem_block))
-# define g_atomic_rc_box_dup(block_size,mem_block) \
-  ((__typeof__(mem_block)) (g_atomic_rc_box_dup) (block_size,mem_block))
+#define g_rc_box_dup(block_size, mem_block) \
+  ((glib_typeof (mem_block)) (g_rc_box_dup) (block_size, mem_block))
+#define g_atomic_rc_box_dup(block_size, mem_block) \
+  ((glib_typeof (mem_block)) (g_atomic_rc_box_dup) (block_size, mem_block))
 #endif
 
 G_END_DECLS
diff --git a/gobject/gobject.h b/gobject/gobject.h
index 499329af2..bf5496c54 100644
--- a/gobject/gobject.h
+++ b/gobject/gobject.h
@@ -513,10 +513,10 @@ GLIB_AVAILABLE_IN_ALL
 void        g_object_remove_weak_pointer      (GObject        *object, 
                                                gpointer       *weak_pointer_location);
 
-#if defined(g_has_typeof) && GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_56
+#if defined(glib_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))
+#define g_object_ref(Obj) ((glib_typeof (Obj)) (g_object_ref) (Obj))
+#define g_object_ref_sink(Obj) ((glib_typeof (Obj)) (g_object_ref_sink) (Obj))
 #endif
 
 /**


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