From 9a8736203da0c070672c3d6eafb28db1e42cdd76 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 9 Nov 2011 06:13:26 -0500 Subject: [PATCH] core: Add ot_util_variant_take_ref for older GLib versions --- libostree/ostree-core.c | 2 +- libotutil/ot-variant-utils.c | 12 ++++++++++++ libotutil/ot-variant-utils.h | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/libostree/ostree-core.c b/libostree/ostree-core.c index 9a05e91e..d65636c7 100644 --- a/libostree/ostree-core.c +++ b/libostree/ostree-core.c @@ -358,7 +358,7 @@ ostree_parse_metadata_file (const char *path, ret = TRUE; *out_type = ret_type; - *out_variant = g_variant_take_ref (ret_variant); + *out_variant = ot_util_variant_take_ref (ret_variant); ret_variant = NULL; out: if (ret_variant) diff --git a/libotutil/ot-variant-utils.c b/libotutil/ot-variant-utils.c index e0d0a75b..837e6ec4 100644 --- a/libotutil/ot-variant-utils.c +++ b/libotutil/ot-variant-utils.c @@ -75,6 +75,18 @@ ot_util_variant_save (GFile *dest, return ret; } +GVariant * +ot_util_variant_take_ref (GVariant *variant) +{ +#if GLIB_CHECK_VERSION(2,32,0) + return g_variant_take_ref (variant); +#else + if (g_variant_is_floating (variant)) + return g_variant_ref_sink (variant); + return variant; +#endif +} + gboolean ot_util_variant_map (GFile *src, const GVariantType *type, diff --git a/libotutil/ot-variant-utils.h b/libotutil/ot-variant-utils.h index 0a9464b6..33850a33 100644 --- a/libotutil/ot-variant-utils.h +++ b/libotutil/ot-variant-utils.h @@ -28,6 +28,8 @@ G_BEGIN_DECLS GHashTable *ot_util_variant_asv_to_hash_table (GVariant *variant); +GVariant * ot_util_variant_take_ref (GVariant *variant); + gboolean ot_util_variant_save (GFile *dest, GVariant *variant, GCancellable *cancellable,