shared: add nm_g_object_ref() and nm_g_object_unref() function
authorThomas Haller <thaller@redhat.com>
Sat, 12 Mar 2016 14:38:53 +0000 (15:38 +0100)
committerThomas Haller <thaller@redhat.com>
Sun, 13 Mar 2016 11:31:04 +0000 (12:31 +0100)
shared/nm-macros-internal.h

index dafce87..1f638ba 100644 (file)
@@ -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)
 {