summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-07-07 22:14:27 +0200
committerThomas Haller <thaller@redhat.com>2020-07-07 22:32:35 +0200
commit6feab75447468a90b3cbb43df0fce45595a691ac (patch)
treea2d0aec8a599244d63e86f842fe08f988e9b2ee0
parent1d6e208c12d0bbf25fb0d9081bec00ec30ea3aaa (diff)
downloadNetworkManager-6feab75447468a90b3cbb43df0fce45595a691ac.tar.gz
shared: add nm_steal_pointer()/nm_clear_free() to "nm-std-aux.h"
There is the team of nm_auto*, nm_clear_pointer() and nm_steal_pointer(). These goes nicely together so that an autovariable owns a resource, to free it (clear) and to transfer ownership (steal). We have these also in glib, but we certainly also need it if we don't have glib because that very much goes together with nm_auto*. Add it.
-rw-r--r--shared/nm-std-aux/nm-std-aux.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/shared/nm-std-aux/nm-std-aux.h b/shared/nm-std-aux/nm-std-aux.h
index 026fafdcc7..2351198930 100644
--- a/shared/nm-std-aux/nm-std-aux.h
+++ b/shared/nm-std-aux/nm-std-aux.h
@@ -520,4 +520,22 @@ NM_AUTO_DEFINE_FCN_VOID0 (void *, _nm_auto_free_impl, free)
_changed; \
})
+#define nm_clear_free(pp) nm_clear_pointer (pp, free)
+
+/*****************************************************************************/
+
+static inline void *
+_nm_steal_pointer (void *pp)
+{
+ void **ptr = (void **) pp;
+ void *ref;
+
+ ref = *ptr;
+ *ptr = NULL;
+ return ref;
+}
+
+#define nm_steal_pointer(pp) \
+ ((typeof (*(pp))) _nm_steal_pointer (pp))
+
#endif /* __NM_STD_AUX_H__ */