mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-11 11:56:16 +01:00
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).
This commit is contained in:
parent
2954754cb3
commit
5b2bee3f53
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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; \
|
||||
#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)); \
|
||||
__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); \
|
||||
#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(g_has_typeof) */
|
||||
#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) \
|
||||
|
@ -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
|
||||
|
||||
/*
|
||||
|
24
glib/gmem.h
24
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: */
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user