From 1d65bc0ff740e4eb44610f9b699bf6a05e799493 Mon Sep 17 00:00:00 2001
From: Alexander Larsson <alexl@redhat.com>
Date: Tue, 1 Dec 2015 16:23:56 +0100
Subject: [PATCH] Add backport of g_set_object

---
 glnx-backports.c | 20 ++++++++++++++++++++
 glnx-backports.h | 10 ++++++++++
 2 files changed, 30 insertions(+)

diff --git a/glnx-backports.c b/glnx-backports.c
index 075c21ac2..c7bb600f4 100644
--- a/glnx-backports.c
+++ b/glnx-backports.c
@@ -38,4 +38,24 @@ glnx_strv_contains (const gchar * const *strv,
 
   return FALSE;
 }
+
+gboolean
+glnx_set_object (GObject **object_ptr,
+                 GObject  *new_object)
+{
+  GObject *old_object = *object_ptr;
+
+  if (old_object == new_object)
+    return FALSE;
+
+  if (new_object != NULL)
+    g_object_ref (new_object);
+
+  *object_ptr = new_object;
+
+  if (old_object != NULL)
+    g_object_unref (old_object);
+
+  return TRUE;
+}
 #endif
diff --git a/glnx-backports.h b/glnx-backports.h
index 825ef0f89..cd853cca2 100644
--- a/glnx-backports.h
+++ b/glnx-backports.h
@@ -28,9 +28,19 @@
 G_BEGIN_DECLS
 
 #if !GLIB_CHECK_VERSION(2, 44, 0)
+
 #define g_strv_contains glnx_strv_contains
 gboolean              glnx_strv_contains  (const gchar * const *strv,
                                            const gchar         *str);
+
+#define g_set_object(object_ptr, new_object) \
+ (/* Check types match. */ \
+  0 ? *(object_ptr) = (new_object), FALSE : \
+  glnx_set_object ((GObject **) (object_ptr), (GObject *) (new_object)) \
+ )
+gboolean              glnx_set_object  (GObject **object_ptr,
+                                        GObject  *new_object);
+
 #endif /* !GLIB_CHECK_VERSION(2, 44, 0) */
 
 G_END_DECLS
-- 
GitLab