diff options
author | Thomas Haller <thaller@redhat.com> | 2020-11-02 10:08:09 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-11-02 22:29:54 +0100 |
commit | 8d2854df65abc6e9ebda8ac8612ba490d41331e4 (patch) | |
tree | 6cc44e94d6a9f23ada131b115e685d6a2dae6448 | |
parent | b2777ae14b732c54771e015a167f9895146762c2 (diff) | |
download | NetworkManager-8d2854df65abc6e9ebda8ac8612ba490d41331e4.tar.gz |
shared: add a compat implementation for g_atomic_pointer_get()
Had one job.
With glib2-2.67.0-1.fc34.x86_64.rpm, clang-11.0.0-2.fc34.x86_64.rpm, we
get a failure for g_atomic_pointer_get():
../shared/nm-glib-aux/nm-hash-utils.c:38:9: error: passing 'typeof (*(&global_seed)) *' (aka 'const unsigned char *volatile *') to parameter of type 'const guint8 **' (aka 'const unsigned char **') discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
g = g_atomic_pointer_get(&global_seed);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:112:38: note: expanded from macro 'g_atomic_pointer_get'
__atomic_load (gapg_temp_atomic, &gapg_temp_newval, __ATOMIC_SEQ_CST); \
^~~~~~~~~~~~~~~~~
../shared/nm-glib-aux/nm-hash-utils.c:109:32: error: passing 'typeof (*(&global_seed)) *' (aka 'const unsigned char *volatile *') to parameter of type 'const guint8 **' (aka 'const unsigned char **') discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
return ((*((const guint *) _get_hash_key())) ^ static_seed) ?: 3679500967u;
^~~~~~~~~~~~~~~
../shared/nm-glib-aux/nm-hash-utils.c:84:14: note: expanded from macro '_get_hash_key'
_g = g_atomic_pointer_get(&global_seed); \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:112:38: note: expanded from macro 'g_atomic_pointer_get'
__atomic_load (gapg_temp_atomic, &gapg_temp_newval, __ATOMIC_SEQ_CST); \
^~~~~~~~~~~~~~~~~
../shared/nm-glib-aux/nm-hash-utils.c:123:9: error: passing 'typeof (*(&global_seed)) *' (aka 'const unsigned char *volatile *') to parameter of type 'const guint8 **' (aka 'const unsigned char **') discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
g = _get_hash_key();
^~~~~~~~~~~~~~~
../shared/nm-glib-aux/nm-hash-utils.c:84:14: note: expanded from macro '_get_hash_key'
_g = g_atomic_pointer_get(&global_seed); \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:112:38: note: expanded from macro 'g_atomic_pointer_get'
__atomic_load (gapg_temp_atomic, &gapg_temp_newval, __ATOMIC_SEQ_CST); \
^~~~~~~~~~~~~~~~~
-rw-r--r-- | shared/nm-glib-aux/nm-glib.h | 51 |
1 files changed, 38 insertions, 13 deletions
diff --git a/shared/nm-glib-aux/nm-glib.h b/shared/nm-glib-aux/nm-glib.h index 7330b007a8..cb8969ffac 100644 --- a/shared/nm-glib-aux/nm-glib.h +++ b/shared/nm-glib-aux/nm-glib.h @@ -586,6 +586,30 @@ _nm_g_value_unset(GValue *value) /*****************************************************************************/ +/* g_atomic_pointer_get() is implemented as a macro, and it is also used for + * (gsize *) arguments. However, that leads to compiler warnings in certain + * configurations. Work around it, by redefining the macro. */ +static inline gpointer +_g_atomic_pointer_get(void **atomic) +{ + return g_atomic_pointer_get(atomic); +} +#undef g_atomic_pointer_get +#define g_atomic_pointer_get(atomic) \ + ({ \ + typeof(*atomic) *const _atomic = (atomic); \ + \ + /* g_atomic_pointer_get() is used by glib also for (gsize *) pointers, + * not only pointers to pointers. We thus don't enforce that (*atomic) + * is a pointer, but of suitable size/alignment. */ \ + \ + G_STATIC_ASSERT(sizeof(*_atomic) == sizeof(gpointer)); \ + G_STATIC_ASSERT(_nm_alignof(*_atomic) == _nm_alignof(gpointer)); \ + (void) (0 ? (gpointer) * (_atomic) : NULL); \ + \ + (typeof(*_atomic)) _g_atomic_pointer_get((void **) _atomic); \ + }) + /* Glib implements g_atomic_pointer_compare_and_exchange() as a macro. * For one, to inline the atomic operation and also to perform some type checks * on the arguments. @@ -594,22 +618,23 @@ _nm_g_value_unset(GValue *value) * pointers there. Reimplement the macro to get that right, but with stronger * type checks (as we use typeof()). Had one job. */ static inline gboolean -_g_atomic_pointer_compare_and_exchange(volatile void *atomic, - gconstpointer oldval, - gconstpointer newval) +_g_atomic_pointer_compare_and_exchange(void **atomic, void *oldval, void *newval) { - return g_atomic_pointer_compare_and_exchange((void **) atomic, - (void *) oldval, - (void *) newval); + return g_atomic_pointer_compare_and_exchange(atomic, oldval, newval); } #undef g_atomic_pointer_compare_and_exchange -#define g_atomic_pointer_compare_and_exchange(atomic, oldval, newval) \ - ({ \ - typeof(atomic) const _atomic = (atomic); \ - typeof(*_atomic) const _oldval = (oldval); \ - typeof(*_atomic) const _newval = (newval); \ - \ - _g_atomic_pointer_compare_and_exchange(_atomic, _oldval, _newval); \ +#define g_atomic_pointer_compare_and_exchange(atomic, oldval, newval) \ + ({ \ + typeof(*atomic) *const _atomic = (atomic); \ + typeof(*_atomic) const _oldval = (oldval); \ + typeof(*_atomic) const _newval = (newval); \ + _nm_unused gconstpointer const _val_type_check = _oldval; \ + \ + (void) (0 ? (gpointer) * (_atomic) : NULL); \ + \ + _g_atomic_pointer_compare_and_exchange((void **) _atomic, \ + (void *) _oldval, \ + (void *) _newval); \ }) /*****************************************************************************/ |