diff options
author | Alexander Larsson <alexl@redhat.com> | 2015-12-01 16:23:56 +0100 |
---|---|---|
committer | Alexander Larsson <alexl@redhat.com> | 2015-12-01 16:32:59 +0100 |
commit | 1d65bc0ff740e4eb44610f9b699bf6a05e799493 (patch) | |
tree | 26faf6b7eafadbda54ba346547f62cea6b354514 | |
parent | dade12b5587e14058ad93263ee744f91038de68c (diff) | |
download | libglnx-1d65bc0ff740e4eb44610f9b699bf6a05e799493.tar.gz |
Add backport of g_set_object
-rw-r--r-- | glnx-backports.c | 20 | ||||
-rw-r--r-- | 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 |