[gnome-software/wip/iainl/ubuntu-xenial: 37/56] Use g_autoptr for Json code



commit 3552067efc8d183985b5f07a85ddd9bc1eb0409f
Author: Robert Ancell <robert ancell canonical com>
Date:   Tue Mar 1 22:02:24 2016 +1300

    Use g_autoptr for Json code

 src/plugins/gs-plugin-snappy.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
---
diff --git a/src/plugins/gs-plugin-snappy.c b/src/plugins/gs-plugin-snappy.c
index 4eed45c..480d946 100644
--- a/src/plugins/gs-plugin-snappy.c
+++ b/src/plugins/gs-plugin-snappy.c
@@ -29,6 +29,11 @@
 #include <libsoup/soup.h>
 #include <json-glib/json-glib.h>
 
+// This is fixed in json-glib 1.1.1
+#ifndef JsonParser_autoptr
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(JsonParser, g_object_unref)
+#endif
+
 // snapd API documentation is at https://github.com/ubuntu-core/snappy/blob/master/docs/rest.md
 
 struct GsPluginPrivate {
@@ -55,7 +60,7 @@ static GSocket *
 open_snapd_socket (GError **error)
 {
        GSocket *socket;
-       g_autoptr (GSocketAddress) address = NULL;
+       g_autoptr(GSocketAddress) address = NULL;
        g_autoptr(GError) sub_error = NULL;
 
        socket = g_socket_new (G_SOCKET_FAMILY_UNIX, G_SOCKET_TYPE_STREAM, G_SOCKET_PROTOCOL_DEFAULT, 
&sub_error);
@@ -226,7 +231,7 @@ get_apps (GsPlugin *plugin, const gchar *sources, gchar **search_terms, GList **
        GPtrArray *query_fields;
        g_autoptr (GString) path = NULL;
        g_autofree gchar *reason_phrase = NULL, *response_type = NULL, *response = NULL;
-       JsonParser *parser;
+       g_autoptr(JsonParser) parser = NULL;
        JsonObject *root, *result, *packages;
        GList *package_list, *link;
        g_autoptr(GError) sub_error = NULL;
@@ -375,7 +380,6 @@ get_apps (GsPlugin *plugin, const gchar *sources, gchar **search_terms, GList **
                }
                gs_plugin_add_app (list, app);
        }
-       g_object_unref (parser);
 
        return TRUE;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]