NetworkManager/shared/nm-glib-aux
Thomas Haller a4f735029a shared/glib: reimplement g_atomic_pointer_compare_and_exchange() macro
With glib 2.63.2 and clang 9.0.0 (Fedora 32) we get compile errors:

  ../clients/cloud-setup/nmcs-provider-ec2.c:51:8: error: incompatible pointer types passing 'typeof ((((void *)0))) *' (aka 'void **') to parameter of type 'const char **' [-Werror,-Wincompatible-pointer-types]
                  if (!g_atomic_pointer_compare_and_exchange (&base_cached, NULL, base))
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  /usr/include/glib-2.0/glib/gatomic.h:192:44: note: expanded from macro 'g_atomic_pointer_compare_and_exchange'
      __atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \
                                             ^~~~~~~~~~~~~~
  ../src/devices/bluetooth/nm-bluez-manager.c:2836:2: error: incompatible pointer types passing 'typeof ((((void *)0))) *' (aka 'void **') to parameter of type 'const NMBtVTableNetworkServer **' (aka 'const struct _NMBtVTableNetworkServer **') [-Werror,-Wincompatible-pointer-types]
          g_atomic_pointer_compare_and_exchange (&nm_bt_vtable_network_server, NULL, &priv->vtable_network_server);
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  /usr/include/glib-2.0/glib/gatomic.h:192:44: note: expanded from macro 'g_atomic_pointer_compare_and_exchange'
      __atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \
                                             ^~~~~~~~~~~~~~
  ../src/devices/bluetooth/nm-bluez-manager.c:2853:2: error: passing 'typeof ((&priv->vtable_network_server)) *' (aka 'struct _NMBtVTableNetworkServer **') to parameter of type 'const NMBtVTableNetworkServer **' (aka 'const struct _NMBtVTableNetworkServer **') discards qualifiers in nested pointer types [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
          g_atomic_pointer_compare_and_exchange (&nm_bt_vtable_network_server, &priv->vtable_network_server, NULL);
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  /usr/include/glib-2.0/glib/gatomic.h:192:44: note: expanded from macro 'g_atomic_pointer_compare_and_exchange'
      __atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \
                                             ^~~~~~~~~~~~~~
  ../src/devices/nm-device.c:8857:8: error: incompatible pointer types passing 'typeof ((((void *)0))) *' (aka 'void **') to parameter of type 'GBytes **' (aka 'struct _GBytes **') [-Werror,-Wincompatible-pointer-types]
                  if (!g_atomic_pointer_compare_and_exchange (&global_duid, NULL, p)) {
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  /usr/include/glib-2.0/glib/gatomic.h:192:44: note: expanded from macro 'g_atomic_pointer_compare_and_exchange'
      __atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \
                                             ^~~~~~~~~~~~~~

The issue happens because glib passes the "atomic" argument to

  __atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)

without cast, and clang 9 seems to be picky about const pointers.
Add our own version of the macro that does better casts while also having
better compile time checks for valid arguments.

(cherry picked from commit f5b0713651)
(cherry picked from commit d8cc6af058)
(cherry picked from commit 925a688400)
2020-04-20 11:38:47 +02:00
..
nm-c-list.h shared: move most of "shared/nm-utils" to "shared/nm-glib-aux" 2019-04-18 19:57:27 +02:00
nm-dedup-multi.c shared: move most of "shared/nm-utils" to "shared/nm-glib-aux" 2019-04-18 19:57:27 +02:00
nm-dedup-multi.h shared: move most of "shared/nm-utils" to "shared/nm-glib-aux" 2019-04-18 19:57:27 +02:00
nm-enum-utils.c shared: move most of "shared/nm-utils" to "shared/nm-glib-aux" 2019-04-18 19:57:27 +02:00
nm-enum-utils.h shared: move most of "shared/nm-utils" to "shared/nm-glib-aux" 2019-04-18 19:57:27 +02:00
nm-errno.c shared: move most of "shared/nm-utils" to "shared/nm-glib-aux" 2019-04-18 19:57:27 +02:00
nm-errno.h shared: move most of "shared/nm-utils" to "shared/nm-glib-aux" 2019-04-18 19:57:27 +02:00
nm-glib.h shared/glib: reimplement g_atomic_pointer_compare_and_exchange() macro 2020-04-20 11:38:47 +02:00
nm-hash-utils.c shared: move most of "shared/nm-utils" to "shared/nm-glib-aux" 2019-04-18 19:57:27 +02:00
nm-hash-utils.h shared: move most of "shared/nm-utils" to "shared/nm-glib-aux" 2019-04-18 19:57:27 +02:00
nm-io-utils.c shared: move most of "shared/nm-utils" to "shared/nm-glib-aux" 2019-04-18 19:57:27 +02:00
nm-io-utils.h shared: move most of "shared/nm-utils" to "shared/nm-glib-aux" 2019-04-18 19:57:27 +02:00
nm-jansson.h shared: move most of "shared/nm-utils" to "shared/nm-glib-aux" 2019-04-18 19:57:27 +02:00
nm-logging-fwd.h shared: move most of "shared/nm-utils" to "shared/nm-glib-aux" 2019-04-18 19:57:27 +02:00
nm-macros-internal.h shared: fix _NM_ENSURE_TYPE_CONST() for const pointers with clang 2019-10-08 15:26:50 +02:00
nm-obj.h shared: move most of "shared/nm-utils" to "shared/nm-glib-aux" 2019-04-18 19:57:27 +02:00
nm-random-utils.c shared: move most of "shared/nm-utils" to "shared/nm-glib-aux" 2019-04-18 19:57:27 +02:00
nm-random-utils.h shared: move most of "shared/nm-utils" to "shared/nm-glib-aux" 2019-04-18 19:57:27 +02:00
nm-secret-utils.c shared: move most of "shared/nm-utils" to "shared/nm-glib-aux" 2019-04-18 19:57:27 +02:00
nm-secret-utils.h shared: move most of "shared/nm-utils" to "shared/nm-glib-aux" 2019-04-18 19:57:27 +02:00
nm-shared-utils.c shared: use nm_str_skip_leading_spaces() in _nm_utils_ascii_str_to_int64() 2019-05-15 14:07:07 +02:00
nm-shared-utils.h ifcfg-rh: preserve existence of wired setting 2019-05-28 11:35:03 +02:00
nm-time-utils.c all: fix typos (milli seconds -> milliseconds) 2019-05-08 13:44:22 +02:00
nm-time-utils.h shared: move most of "shared/nm-utils" to "shared/nm-glib-aux" 2019-04-18 19:57:27 +02:00