From 4a00bcf5a6a8ad37d5bebd13dc640992cc104c18 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 12 Mar 2016 15:38:53 +0100 Subject: [PATCH] shared: add nm_g_object_ref() and nm_g_object_unref() function --- shared/nm-macros-internal.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/shared/nm-macros-internal.h b/shared/nm-macros-internal.h index dafce87795..1f638bab18 100644 --- a/shared/nm-macros-internal.h +++ b/shared/nm-macros-internal.h @@ -313,6 +313,26 @@ _notify (obj_type *obj, _PropertyEnums prop) \ /*****************************************************************************/ +static inline gpointer +nm_g_object_ref (gpointer obj) +{ + /* g_object_ref() doesn't accept NULL. */ + if (obj) + g_object_ref (obj); + return obj; +} + +static inline void +nm_g_object_unref (gpointer obj) +{ + /* g_object_unref() doesn't accept NULL. Usully, we workaround that + * by using g_clear_object(), but sometimes that is not convinient + * (for example as as destroy function for a hash table that can contain + * NULL values). */ + if (obj) + g_object_unref (obj); +} + static inline gboolean nm_clear_g_source (guint *id) {