From 6ef00b04680e3bfb8923158f7ffef3de8d9b09ef Mon Sep 17 00:00:00 2001 From: Kalev Lember Date: Tue, 8 Sep 2015 14:30:28 +0200 Subject: Use GLib's cleanup functions instead of libgsystem's We still have a few types that don't support g_autoptr(), but very very close to having everything ported over. This also bumps gdk-pixbuf dep to 2.31.5 for the cleanup macro support. --- client/as-builder.c | 54 ++-- client/as-util.c | 198 ++++++------- client/as-validate.c | 14 +- configure.ac | 2 +- libappstream-builder/asb-app.c | 6 +- libappstream-builder/asb-context.c | 86 +++--- libappstream-builder/asb-package-alpm.c | 2 +- libappstream-builder/asb-package-cab.c | 8 +- libappstream-builder/asb-package-deb.c | 12 +- libappstream-builder/asb-package-ostree.c | 24 +- libappstream-builder/asb-package-rpm.c | 16 +- libappstream-builder/asb-package.c | 8 +- libappstream-builder/asb-plugin-loader.c | 6 +- libappstream-builder/asb-plugin.c | 4 +- libappstream-builder/asb-self-test.c | 46 +-- libappstream-builder/asb-task.c | 10 +- libappstream-builder/asb-utils.c | 36 +-- libappstream-builder/plugins/asb-plugin-absorb.c | 2 +- libappstream-builder/plugins/asb-plugin-appdata.c | 10 +- libappstream-builder/plugins/asb-plugin-dbus.c | 8 +- libappstream-builder/plugins/asb-plugin-desktop.c | 34 +-- libappstream-builder/plugins/asb-plugin-firmware.c | 20 +- libappstream-builder/plugins/asb-plugin-font.c | 38 +-- libappstream-builder/plugins/asb-plugin-gettext.c | 14 +- libappstream-builder/plugins/asb-plugin-gir.c | 4 +- .../plugins/asb-plugin-gresource.c | 6 +- .../plugins/asb-plugin-gstreamer.c | 8 +- libappstream-builder/plugins/asb-plugin-ibus-sql.c | 16 +- libappstream-builder/plugins/asb-plugin-ibus-xml.c | 14 +- .../plugins/asb-plugin-kde-services.c | 8 +- libappstream-builder/plugins/asb-plugin-metainfo.c | 6 +- libappstream-builder/plugins/asb-plugin-nm.c | 6 +- libappstream-builder/plugins/asb-plugin-ostree.c | 10 +- libappstream-glib/as-app-desktop.c | 26 +- libappstream-glib/as-app-inf.c | 42 +-- libappstream-glib/as-app-validate.c | 14 +- libappstream-glib/as-app.c | 56 ++-- libappstream-glib/as-cleanup.h | 33 --- libappstream-glib/as-icon.c | 28 +- libappstream-glib/as-image.c | 10 +- libappstream-glib/as-inf.c | 46 +-- libappstream-glib/as-monitor.c | 16 +- libappstream-glib/as-node.c | 44 +-- libappstream-glib/as-release.c | 4 +- libappstream-glib/as-screenshot.c | 10 +- libappstream-glib/as-self-test.c | 318 ++++++++++----------- libappstream-glib/as-store.c | 96 +++---- libappstream-glib/as-utils.c | 82 +++--- libappstream-glib/as-yaml.c | 10 +- 49 files changed, 769 insertions(+), 802 deletions(-) diff --git a/client/as-builder.c b/client/as-builder.c index 5e9e2bf..efe6ded 100644 --- a/client/as-builder.c +++ b/client/as-builder.c @@ -43,13 +43,13 @@ static gboolean as_builder_search_path (GPtrArray *array, const gchar *path, GError **error) { const gchar *filename; - _cleanup_dir_close_ GDir *dir = NULL; + g_autoptr(GDir) dir = NULL; dir = g_dir_open (path, 0, error); if (dir == NULL) return FALSE; while ((filename = g_dir_read_name (dir)) != NULL) { - _cleanup_free_ gchar *tmp = NULL; + g_autofree gchar *tmp = NULL; tmp = g_build_filename (path, filename, NULL); if (g_file_test (tmp, G_FILE_TEST_IS_DIR)) { if (!as_builder_search_path (array, tmp, error)) @@ -71,9 +71,9 @@ as_builder_setup_ostree (AsbContext *ctx, const gchar *ostree_repo, GError **err GHashTableIter iter; gpointer key; gpointer value; - _cleanup_hashtable_unref_ GHashTable *refs = NULL; - _cleanup_object_unref_ GFile *file = NULL; - _cleanup_object_unref_ OstreeRepo *repo = NULL; + g_autoptr(GHashTable) refs = NULL; + g_autoptr(GFile) file = NULL; + g_autoptr(OstreeRepo) repo = NULL; /* load repo */ file = g_file_new_for_path (ostree_repo); @@ -85,11 +85,11 @@ as_builder_setup_ostree (AsbContext *ctx, const gchar *ostree_repo, GError **err g_hash_table_iter_init (&iter, refs); while (g_hash_table_iter_next (&iter, &key, &value)) { const gchar *refspec = key; - _cleanup_free_ gchar *remote = NULL; - _cleanup_free_ gchar *name = NULL; - _cleanup_free_ gchar *filename = NULL; - _cleanup_free_ gchar *ref = NULL; - _cleanup_object_unref_ AsbPackage *pkg = NULL; + g_autofree gchar *remote = NULL; + g_autofree gchar *name = NULL; + g_autofree gchar *filename = NULL; + g_autofree gchar *ref = NULL; + g_autoptr(AsbPackage) pkg = NULL; if (!ostree_parse_refspec (refspec, &remote, &ref, error)) return FALSE; @@ -140,21 +140,21 @@ main (int argc, char **argv) gint min_icon_size = 32; guint i; int retval = EXIT_SUCCESS; - _cleanup_dir_close_ GDir *dir = NULL; - _cleanup_error_free_ GError *error = NULL; - _cleanup_free_ gchar *basename = NULL; - _cleanup_free_ gchar *cache_dir = NULL; - _cleanup_free_ gchar *log_dir = NULL; - _cleanup_free_ gchar *icons_dir = NULL; - _cleanup_free_ gchar *old_metadata = NULL; - _cleanup_free_ gchar *origin = NULL; - _cleanup_free_ gchar *ostree_repo = NULL; - _cleanup_free_ gchar *output_dir = NULL; - _cleanup_free_ gchar *temp_dir = NULL; - _cleanup_free_ gchar **veto_ignore = NULL; - _cleanup_ptrarray_unref_ GPtrArray *packages = NULL; - _cleanup_strv_free_ gchar **packages_dirs = NULL; - _cleanup_timer_destroy_ GTimer *timer = NULL; + g_autoptr(GDir) dir = NULL; + g_autoptr(GError) error = NULL; + g_autofree gchar *basename = NULL; + g_autofree gchar *cache_dir = NULL; + g_autofree gchar *log_dir = NULL; + g_autofree gchar *icons_dir = NULL; + g_autofree gchar *old_metadata = NULL; + g_autofree gchar *origin = NULL; + g_autofree gchar *ostree_repo = NULL; + g_autofree gchar *output_dir = NULL; + g_autofree gchar *temp_dir = NULL; + g_autofree gchar **veto_ignore = NULL; + g_autoptr(GPtrArray) packages = NULL; + g_auto(GStrv) packages_dirs = NULL; + g_autoptr(GTimer) timer = NULL; const GOptionEntry options[] = { { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, /* TRANSLATORS: command line option */ @@ -353,7 +353,7 @@ main (int argc, char **argv) if (argc == 1 && ostree_repo == NULL) { /* if the user launches the tool with no arguments */ if (packages_dirs == NULL) { - _cleanup_free_ gchar *tmp = NULL; + g_autofree gchar *tmp = NULL; tmp = g_option_context_get_help (option_context, TRUE, NULL); g_print ("%s", tmp); retval = EXIT_FAILURE; @@ -375,7 +375,7 @@ main (int argc, char **argv) g_print ("%s\n", _("Scanning packages...")); timer = g_timer_new (); for (i = 0; i < packages->len; i++) { - _cleanup_error_free_ GError *error_local = NULL; + g_autoptr(GError) error_local = NULL; filename = g_ptr_array_index (packages, i); diff --git a/client/as-util.c b/client/as-util.c index 0deca94..db02ec5 100644 --- a/client/as-util.c +++ b/client/as-util.c @@ -91,7 +91,7 @@ as_util_add (GPtrArray *array, { AsUtilItem *item; guint i; - _cleanup_strv_free_ gchar **names = NULL; + g_auto(GStrv) names = NULL; g_return_if_fail (name != NULL); g_return_if_fail (description != NULL); @@ -482,7 +482,7 @@ as_util_convert_appstream (GFile *file_input, gdouble new_version, GError **error) { - _cleanup_object_unref_ AsStore *store = NULL; + g_autoptr(AsStore) store = NULL; store = as_store_new (); if (!as_store_from_file (store, file_input, NULL, NULL, error)) @@ -512,8 +512,8 @@ as_util_convert (AsUtilPrivate *priv, gchar **values, GError **error) AsAppSourceKind input_kind; AsAppSourceKind output_kind; gdouble new_version; - _cleanup_object_unref_ GFile *file_input = NULL; - _cleanup_object_unref_ GFile *file_output = NULL; + g_autoptr(GFile) file_input = NULL; + g_autoptr(GFile) file_output = NULL; /* check args */ if (g_strv_length (values) != 3) { @@ -582,7 +582,7 @@ as_util_upgrade (AsUtilPrivate *priv, gchar **values, GError **error) /* process each file */ for (i = 0; values[i] != NULL; i++) { - _cleanup_object_unref_ GFile *file = NULL; + g_autoptr(GFile) file = NULL; AsAppSourceKind source_kind; source_kind = as_app_guess_source_kind (values[i]); switch (source_kind) { @@ -632,7 +632,7 @@ as_util_appdata_to_news (AsUtilPrivate *priv, gchar **values, GError **error) /* convert all the AppData files */ for (f = 0; values[f] != NULL; f++) { - _cleanup_object_unref_ AsApp *app = NULL; + g_autoptr(AsApp) app = NULL; _cleanup_string_free_ GString *str = NULL; /* add separator */ @@ -658,9 +658,9 @@ as_util_appdata_to_news (AsUtilPrivate *priv, gchar **values, GError **error) for (i = 0; i < releases->len; i++) { AsRelease *rel; const gchar *tmp; - _cleanup_free_ gchar *version = NULL; - _cleanup_free_ gchar *date = NULL; - _cleanup_date_time_unref_ GDateTime *dt = NULL; + g_autofree gchar *version = NULL; + g_autofree gchar *date = NULL; + g_autoptr(GDateTime) dt = NULL; rel = g_ptr_array_index (releases, i); @@ -681,7 +681,7 @@ as_util_appdata_to_news (AsUtilPrivate *priv, gchar **values, GError **error) /* print description */ tmp = as_release_get_description (rel, NULL); if (tmp != NULL) { - _cleanup_free_ gchar *md = NULL; + g_autofree gchar *md = NULL; md = as_markup_convert (tmp, AS_MARKUP_CONVERT_FORMAT_MARKDOWN, error); @@ -796,7 +796,7 @@ as_util_news_add_markup (GString *desc, const gchar *tag, const gchar *line) { guint i; guint indent = 0; - _cleanup_free_ gchar *escaped = NULL; + g_autofree gchar *escaped = NULL; /* empty line means do nothing */ if (line != NULL && line[0] == '\0') @@ -826,7 +826,7 @@ as_util_news_add_markup (GString *desc, const gchar *tag, const gchar *line) g_string_append_printf (desc, "<%s>\n", tag); } else { gchar *tmp; - _cleanup_strv_free_ gchar **lines = NULL; + g_auto(GStrv) lines = NULL; escaped = g_markup_escape_text (line, -1); tmp = g_strrstr (escaped, " ("); if (tmp != NULL) @@ -863,9 +863,9 @@ as_util_news_to_appdata_hdr (GString *desc, const gchar *txt, GError **error) guint i; const gchar *version = NULL; const gchar *release = NULL; - _cleanup_strv_free_ gchar **release_split = NULL; - _cleanup_date_time_unref_ GDateTime *dt = NULL; - _cleanup_strv_free_ gchar **lines = NULL; + g_auto(GStrv) release_split = NULL; + g_autoptr(GDateTime) dt = NULL; + g_auto(GStrv) lines = NULL; /* get info */ lines = g_strsplit (txt, "\n", -1); @@ -955,7 +955,7 @@ static gboolean as_util_news_to_appdata_para (GString *desc, const gchar *txt, GError **error) { guint i; - _cleanup_strv_free_ gchar **lines = NULL; + g_auto(GStrv) lines = NULL; lines = g_strsplit (txt, "\n", -1); for (i = 1; lines[i] != NULL; i++) { @@ -974,10 +974,10 @@ static gboolean as_util_news_to_appdata (AsUtilPrivate *priv, gchar **values, GError **error) { guint i; - _cleanup_free_ gchar *data = NULL; + g_autofree gchar *data = NULL; _cleanup_string_free_ GString *data_str = NULL; _cleanup_string_free_ GString *desc = NULL; - _cleanup_strv_free_ gchar **split = NULL; + g_auto(GStrv) split = NULL; /* check args */ if (g_strv_length (values) != 1) { @@ -1001,7 +1001,7 @@ as_util_news_to_appdata (AsUtilPrivate *priv, gchar **values, GError **error) desc = g_string_new (""); split = g_strsplit (data_str->str, "\n\n", -1); for (i = 0; split[i] != NULL; i++) { - _cleanup_strv_free_ gchar **lines = NULL; + g_auto(GStrv) lines = NULL; /* ignore empty sections */ if (split[i][0] == '\0') @@ -1081,13 +1081,13 @@ static gboolean as_util_appdata_from_desktop (AsUtilPrivate *priv, gchar **values, GError **error) { gchar *instr = NULL; - _cleanup_free_ gchar *id_new = NULL; - _cleanup_object_unref_ AsApp *app = NULL; - _cleanup_object_unref_ AsImage *im1 = NULL; - _cleanup_object_unref_ AsImage *im2 = NULL; - _cleanup_object_unref_ AsScreenshot *ss1 = NULL; - _cleanup_object_unref_ AsScreenshot *ss2 = NULL; - _cleanup_object_unref_ GFile *file = NULL; + g_autofree gchar *id_new = NULL; + g_autoptr(AsApp) app = NULL; + g_autoptr(AsImage) im1 = NULL; + g_autoptr(AsImage) im2 = NULL; + g_autoptr(AsScreenshot) ss1 = NULL; + g_autoptr(AsScreenshot) ss2 = NULL; + g_autoptr(GFile) file = NULL; /* check args */ if (g_strv_length (values) != 2) { @@ -1184,8 +1184,8 @@ as_util_appdata_from_desktop (AsUtilPrivate *priv, gchar **values, GError **erro static gboolean as_util_add_file_to_store (AsStore *store, const gchar *filename, GError **error) { - _cleanup_object_unref_ AsApp *app = NULL; - _cleanup_object_unref_ GFile *file_input = NULL; + g_autoptr(AsApp) app = NULL; + g_autoptr(GFile) file_input = NULL; switch (as_app_guess_source_kind (filename)) { case AS_APP_SOURCE_KIND_APPDATA: @@ -1221,7 +1221,7 @@ as_util_dump (AsUtilPrivate *priv, gchar **values, GError **error) { guint i; _cleanup_string_free_ GString *xml = NULL; - _cleanup_object_unref_ AsStore *store = NULL; + g_autoptr(AsStore) store = NULL; /* check args */ if (g_strv_length (values) < 1) { @@ -1267,7 +1267,7 @@ as_util_search (AsUtilPrivate *priv, gchar **values, GError **error) { GPtrArray *apps; guint i; - _cleanup_object_unref_ AsStore *store = NULL; + g_autoptr(AsStore) store = NULL; /* check args */ if (g_strv_length (values) < 1) { @@ -1323,9 +1323,9 @@ as_util_show_search_tokens (AsUtilPrivate *priv, gchar **values, GError **error) guint j; const gchar *tmp; guint *cnt; - _cleanup_hashtable_unref_ GHashTable *dict = NULL; - _cleanup_object_unref_ AsStore *store = NULL; - _cleanup_list_free_ GList *keys = NULL; + g_autoptr(GHashTable) dict = NULL; + g_autoptr(AsStore) store = NULL; + g_autoptr(GList) keys = NULL; /* load system database */ store = as_store_new (); @@ -1335,7 +1335,7 @@ as_util_show_search_tokens (AsUtilPrivate *priv, gchar **values, GError **error) apps = as_store_get_apps (store); for (i = 0; i < apps->len; i++) { AsApp *app; - _cleanup_ptrarray_unref_ GPtrArray *tokens = NULL; + g_autoptr(GPtrArray) tokens = NULL; app = g_ptr_array_index (apps, i); tokens = as_app_get_search_tokens (app); for (j = 0; j < tokens->len; j++) { @@ -1433,7 +1433,7 @@ static gboolean as_util_rmtree (const gchar *directory, GError **error) { const gchar *filename; - _cleanup_dir_close_ GDir *dir = NULL; + g_autoptr(GDir) dir = NULL; /* try to open */ dir = g_dir_open (directory, 0, error); @@ -1442,7 +1442,7 @@ as_util_rmtree (const gchar *directory, GError **error) /* find each */ while ((filename = g_dir_read_name (dir))) { - _cleanup_free_ gchar *src = NULL; + g_autofree gchar *src = NULL; src = g_build_filename (directory, filename, NULL); if (g_file_test (src, G_FILE_TEST_IS_DIR)) { if (!as_util_rmtree (src, error)) @@ -1492,12 +1492,12 @@ as_util_uninstall (AsUtilPrivate *priv, gchar **values, GError **error) /* remove XML file */ destdir = g_getenv ("DESTDIR"); for (i = 0; locations[i] != NULL; i++) { - _cleanup_free_ gchar *path_xml = NULL; + g_autofree gchar *path_xml = NULL; path_xml = g_strdup_printf ("%s%s/app-info/xmls/%s.xml.gz", destdir != NULL ? destdir : "", locations[i], values[0]); if (g_file_test (path_xml, G_FILE_TEST_EXISTS)) { - _cleanup_object_unref_ GFile *file = NULL; + g_autoptr(GFile) file = NULL; file = g_file_new_for_path (path_xml); if (!g_file_delete (file, NULL, error)) return FALSE; @@ -1506,7 +1506,7 @@ as_util_uninstall (AsUtilPrivate *priv, gchar **values, GError **error) /* remove icons */ for (i = 0; locations[i] != NULL; i++) { - _cleanup_free_ gchar *path_icons = NULL; + g_autofree gchar *path_icons = NULL; path_icons = g_strdup_printf ("%s%s/app-info/icons/%s", destdir != NULL ? destdir : "", locations[i], values[0]); @@ -2068,8 +2068,8 @@ as_util_status_html (AsUtilPrivate *priv, gchar **values, GError **error) AsUtilDistro distro = AS_UTIL_DISTRO_UNKNOWN; GPtrArray *apps = NULL; guint i; - _cleanup_object_unref_ AsStore *store = NULL; - _cleanup_object_unref_ GFile *file = NULL; + g_autoptr(AsStore) store = NULL; + g_autoptr(GFile) file = NULL; _cleanup_string_free_ GString *html = NULL; /* check args */ @@ -2287,7 +2287,7 @@ as_util_matrix_html_write_app (AsApp *app, GString *html, AsUtilDistro distro) if (arr == NULL || arr->len == 0) { as_util_matrix_html_write_item (NULL, AS_UTIL_PKG_STATE_OK, str, NULL); } else { - _cleanup_free_ gchar *tmp = NULL; + g_autofree gchar *tmp = NULL; tmp = as_util_status_html_join (arr); if (g_strstr_len (tmp, -1, "Dead upstream") != NULL) { as_util_matrix_html_write_item (&state_app, @@ -2348,7 +2348,7 @@ as_util_matrix_html (AsUtilPrivate *priv, gchar **values, GError **error) AsUtilDistro distro = AS_UTIL_DISTRO_UNKNOWN; GPtrArray *apps = NULL; guint i; - _cleanup_object_unref_ AsStore *store = NULL; + g_autoptr(AsStore) store = NULL; _cleanup_string_free_ GString *html = NULL; /* check args */ @@ -2364,7 +2364,7 @@ as_util_matrix_html (AsUtilPrivate *priv, gchar **values, GError **error) /* load file */ store = as_store_new (); for (i = 1; values[i] != NULL; i++) { - _cleanup_object_unref_ GFile *file = NULL; + g_autoptr(GFile) file = NULL; file = g_file_new_for_path (values[i]); if (!as_store_from_file (store, file, NULL, NULL, error)) return FALSE; @@ -2438,7 +2438,7 @@ as_util_status_csv_filter_func (AsApp *app, gchar **filters) AsIdKind id_kind = AS_ID_KIND_DESKTOP; for (i = 0; filters[i] != NULL; i++) { - _cleanup_strv_free_ gchar **split = NULL; + g_auto(GStrv) split = NULL; split = g_strsplit (filters[i], "=", 2); if (g_strv_length (split) != 2) continue; @@ -2469,8 +2469,8 @@ as_util_status_csv (AsUtilPrivate *priv, gchar **values, GError **error) GPtrArray *apps = NULL; const gchar *tmp; guint i; - _cleanup_object_unref_ AsStore *store = NULL; - _cleanup_object_unref_ GFile *file = NULL; + g_autoptr(AsStore) store = NULL; + g_autoptr(GFile) file = NULL; _cleanup_string_free_ GString *data = NULL; /* check args */ @@ -2493,7 +2493,7 @@ as_util_status_csv (AsUtilPrivate *priv, gchar **values, GError **error) /* write applications */ data = g_string_new ("id,pkgname,name,comment,description,url\n"); for (i = 0; i < apps->len; i++) { - _cleanup_free_ gchar *description = NULL; + g_autofree gchar *description = NULL; app = g_ptr_array_index (apps, i); /* process filters */ @@ -2530,8 +2530,8 @@ as_util_non_package_yaml (AsUtilPrivate *priv, gchar **values, GError **error) AsApp *app; GPtrArray *apps = NULL; guint i; - _cleanup_object_unref_ AsStore *store = NULL; - _cleanup_object_unref_ GFile *file = NULL; + g_autoptr(AsStore) store = NULL; + g_autoptr(GFile) file = NULL; _cleanup_string_free_ GString *yaml = NULL; /* check args */ @@ -2633,7 +2633,7 @@ as_util_validate_output_html (const gchar *filename, GPtrArray *probs) g_print ("" ""; - _cleanup_hashtable_unref_ GHashTable *hash = NULL; + g_autoptr(GHashTable) hash = NULL; _cleanup_node_unref_ GNode *root = NULL; root = as_node_from_xml (xml, 0, &error); @@ -2333,10 +2333,10 @@ as_test_app_subsume_func (void) { AsIcon *ic; GList *list; - _cleanup_object_unref_ AsApp *app = NULL; - _cleanup_object_unref_ AsApp *donor = NULL; - _cleanup_object_unref_ AsIcon *icon = NULL; - _cleanup_object_unref_ AsScreenshot *ss = NULL; + g_autoptr(AsApp) app = NULL; + g_autoptr(AsApp) donor = NULL; + g_autoptr(AsIcon) icon = NULL; + g_autoptr(AsScreenshot) ss = NULL; donor = as_app_new (); icon = as_icon_new (); @@ -2395,7 +2395,7 @@ as_test_app_search_func (void) const gchar *all[] = { "gnome", "install", "software", NULL }; const gchar *none[] = { "gnome", "xxx", "software", NULL }; const gchar *mime[] = { "vnd", "oasis", "opendocument","text", NULL }; - _cleanup_object_unref_ AsApp *app = NULL; + g_autoptr(AsApp) app = NULL; app = as_app_new (); as_app_set_name (app, NULL, "GNOME Software"); @@ -2426,8 +2426,8 @@ as_test_store_embedded_func (void) AsApp *app; AsIcon *icon; gboolean ret; - _cleanup_error_free_ GError *error = NULL; - _cleanup_object_unref_ AsStore *store = NULL; + g_autoptr(GError) error = NULL; + g_autoptr(AsStore) store = NULL; _cleanup_string_free_ GString *xml = NULL; const gchar *xml_src = "" @@ -2530,8 +2530,8 @@ as_test_store_auto_reload_dir_func (void) AsApp *app; gboolean ret; guint cnt = 0; - _cleanup_error_free_ GError *error = NULL; - _cleanup_object_unref_ AsStore *store = NULL; + g_autoptr(GError) error = NULL; + g_autoptr(AsStore) store = NULL; /* add this file to a store */ store = as_store_new (); @@ -2584,9 +2584,9 @@ as_test_store_auto_reload_file_func (void) AsRelease *rel; gboolean ret; guint cnt = 0; - _cleanup_error_free_ GError *error = NULL; - _cleanup_object_unref_ AsStore *store = NULL; - _cleanup_object_unref_ GFile *file = NULL; + g_autoptr(GError) error = NULL; + g_autoptr(AsStore) store = NULL; + g_autoptr(GFile) file = NULL; /* set initial file */ ret = g_file_set_contents ("/tmp/foo.xml", @@ -2668,11 +2668,11 @@ as_test_store_demote_func (void) AsApp *app; GError *error = NULL; gboolean ret; - _cleanup_free_ gchar *filename1 = NULL; - _cleanup_free_ gchar *filename2 = NULL; - _cleanup_object_unref_ AsApp *app_appdata = NULL; - _cleanup_object_unref_ AsApp *app_desktop = NULL; - _cleanup_object_unref_ AsStore *store = NULL; + g_autofree gchar *filename1 = NULL; + g_autofree gchar *filename2 = NULL; + g_autoptr(AsApp) app_appdata = NULL; + g_autoptr(AsApp) app_desktop = NULL; + g_autoptr(AsStore) store = NULL; _cleanup_string_free_ GString *xml = NULL; /* load example desktop file */ @@ -2717,11 +2717,11 @@ static void as_test_store_merges_func (void) { AsApp *app_tmp; - _cleanup_object_unref_ AsApp *app_appdata = NULL; - _cleanup_object_unref_ AsApp *app_appinfo = NULL; - _cleanup_object_unref_ AsApp *app_desktop = NULL; - _cleanup_object_unref_ AsStore *store_all = NULL; - _cleanup_object_unref_ AsStore *store_desktop_appdata = NULL; + g_autoptr(AsApp) app_appdata = NULL; + g_autoptr(AsApp) app_appinfo = NULL; + g_autoptr(AsApp) app_desktop = NULL; + g_autoptr(AsStore) store_all = NULL; + g_autoptr(AsStore) store_desktop_appdata = NULL; /* test desktop + appdata */ store_desktop_appdata = as_store_new (); @@ -2785,10 +2785,10 @@ static void as_test_store_merges_local_func (void) { AsApp *app_tmp; - _cleanup_object_unref_ AsApp *app_appdata = NULL; - _cleanup_object_unref_ AsApp *app_appinfo = NULL; - _cleanup_object_unref_ AsApp *app_desktop = NULL; - _cleanup_object_unref_ AsStore *store = NULL; + g_autoptr(AsApp) app_appdata = NULL; + g_autoptr(AsApp) app_appinfo = NULL; + g_autoptr(AsApp) app_desktop = NULL; + g_autoptr(AsStore) store = NULL; /* test desktop + appdata + appstream */ store = as_store_new (); @@ -2839,8 +2839,8 @@ static void as_test_store_empty_func (void) { gboolean ret; - _cleanup_error_free_ GError *error = NULL; - _cleanup_object_unref_ AsStore *store = NULL; + g_autoptr(GError) error = NULL; + g_autoptr(AsStore) store = NULL; store = as_store_new (); ret = as_store_from_xml (store, "", NULL, &error); @@ -2853,7 +2853,7 @@ as_test_store_func (void) { AsApp *app; GString *xml; - _cleanup_object_unref_ AsStore *store = NULL; + g_autoptr(AsStore) store = NULL; /* create a store and add a single app */ store = as_store_new (); @@ -2919,8 +2919,8 @@ as_test_store_provides_func (void) { AsApp *app; gboolean ret; - _cleanup_error_free_ GError *error = NULL; - _cleanup_object_unref_ AsStore *store = NULL; + g_autoptr(GError) error = NULL; + g_autoptr(AsStore) store = NULL; /* create a store and add a single app */ store = as_store_new (); @@ -3068,7 +3068,7 @@ as_test_store_addons_func (void) "eclipse.desktop" "" ""; - _cleanup_object_unref_ AsStore *store = NULL; + g_autoptr(AsStore) store = NULL; _cleanup_string_free_ GString *str = NULL; /* load a file to the store */ @@ -3119,8 +3119,8 @@ as_test_node_no_dup_c_func (void) "Krita" "Krita" ""; - _cleanup_free_ AsNodeContext *ctx = NULL; - _cleanup_object_unref_ AsApp *app = NULL; + g_autofree AsNodeContext *ctx = NULL; + g_autoptr(AsApp) app = NULL; /* to object */ app = as_app_new (); @@ -3159,9 +3159,9 @@ as_test_store_origin_func (void) AsApp *app; GError *error = NULL; gboolean ret; - _cleanup_free_ gchar *filename = NULL; - _cleanup_object_unref_ AsStore *store = NULL; - _cleanup_object_unref_ GFile *file = NULL; + g_autofree gchar *filename = NULL; + g_autoptr(AsStore) store = NULL; + g_autoptr(GFile) file = NULL; /* load a file to the store */ store = as_store_new (); @@ -3189,15 +3189,15 @@ as_test_store_speed_appstream_func (void) gboolean ret; guint i; guint loops = 10; - _cleanup_free_ gchar *filename = NULL; - _cleanup_object_unref_ GFile *file = NULL; - _cleanup_timer_destroy_ GTimer *timer = NULL; + g_autofree gchar *filename = NULL; + g_autoptr(GFile) file = NULL; + g_autoptr(GTimer) timer = NULL; filename = as_test_get_filename ("example-v04.xml.gz"); file = g_file_new_for_path (filename); timer = g_timer_new (); for (i = 0; i < loops; i++) { - _cleanup_object_unref_ AsStore *store = NULL; + g_autoptr(AsStore) store = NULL; store = as_store_new (); ret = as_store_from_file (store, file, NULL, NULL, &error); g_assert_no_error (error); @@ -3216,13 +3216,13 @@ as_test_store_speed_appdata_func (void) gboolean ret; guint i; guint loops = 10; - _cleanup_free_ gchar *filename = NULL; - _cleanup_timer_destroy_ GTimer *timer = NULL; + g_autofree gchar *filename = NULL; + g_autoptr(GTimer) timer = NULL; filename = as_test_get_filename ("."); timer = g_timer_new (); for (i = 0; i < loops; i++) { - _cleanup_object_unref_ AsStore *store = NULL; + g_autoptr(AsStore) store = NULL; store = as_store_new (); as_store_set_destdir (store, filename); g_test_expect_message (G_LOG_DOMAIN, @@ -3243,13 +3243,13 @@ as_test_store_speed_desktop_func (void) gboolean ret; guint i; guint loops = 10; - _cleanup_free_ gchar *filename = NULL; - _cleanup_timer_destroy_ GTimer *timer = NULL; + g_autofree gchar *filename = NULL; + g_autoptr(GTimer) timer = NULL; filename = as_test_get_filename ("."); timer = g_timer_new (); for (i = 0; i < loops; i++) { - _cleanup_object_unref_ AsStore *store = NULL; + g_autoptr(AsStore) store = NULL; store = as_store_new (); as_store_set_destdir (store, filename); ret = as_store_load (store, AS_STORE_LOAD_FLAG_DESKTOP, NULL, &error); @@ -3263,7 +3263,7 @@ as_test_store_speed_desktop_func (void) static void as_test_utils_guid_func (void) { - _cleanup_free_ gchar *guid = NULL; + g_autofree gchar *guid = NULL; /* invalid */ g_assert (!as_utils_guid_is_valid (NULL)); @@ -3285,7 +3285,7 @@ as_test_utils_icons_func (void) { gchar *tmp; GError *error = NULL; - _cleanup_free_ gchar *destdir = NULL; + g_autofree gchar *destdir = NULL; destdir = as_test_get_filename ("."); @@ -3527,7 +3527,7 @@ as_test_store_app_install_func (void) { GError *error = NULL; gboolean ret; - _cleanup_object_unref_ AsStore *store = NULL; + g_autoptr(AsStore) store = NULL; store = as_store_new (); ret = as_store_load (store, @@ -3559,7 +3559,7 @@ as_test_store_metadata_func (void) "" "" ""; - _cleanup_object_unref_ AsStore *store = NULL; + g_autoptr(AsStore) store = NULL; store = as_store_new (); ret = as_store_from_xml (store, xml, NULL, &error); @@ -3577,15 +3577,15 @@ as_test_store_metadata_index_func (void) GPtrArray *apps; const guint repeats = 10000; guint i; - _cleanup_object_unref_ AsStore *store = NULL; - _cleanup_timer_destroy_ GTimer *timer = NULL; + g_autoptr(AsStore) store = NULL; + g_autoptr(GTimer) timer = NULL; /* create lots of applications in the store */ store = as_store_new (); as_store_add_metadata_index (store, "X-CacheID"); for (i = 0; i < repeats; i++) { - _cleanup_free_ gchar *id = g_strdup_printf ("app-%05i", i); - _cleanup_object_unref_ AsApp *app = as_app_new (); + g_autofree gchar *id = g_strdup_printf ("app-%05i", i); + g_autoptr(AsApp) app = as_app_new (); as_app_set_id (app, id); as_app_add_metadata (app, "X-CacheID", "dave.i386"); as_app_add_metadata (app, "baz", "dave"); @@ -3613,8 +3613,8 @@ as_test_yaml_func (void) GError *error = NULL; GString *str; const gchar *expected; - _cleanup_free_ gchar *filename = NULL; - _cleanup_object_unref_ GFile *file = NULL; + g_autofree gchar *filename = NULL; + g_autoptr(GFile) file = NULL; /* simple header */ node = as_yaml_from_data ( @@ -3722,10 +3722,10 @@ as_test_store_yaml_func (void) AsApp *app; GError *error = NULL; gboolean ret; - _cleanup_free_ gchar *filename = NULL; - _cleanup_free_ gchar *icon_root = NULL; - _cleanup_object_unref_ AsStore *store = NULL; - _cleanup_object_unref_ GFile *file = NULL; + g_autofree gchar *filename = NULL; + g_autofree gchar *icon_root = NULL; + g_autoptr(AsStore) store = NULL; + g_autoptr(GFile) file = NULL; _cleanup_string_free_ GString *str = NULL; const gchar *xml = "\n" @@ -3788,16 +3788,16 @@ as_test_store_speed_yaml_func (void) gboolean ret; guint i; guint loops = 10; - _cleanup_free_ gchar *filename = NULL; - _cleanup_object_unref_ GFile *file = NULL; - _cleanup_timer_destroy_ GTimer *timer = NULL; + g_autofree gchar *filename = NULL; + g_autoptr(GFile) file = NULL; + g_autoptr(GTimer) timer = NULL; filename = as_test_get_filename ("example-v06.yml.gz"); g_assert (filename != NULL); file = g_file_new_for_path (filename); timer = g_timer_new (); for (i = 0; i < loops; i++) { - _cleanup_object_unref_ AsStore *store = NULL; + g_autoptr(AsStore) store = NULL; store = as_store_new (); ret = as_store_from_file (store, file, NULL, NULL, &error); g_assert_no_error (error); @@ -3848,9 +3848,9 @@ as_test_inf_func (void) gboolean ret; gchar *tmp; guint64 ts; - _cleanup_dir_close_ GDir *dir = NULL; - _cleanup_free_ gchar *filename = NULL; - _cleanup_free_ gchar *infs = NULL; + g_autoptr(GDir) dir = NULL; + g_autofree gchar *filename = NULL; + g_autofree gchar *infs = NULL; /* case insensitive */ kf = g_key_file_new (); @@ -4124,7 +4124,7 @@ as_test_inf_func (void) if (infs != NULL) { dir = g_dir_open (infs, 0, NULL); while ((data = g_dir_read_name (dir)) != NULL) { - _cleanup_free_ gchar *path = NULL; + g_autofree gchar *path = NULL; path = g_build_filename (infs, data, NULL); kf = g_key_file_new (); ret = as_inf_load_file (kf, path, @@ -4151,10 +4151,10 @@ as_test_utils_install_filename_func (void) { gboolean ret; GError *error = NULL; - _cleanup_free_ gchar *filename1 = NULL; - _cleanup_free_ gchar *filename2 = NULL; - _cleanup_free_ gchar *filename3 = NULL; - _cleanup_free_ gchar *filename4 = NULL; + g_autofree gchar *filename1 = NULL; + g_autofree gchar *filename2 = NULL; + g_autofree gchar *filename3 = NULL; + g_autofree gchar *filename4 = NULL; /* appdata to shared */ filename1 = as_test_get_filename ("broken.appdata.xml"); diff --git a/libappstream-glib/as-store.c b/libappstream-glib/as-store.c index 0a0f5b0..1ad5987 100644 --- a/libappstream-glib/as-store.c +++ b/libappstream-glib/as-store.c @@ -861,8 +861,8 @@ as_store_from_root (AsStore *store, GNode *apps; GNode *n; const gchar *tmp; - _cleanup_free_ AsNodeContext *ctx = NULL; - _cleanup_free_ gchar *icon_path = NULL; + g_autofree AsNodeContext *ctx = NULL; + g_autofree gchar *icon_path = NULL; _cleanup_uninhibit_ guint32 *tok = NULL; g_return_val_if_fail (AS_IS_STORE (store), FALSE); @@ -908,8 +908,8 @@ as_store_from_root (AsStore *store, } ctx = as_node_context_new (); for (n = apps->children; n != NULL; n = n->next) { - _cleanup_error_free_ GError *error_local = NULL; - _cleanup_object_unref_ AsApp *app = NULL; + g_autoptr(GError) error_local = NULL; + g_autoptr(AsApp) app = NULL; if (as_node_get_tag (n) != AS_TAG_COMPONENT) continue; @@ -966,8 +966,8 @@ as_store_load_yaml_file (AsStore *store, GNode *app_n; GNode *n; const gchar *tmp; - _cleanup_free_ AsNodeContext *ctx = NULL; - _cleanup_free_ gchar *icon_path = NULL; + g_autofree AsNodeContext *ctx = NULL; + g_autofree gchar *icon_path = NULL; _cleanup_yaml_unref_ GNode *root = NULL; _cleanup_uninhibit_ guint32 *tok = NULL; @@ -1005,7 +1005,7 @@ as_store_load_yaml_file (AsStore *store, /* parse applications */ ctx = as_node_context_new (); for (app_n = root->children->next; app_n != NULL; app_n = app_n->next) { - _cleanup_object_unref_ AsApp *app = NULL; + g_autoptr(AsApp) app = NULL; if (app_n->children == NULL) continue; app = as_app_new (); @@ -1036,7 +1036,7 @@ as_store_remove_by_source_file (AsStore *store, const gchar *filename) GPtrArray *apps; guint i; const gchar *tmp; - _cleanup_ptrarray_unref_ GPtrArray *ids = NULL; + g_autoptr(GPtrArray) ids = NULL; /* find any applications in the store with this source file */ ids = g_ptr_array_new_with_free_func (g_free); @@ -1071,8 +1071,8 @@ as_store_monitor_changed_cb (AsMonitor *monitor, /* reload, or emit a signal */ if (priv->watch_flags & AS_STORE_WATCH_FLAG_ADDED) { - _cleanup_error_free_ GError *error = NULL; - _cleanup_object_unref_ GFile *file = NULL; + g_autoptr(GError) error = NULL; + g_autoptr(GFile) file = NULL; _cleanup_uninhibit_ guint32 *tok = NULL; tok = as_store_changed_inhibit (store); as_store_remove_by_source_file (store, filename); @@ -1096,8 +1096,8 @@ as_store_monitor_added_cb (AsMonitor *monitor, /* reload, or emit a signal */ if (priv->watch_flags & AS_STORE_WATCH_FLAG_ADDED) { - _cleanup_error_free_ GError *error = NULL; - _cleanup_object_unref_ GFile *file = NULL; + g_autoptr(GError) error = NULL; + g_autoptr(GFile) file = NULL; g_debug ("scanning %s", filename); file = g_file_new_for_path (filename); if (!as_store_from_file (store, file, NULL, NULL, &error)) @@ -1151,8 +1151,8 @@ as_store_from_file (AsStore *store, GError **error) { AsStorePrivate *priv = GET_PRIVATE (store); - _cleanup_free_ gchar *filename = NULL; - _cleanup_error_free_ GError *error_local = NULL; + g_autofree gchar *filename = NULL; + g_autoptr(GError) error_local = NULL; _cleanup_node_unref_ GNode *root = NULL; g_return_val_if_fail (AS_IS_STORE (store), FALSE); @@ -1212,7 +1212,7 @@ as_store_from_xml (AsStore *store, const gchar *icon_root, GError **error) { - _cleanup_error_free_ GError *error_local = NULL; + g_autoptr(GError) error_local = NULL; _cleanup_node_unref_ GNode *root = NULL; g_return_val_if_fail (AS_IS_STORE (store), FALSE); @@ -1267,7 +1267,7 @@ as_store_to_xml (AsStore *store, AsNodeToXmlFlags flags) GString *xml; guint i; gchar version[6]; - _cleanup_free_ AsNodeContext *ctx = NULL; + g_autofree AsNodeContext *ctx = NULL; /* get XML text */ node_root = as_node_new (); @@ -1353,12 +1353,12 @@ as_store_to_file (AsStore *store, GCancellable *cancellable, GError **error) { - _cleanup_error_free_ GError *error_local = NULL; - _cleanup_object_unref_ GOutputStream *out2 = NULL; - _cleanup_object_unref_ GOutputStream *out = NULL; - _cleanup_object_unref_ GZlibCompressor *compressor = NULL; + g_autoptr(GError) error_local = NULL; + g_autoptr(GOutputStream) out2 = NULL; + g_autoptr(GOutputStream) out = NULL; + g_autoptr(GZlibCompressor) compressor = NULL; _cleanup_string_free_ GString *xml = NULL; - _cleanup_free_ gchar *basename = NULL; + g_autofree gchar *basename = NULL; /* check if compressed */ basename = g_file_get_basename (file); @@ -1639,7 +1639,7 @@ as_store_guess_origin_fallback (AsStore *store, GError **error) { gchar *tmp; - _cleanup_free_ gchar *origin_fallback = NULL; + g_autofree gchar *origin_fallback = NULL; /* the first component of the file (e.g. "fedora-20.xml.gz) * is used for the icon directory as we might want to clean up @@ -1674,7 +1674,7 @@ as_store_load_app_info_file (AsStore *store, GCancellable *cancellable, GError **error) { - _cleanup_object_unref_ GFile *file = NULL; + g_autoptr(GFile) file = NULL; /* guess this based on the name */ if (!as_store_guess_origin_fallback (store, path_xml, error)) @@ -1703,10 +1703,10 @@ as_store_load_app_info (AsStore *store, { AsStorePrivate *priv = GET_PRIVATE (store); const gchar *tmp; - _cleanup_dir_close_ GDir *dir = NULL; - _cleanup_error_free_ GError *error_local = NULL; - _cleanup_free_ gchar *icon_root = NULL; - _cleanup_free_ gchar *path_md = NULL; + g_autoptr(GDir) dir = NULL; + g_autoptr(GError) error_local = NULL; + g_autofree gchar *icon_root = NULL; + g_autofree gchar *path_md = NULL; _cleanup_uninhibit_ guint32 *tok = NULL; /* emit once when finished */ @@ -1727,7 +1727,7 @@ as_store_load_app_info (AsStore *store, } icon_root = g_build_filename (path, "icons", NULL); while ((tmp = g_dir_read_name (dir)) != NULL) { - _cleanup_free_ gchar *filename_md = NULL; + g_autofree gchar *filename_md = NULL; filename_md = g_build_filename (path_md, tmp, NULL); if (!as_store_load_app_info_file (store, filename_md, @@ -1759,9 +1759,9 @@ as_store_add_app_install_screenshot (AsApp *app) { GPtrArray *pkgnames; const gchar *pkgname; - _cleanup_free_ gchar *url = NULL; - _cleanup_object_unref_ AsImage *im = NULL; - _cleanup_object_unref_ AsScreenshot *ss = NULL; + g_autofree gchar *url = NULL; + g_autoptr(AsImage) im = NULL; + g_autoptr(AsScreenshot) ss = NULL; /* get the default package name */ pkgnames = as_app_get_pkgnames (app); @@ -1795,8 +1795,8 @@ as_store_load_app_install_file (AsStore *store, AsIcon *icon; GPtrArray *icons; guint i; - _cleanup_error_free_ GError *error_local = NULL; - _cleanup_object_unref_ AsApp *app = NULL; + g_autoptr(GError) error_local = NULL; + g_autoptr(AsApp) app = NULL; app = as_app_new (); as_app_set_icon_path (app, path_icons); @@ -1846,10 +1846,10 @@ as_store_load_app_install (AsStore *store, GError **error) { const gchar *tmp; - _cleanup_dir_close_ GDir *dir = NULL; - _cleanup_error_free_ GError *error_local = NULL; - _cleanup_free_ gchar *path_desktop = NULL; - _cleanup_free_ gchar *path_icons = NULL; + g_autoptr(GDir) dir = NULL; + g_autoptr(GError) error_local = NULL; + g_autofree gchar *path_desktop = NULL; + g_autofree gchar *path_icons = NULL; path_desktop = g_build_filename (path, "desktop", NULL); if (!g_file_test (path_desktop, G_FILE_TEST_EXISTS)) @@ -1867,7 +1867,7 @@ as_store_load_app_install (AsStore *store, path_icons = g_build_filename (path, "icons", NULL); while ((tmp = g_dir_read_name (dir)) != NULL) { - _cleanup_free_ gchar *filename = NULL; + g_autofree gchar *filename = NULL; if (!g_str_has_suffix (tmp, ".desktop")) continue; filename = g_build_filename (path_desktop, tmp, NULL); @@ -1894,7 +1894,7 @@ as_store_load_installed (AsStore *store, AsStorePrivate *priv = GET_PRIVATE (store); GError *error_local = NULL; const gchar *tmp; - _cleanup_dir_close_ GDir *dir = NULL; + g_autoptr(GDir) dir = NULL; _cleanup_uninhibit_ guint32 *tok = NULL; dir = g_dir_open (path, 0, error); @@ -1910,8 +1910,8 @@ as_store_load_installed (AsStore *store, while ((tmp = g_dir_read_name (dir)) != NULL) { AsApp *app_tmp; - _cleanup_free_ gchar *filename = NULL; - _cleanup_object_unref_ AsApp *app = NULL; + g_autofree gchar *filename = NULL; + g_autoptr(AsApp) app = NULL; filename = g_build_filename (path, tmp, NULL); if (!g_file_test (filename, G_FILE_TEST_IS_REGULAR)) continue; @@ -2003,8 +2003,8 @@ as_store_load (AsStore *store, const gchar *tmp; gchar *path; guint i; - _cleanup_ptrarray_unref_ GPtrArray *app_info = NULL; - _cleanup_ptrarray_unref_ GPtrArray *installed = NULL; + g_autoptr(GPtrArray) app_info = NULL; + g_autoptr(GPtrArray) installed = NULL; _cleanup_uninhibit_ guint32 *tok = NULL; /* system locations */ @@ -2057,7 +2057,7 @@ as_store_load (AsStore *store, /* load each app-info path if it exists */ tok = as_store_changed_inhibit (store); for (i = 0; i < app_info->len; i++) { - _cleanup_free_ gchar *dest = NULL; + g_autofree gchar *dest = NULL; tmp = g_ptr_array_index (app_info, i); dest = g_build_filename (priv->destdir ? priv->destdir : "/", tmp, NULL); if (!g_file_test (dest, G_FILE_TEST_EXISTS)) @@ -2070,7 +2070,7 @@ as_store_load (AsStore *store, /* load each appdata and desktop path if it exists */ for (i = 0; i < installed->len; i++) { - _cleanup_free_ gchar *dest = NULL; + g_autofree gchar *dest = NULL; tmp = g_ptr_array_index (installed, i); dest = g_build_filename (priv->destdir ? priv->destdir : "/", tmp, NULL); if (!g_file_test (dest, G_FILE_TEST_EXISTS)) @@ -2081,7 +2081,7 @@ as_store_load (AsStore *store, /* ubuntu specific */ if ((flags & AS_STORE_LOAD_FLAG_APP_INSTALL) > 0) { - _cleanup_free_ gchar *dest = NULL; + g_autofree gchar *dest = NULL; dest = g_build_filename (priv->destdir ? priv->destdir : "/", "/usr/share/app-install", NULL); if (!as_store_load_app_install (store, dest, cancellable, error)) @@ -2106,7 +2106,7 @@ as_store_validate_add (GPtrArray *problems, AsProblemKind kind, const gchar *fmt AsProblem *problem; guint i; va_list args; - _cleanup_free_ gchar *str = NULL; + g_autofree gchar *str = NULL; va_start (args, fmt); str = g_strdup_vprintf (fmt, args); @@ -2181,7 +2181,7 @@ as_store_validate (AsStore *store, AsAppValidateFlags flags, GError **error) for (i = 0; i < priv->array->len; i++) { AsProblem *prob; guint j; - _cleanup_ptrarray_unref_ GPtrArray *probs_app = NULL; + g_autoptr(GPtrArray) probs_app = NULL; app = g_ptr_array_index (priv->array, i); if (priv->api_version < 0.3) { diff --git a/libappstream-glib/as-utils.c b/libappstream-glib/as-utils.c index 6261722..aa34274 100644 --- a/libappstream-glib/as-utils.c +++ b/libappstream-glib/as-utils.c @@ -81,7 +81,7 @@ as_markup_strsplit_words (const gchar *text, guint line_len) GPtrArray *lines; guint i; _cleanup_string_free_ GString *curline = NULL; - _cleanup_strv_free_ gchar **tokens = NULL; + g_auto(GStrv) tokens = NULL; /* sanity check */ if (text == NULL || text[0] == '\0') @@ -130,7 +130,7 @@ static void as_markup_render_para (GString *str, AsMarkupConvertFormat format, const gchar *data) { guint i; - _cleanup_strv_free_ gchar **spl = NULL; + g_auto(GStrv) spl = NULL; if (str->len > 0) g_string_append (str, "\n"); @@ -156,7 +156,7 @@ static void as_markup_render_li (GString *str, AsMarkupConvertFormat format, const gchar *data) { guint i; - _cleanup_strv_free_ gchar **spl = NULL; + g_auto(GStrv) spl = NULL; switch (format) { case AS_MARKUP_CONVERT_FORMAT_SIMPLE: @@ -319,8 +319,8 @@ as_hash_lookup_by_locale (GHashTable *hash, const gchar *locale) gboolean as_utils_is_stock_icon_name (const gchar *name) { - _cleanup_bytes_unref_ GBytes *data = NULL; - _cleanup_free_ gchar *key = NULL; + g_autoptr(GBytes) data = NULL; + g_autofree gchar *key = NULL; /* load the readonly data section and look for the icon name */ data = g_resource_lookup_data (as_get_resource (), @@ -346,8 +346,8 @@ as_utils_is_stock_icon_name (const gchar *name) gboolean as_utils_is_spdx_license_id (const gchar *license_id) { - _cleanup_bytes_unref_ GBytes *data = NULL; - _cleanup_free_ gchar *key = NULL; + g_autoptr(GBytes) data = NULL; + g_autofree gchar *key = NULL; /* this is used to map non-SPDX licence-ids to legitimate values */ if (g_str_has_prefix (license_id, "LicenseRef-")) @@ -378,9 +378,9 @@ gboolean as_utils_is_blacklisted_id (const gchar *desktop_id) { guint i; - _cleanup_bytes_unref_ GBytes *data = NULL; - _cleanup_free_ gchar *key = NULL; - _cleanup_strv_free_ gchar **split = NULL; + g_autoptr(GBytes) data = NULL; + g_autofree gchar *key = NULL; + g_auto(GStrv) split = NULL; /* load the readonly data section and look for the icon name */ data = g_resource_lookup_data (as_get_resource (), @@ -410,8 +410,8 @@ as_utils_is_blacklisted_id (const gchar *desktop_id) gboolean as_utils_is_environment_id (const gchar *environment_id) { - _cleanup_bytes_unref_ GBytes *data = NULL; - _cleanup_free_ gchar *key = NULL; + g_autoptr(GBytes) data = NULL; + g_autofree gchar *key = NULL; /* load the readonly data section and look for the icon name */ data = g_resource_lookup_data (as_get_resource (), @@ -437,8 +437,8 @@ as_utils_is_environment_id (const gchar *environment_id) gboolean as_utils_is_category_id (const gchar *category_id) { - _cleanup_bytes_unref_ GBytes *data = NULL; - _cleanup_free_ gchar *key = NULL; + g_autoptr(GBytes) data = NULL; + g_autofree gchar *key = NULL; /* load the readonly data section and look for the icon name */ data = g_resource_lookup_data (as_get_resource (), @@ -468,7 +468,7 @@ as_utils_spdx_license_tokenize_drop (AsUtilsSpdxHelper *helper) { const gchar *tmp = helper->collect->str; guint i; - _cleanup_free_ gchar *last_literal = NULL; + g_autofree gchar *last_literal = NULL; struct { const gchar *old; const gchar *new; @@ -634,7 +634,7 @@ gboolean as_utils_is_spdx_license (const gchar *license) { guint i; - _cleanup_strv_free_ gchar **tokens = NULL; + g_auto(GStrv) tokens = NULL; /* no license information whatsoever */ if (g_strcmp0 (license, "NONE") == 0) @@ -789,8 +789,8 @@ as_pixbuf_blur (GdkPixbuf *src, gint radius, gint iterations) { gint kernel_size; gint i; - _cleanup_free_ guchar *div_kernel_size = NULL; - _cleanup_object_unref_ GdkPixbuf *tmp = NULL; + g_autofree guchar *div_kernel_size = NULL; + g_autoptr(GdkPixbuf) tmp = NULL; tmp = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (src), gdk_pixbuf_get_has_alpha (src), @@ -829,7 +829,7 @@ as_pixbuf_sharpen (GdkPixbuf *src, gint radius, gdouble amount) guchar *p_blurred_row; guchar *p_src; guchar *p_src_row; - _cleanup_object_unref_ GdkPixbuf *blurred = NULL; + g_autoptr(GdkPixbuf) blurred = NULL; blurred = gdk_pixbuf_copy (src); as_pixbuf_blur (blurred, radius, 3); @@ -923,7 +923,7 @@ as_utils_find_icon_filename_full (const gchar *destdir, "status", "stock", NULL }; - _cleanup_free_ gchar *prefix = NULL; + g_autofree gchar *prefix = NULL; /* fallback */ if (destdir == NULL) @@ -931,7 +931,7 @@ as_utils_find_icon_filename_full (const gchar *destdir, /* is this an absolute path */ if (search[0] == '/') { - _cleanup_free_ gchar *tmp = NULL; + g_autofree gchar *tmp = NULL; tmp = g_build_filename (destdir, search, NULL); if (!g_file_test (tmp, G_FILE_TEST_EXISTS)) { g_set_error (error, @@ -964,7 +964,7 @@ as_utils_find_icon_filename_full (const gchar *destdir, for (i = 0; sizes[i] != NULL; i++) { for (m = 0; types[m] != NULL; m++) { for (j = 0; supported_ext[j] != NULL; j++) { - _cleanup_free_ gchar *tmp = NULL; + g_autofree gchar *tmp = NULL; tmp = g_strdup_printf ("%s/share/icons/" "%s/%s/%s/%s%s", prefix, @@ -983,7 +983,7 @@ as_utils_find_icon_filename_full (const gchar *destdir, /* pixmap */ for (i = 0; pixmap_dirs[i] != NULL; i++) { for (j = 0; supported_ext[j] != NULL; j++) { - _cleanup_free_ gchar *tmp = NULL; + g_autofree gchar *tmp = NULL; tmp = g_strdup_printf ("%s/share/%s/%s%s", prefix, pixmap_dirs[i], @@ -1056,8 +1056,8 @@ as_utils_install_icon (AsUtilsLocation location, int r; struct archive *arch = NULL; struct archive_entry *entry; - _cleanup_free_ gchar *data = NULL; - _cleanup_free_ gchar *dir = NULL; + g_autofree gchar *data = NULL; + g_autofree gchar *dir = NULL; dir = g_strdup_printf ("%s%s/app-info/icons/%s", destdir, @@ -1086,7 +1086,7 @@ as_utils_install_icon (AsUtilsLocation location, /* decompress each file */ for (;;) { - _cleanup_free_ gchar *buf = NULL; + g_autofree gchar *buf = NULL; r = archive_read_next_header (arch, &entry); if (r == ARCHIVE_EOF) @@ -1113,7 +1113,7 @@ as_utils_install_icon (AsUtilsLocation location, /* update hardlinks */ tmp = archive_entry_hardlink (entry); if (tmp != NULL) { - _cleanup_free_ gchar *buf_link = NULL; + g_autofree gchar *buf_link = NULL; buf_link = g_build_filename (dir, tmp, NULL); archive_entry_update_hardlink_utf8 (entry, buf_link); } @@ -1121,7 +1121,7 @@ as_utils_install_icon (AsUtilsLocation location, /* update symlinks */ tmp = archive_entry_symlink (entry); if (tmp != NULL) { - _cleanup_free_ gchar *buf_link = NULL; + g_autofree gchar *buf_link = NULL; buf_link = g_build_filename (dir, tmp, NULL); archive_entry_update_symlink_utf8 (entry, buf_link); } @@ -1156,11 +1156,11 @@ as_utils_install_xml (const gchar *filename, GError **error) { gchar *tmp; - _cleanup_free_ gchar *basename = NULL; - _cleanup_free_ gchar *path_dest = NULL; - _cleanup_free_ gchar *path_parent = NULL; - _cleanup_object_unref_ GFile *file_dest = NULL; - _cleanup_object_unref_ GFile *file_src = NULL; + g_autofree gchar *basename = NULL; + g_autofree gchar *path_dest = NULL; + g_autofree gchar *path_parent = NULL; + g_autoptr(GFile) file_dest = NULL; + g_autoptr(GFile) file_src = NULL; /* create directory structure */ path_parent = g_strdup_printf ("%s%s", destdir, dir); @@ -1176,7 +1176,7 @@ as_utils_install_xml (const gchar *filename, file_src = g_file_new_for_path (filename); basename = g_path_get_basename (filename); if (origin != NULL) { - _cleanup_free_ gchar *basename_new = NULL; + g_autofree gchar *basename_new = NULL; tmp = g_strstr_len (basename, -1, "."); if (tmp == NULL) { g_set_error (error, @@ -1203,7 +1203,7 @@ as_utils_install_xml (const gchar *filename, /* fix the origin */ if (origin != NULL) { - _cleanup_object_unref_ AsStore *store = NULL; + g_autoptr(AsStore) store = NULL; store = as_store_new (); if (!as_store_from_file (store, file_dest, NULL, NULL, error)) return FALSE; @@ -1240,8 +1240,8 @@ as_utils_install_filename (AsUtilsLocation location, { gboolean ret = FALSE; gchar *tmp; - _cleanup_free_ gchar *basename = NULL; - _cleanup_free_ gchar *path = NULL; + g_autofree gchar *basename = NULL; + g_autofree gchar *path = NULL; /* default value */ if (destdir == NULL) @@ -1354,7 +1354,7 @@ as_utils_search_tokenize (const gchar *search) gchar **values = NULL; guint i; guint idx = 0; - _cleanup_strv_free_ gchar **tmp = NULL; + g_auto(GStrv) tmp = NULL; /* only add keywords that are long enough */ tmp = g_strsplit (search, " ", -1); @@ -1391,8 +1391,8 @@ as_utils_vercmp (const gchar *version_a, const gchar *version_b) gint64 ver_b; guint i; guint longest_split; - _cleanup_strv_free_ gchar **split_a = NULL; - _cleanup_strv_free_ gchar **split_b = NULL; + g_auto(GStrv) split_a = NULL; + g_auto(GStrv) split_b = NULL; /* sanity check */ if (version_a == NULL || version_b == NULL) @@ -1484,7 +1484,7 @@ as_utils_guid_is_xdigit (const gchar *str) gboolean as_utils_guid_is_valid (const gchar *guid) { - _cleanup_strv_free_ gchar **split = NULL; + g_auto(GStrv) split = NULL; if (guid == NULL) return FALSE; split = g_strsplit (guid, "-", -1); diff --git a/libappstream-glib/as-yaml.c b/libappstream-glib/as-yaml.c index f226c52..74fdd41 100644 --- a/libappstream-glib/as-yaml.c +++ b/libappstream-glib/as-yaml.c @@ -330,11 +330,11 @@ as_yaml_from_file (GFile *file, GCancellable *cancellable, GError **error) #if AS_BUILD_DEP11 const gchar *content_type = NULL; yaml_parser_t parser; - _cleanup_free_ gchar *data = NULL; - _cleanup_object_unref_ GConverter *conv = NULL; - _cleanup_object_unref_ GFileInfo *info = NULL; - _cleanup_object_unref_ GInputStream *file_stream = NULL; - _cleanup_object_unref_ GInputStream *stream_data = NULL; + g_autofree gchar *data = NULL; + g_autoptr(GConverter) conv = NULL; + g_autoptr(GFileInfo) info = NULL; + g_autoptr(GInputStream) file_stream = NULL; + g_autoptr(GInputStream) stream_data = NULL; /* what kind of file is this */ info = g_file_query_info (file, -- cgit v1.2.1