diff options
author | Thomas Haller <thaller@redhat.com> | 2020-07-20 15:17:36 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-07-23 15:29:23 +0200 |
commit | 97770bc7a834158dad449b09cc70991b7409f91f (patch) | |
tree | a8c6ccb9a8ddeab5bfebee39b01b3627e920c1fc /shared/nm-glib-aux/nm-macros-internal.h | |
parent | ace515e697798659df5fc958e53765c94f8c1574 (diff) | |
download | NetworkManager-97770bc7a834158dad449b09cc70991b7409f91f.tar.gz |
shared: add nm_g_object_ref_set_take() helper macro
Diffstat (limited to 'shared/nm-glib-aux/nm-macros-internal.h')
-rw-r--r-- | shared/nm-glib-aux/nm-macros-internal.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/shared/nm-glib-aux/nm-macros-internal.h b/shared/nm-glib-aux/nm-macros-internal.h index 41f701f98e..a8a5360548 100644 --- a/shared/nm-glib-aux/nm-macros-internal.h +++ b/shared/nm-glib-aux/nm-macros-internal.h @@ -825,6 +825,26 @@ nm_g_object_unref (gpointer obj) _changed; \ }) +#define nm_g_object_ref_set_take(pp, obj) \ + ({ \ + typeof (*(pp)) *const _pp = (pp); \ + typeof (*_pp) const _obj = (obj); \ + typeof (*_pp) _p; \ + gboolean _changed = FALSE; \ + \ + nm_assert (!_pp || !*_pp || G_IS_OBJECT (*_pp)); \ + nm_assert (!_obj || G_IS_OBJECT (_obj)); \ + \ + if ( _pp \ + && ((_p = *_pp) != _obj)) { \ + *_pp = _obj; \ + nm_g_object_unref (_p); \ + _changed = TRUE; \ + } else \ + nm_g_object_unref (_obj); \ + _changed; \ + }) + /* basically, replaces * g_clear_pointer (&location, g_free) * with |