[libglnx] Add backport of g_set_object
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libglnx] Add backport of g_set_object
- Date: Tue, 1 Dec 2015 15:33:18 +0000 (UTC)
commit 1d65bc0ff740e4eb44610f9b699bf6a05e799493
Author: Alexander Larsson <alexl redhat com>
Date: Tue Dec 1 16:23:56 2015 +0100
Add backport of g_set_object
glnx-backports.c | 20 ++++++++++++++++++++
glnx-backports.h | 10 ++++++++++
2 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/glnx-backports.c b/glnx-backports.c
index 075c21a..c7bb600 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 825ef0f..cd853cc 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]