NetworkManager/shared
Thomas Haller d8cc6af058 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)
2019-12-13 13:48:00 +01:00
..
c-list shared/c-list: reimport 2019-04-14 17:22:04 +02:00
c-rbtree shared/c-rbtree: reimport 2019-04-14 17:23:01 +02:00
c-siphash shared/c-siphash: reimport 2019-04-14 17:23:25 +02:00
c-stdaux shared: patch c-stdaux.h to not include <stdatomic.h> 2019-04-14 17:17:52 +02:00
n-acd n-acd: fix leaking socket handle in n_acd_socket_new() when setsockopt() fails 2019-08-02 11:26:25 +02:00
n-dhcp4 n-dhcp4/socket: use SO_REUSEADDR on UDP socket 2019-12-11 09:25:05 +01:00
nm-glib-aux shared/glib: reimplement g_atomic_pointer_compare_and_exchange() macro 2019-12-13 13:48:00 +01:00
nm-libnm-core-aux all: unify format of our Copyright source code comments 2019-10-02 17:03:52 +02:00
nm-libnm-core-intern dhcp: support FQDN flags in the dhclient backend 2019-11-28 17:56:35 +01:00
nm-std-aux all: unify format of our Copyright source code comments 2019-10-02 17:03:52 +02:00
nm-udev-aux all: manually drop code comments with file description 2019-10-01 07:50:52 +02:00
nm-utils shared/tests: add nmtst_main_context_iterate_until() helper 2019-11-07 11:34:36 +01:00
systemd systemd: merge branch systemd into master 2019-11-29 13:14:05 +01:00
meson.build shared: cleanup include guard for nm-logging-fwd.h 2019-11-28 19:20:33 +01:00
nm-default.h libnm: include "nm-libnm-utils.h" by default in libnm sources 2019-10-18 22:09:18 +02:00
nm-meta-setting.c all: unify format of our Copyright source code comments 2019-10-02 17:03:52 +02:00
nm-meta-setting.h all: unify format of our Copyright source code comments 2019-10-02 17:03:52 +02:00
nm-test-libnm-utils.h tests: add nmtstc_client_new() helper 2019-11-07 11:34:36 +01:00
nm-test-utils-impl.c libnm: refactor caching of D-Bus objects in NMClient 2019-11-25 15:08:00 +01:00
nm-version-macros.h.in all: unify format of our Copyright source code comments 2019-10-02 17:03:52 +02:00