Blame SOURCES/0001-Use-g_list_free_full-where-easily-possible.patch

4c949f
From f4bae6ba2f20caa6e3bf6fa7a7ea52eaf2180beb Mon Sep 17 00:00:00 2001
4c949f
From: Pino Toscano <ptoscano@redhat.com>
4c949f
Date: Thu, 20 Dec 2018 10:56:25 +0100
4c949f
Subject: [PATCH] Use g_list_free_full where easily possible
4c949f
MIME-Version: 1.0
4c949f
Content-Type: text/plain; charset=UTF-8
4c949f
Content-Transfer-Encoding: 8bit
4c949f
4c949f
Use g_list_free_full instead of g_list_foreach + g_list_free, so the
4c949f
lists are cleared with a single call.
4c949f
4c949f
test-isodetect gets a void* wrapper, so there is no need to add casts
4c949f
everywhere.
4c949f
4c949f
Reviewed-by: Fabiano FidĂȘncio <fidencio@redhat.com>
4c949f
(cherry picked from commit 4fe69c9fe31befe3caa55bbaac0bcfa5e605f028)
4c949f
---
4c949f
 osinfo/osinfo_deployment.c    |  8 +-------
4c949f
 osinfo/osinfo_entity.c        |  7 +------
4c949f
 osinfo/osinfo_filter.c        |  9 +--------
4c949f
 osinfo/osinfo_loader.c        |  3 +--
4c949f
 osinfo/osinfo_os.c            |  8 +-------
4c949f
 osinfo/osinfo_platform.c      |  8 +-------
4c949f
 osinfo/osinfo_product.c       |  5 ++---
4c949f
 osinfo/osinfo_productfilter.c |  9 +--------
4c949f
 tests/test-isodetect.c        | 17 +++++++++++------
4c949f
 9 files changed, 20 insertions(+), 54 deletions(-)
4c949f
4c949f
diff --git a/osinfo/osinfo_deployment.c b/osinfo/osinfo_deployment.c
4c949f
index 7191ac3..a79b32f 100644
4c949f
--- a/osinfo/osinfo_deployment.c
4c949f
+++ b/osinfo/osinfo_deployment.c
4c949f
@@ -114,18 +114,12 @@ osinfo_deployment_get_property(GObject *object,
4c949f
 
4c949f
 
4c949f
 
4c949f
-static void osinfo_device_link_free(gpointer data, gpointer opaque G_GNUC_UNUSED)
4c949f
-{
4c949f
-    g_object_unref(OSINFO_DEVICELINK(data));
4c949f
-}
4c949f
-
4c949f
 static void
4c949f
 osinfo_deployment_finalize(GObject *object)
4c949f
 {
4c949f
     OsinfoDeployment *deployment = OSINFO_DEPLOYMENT(object);
4c949f
 
4c949f
-    g_list_foreach(deployment->priv->deviceLinks, osinfo_device_link_free, NULL);
4c949f
-    g_list_free(deployment->priv->deviceLinks);
4c949f
+    g_list_free_full(deployment->priv->deviceLinks, g_object_unref);
4c949f
 
4c949f
     g_object_unref(deployment->priv->os);
4c949f
     g_object_unref(deployment->priv->platform);
4c949f
diff --git a/osinfo/osinfo_entity.c b/osinfo/osinfo_entity.c
4c949f
index 20b9115..a776baa 100644
4c949f
--- a/osinfo/osinfo_entity.c
4c949f
+++ b/osinfo/osinfo_entity.c
4c949f
@@ -146,15 +146,10 @@ osinfo_entity_class_init(OsinfoEntityClass *klass)
4c949f
     g_type_class_add_private(klass, sizeof(OsinfoEntityPrivate));
4c949f
 }
4c949f
 
4c949f
-static void osinfo_entity_param_value_free(gpointer value, gpointer opaque G_GNUC_UNUSED)
4c949f
-{
4c949f
-    g_free(value);
4c949f
-}
4c949f
 
4c949f
 static void osinfo_entity_param_values_free(gpointer values)
4c949f
 {
4c949f
-    g_list_foreach(values, osinfo_entity_param_value_free, NULL);
4c949f
-    g_list_free(values);
4c949f
+    g_list_free_full(values, g_free);
4c949f
 }
4c949f
 
4c949f
 
4c949f
diff --git a/osinfo/osinfo_filter.c b/osinfo/osinfo_filter.c
4c949f
index 7f06d43..1c38735 100644
4c949f
--- a/osinfo/osinfo_filter.c
4c949f
+++ b/osinfo/osinfo_filter.c
4c949f
@@ -88,17 +88,10 @@ OsinfoFilter *osinfo_filter_new(void)
4c949f
 }
4c949f
 
4c949f
 
4c949f
-static void
4c949f
-osinfo_filter_prop_constraint_free(gpointer value, gpointer opaque G_GNUC_UNUSED)
4c949f
-{
4c949f
-    g_free(value);
4c949f
-}
4c949f
-
4c949f
 static void
4c949f
 osinfo_filter_prop_constraints_free(gpointer props)
4c949f
 {
4c949f
-    g_list_foreach(props, osinfo_filter_prop_constraint_free, NULL);
4c949f
-    g_list_free(props);
4c949f
+    g_list_free_full(props, g_free);
4c949f
 }
4c949f
 
4c949f
 
4c949f
diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
4c949f
index dca23f1..d580b66 100644
4c949f
--- a/osinfo/osinfo_loader.c
4c949f
+++ b/osinfo/osinfo_loader.c
4c949f
@@ -1898,8 +1898,7 @@ static void osinfo_loader_entity_files_free(OsinfoLoaderEntityFiles *files)
4c949f
 {
4c949f
     if (!files)
4c949f
         return;
4c949f
-    g_list_foreach(files->extensions, (GFunc)g_object_unref, NULL);
4c949f
-    g_list_free(files->extensions);
4c949f
+    g_list_free_full(files->extensions, g_object_unref);
4c949f
     if (files->master)
4c949f
         g_object_unref(files->master);
4c949f
     g_free(files);
4c949f
diff --git a/osinfo/osinfo_os.c b/osinfo/osinfo_os.c
4c949f
index 4f74331..b77c687 100644
4c949f
--- a/osinfo/osinfo_os.c
4c949f
+++ b/osinfo/osinfo_os.c
4c949f
@@ -75,11 +75,6 @@ enum {
4c949f
 
4c949f
 static void osinfo_os_finalize(GObject *object);
4c949f
 
4c949f
-static void osinfo_device_link_free(gpointer data, gpointer opaque G_GNUC_UNUSED)
4c949f
-{
4c949f
-    g_object_unref(OSINFO_DEVICELINK(data));
4c949f
-}
4c949f
-
4c949f
 static void
4c949f
 osinfo_os_get_property(GObject    *object,
4c949f
                         guint       property_id,
4c949f
@@ -112,8 +107,7 @@ osinfo_os_finalize(GObject *object)
4c949f
 {
4c949f
     OsinfoOs *os = OSINFO_OS(object);
4c949f
 
4c949f
-    g_list_foreach(os->priv->deviceLinks, osinfo_device_link_free, NULL);
4c949f
-    g_list_free(os->priv->deviceLinks);
4c949f
+    g_list_free_full(os->priv->deviceLinks, g_object_unref);
4c949f
     g_object_unref(os->priv->medias);
4c949f
     g_object_unref(os->priv->trees);
4c949f
     g_object_unref(os->priv->variants);
4c949f
diff --git a/osinfo/osinfo_platform.c b/osinfo/osinfo_platform.c
4c949f
index b17eef6..c949a83 100644
4c949f
--- a/osinfo/osinfo_platform.c
4c949f
+++ b/osinfo/osinfo_platform.c
4c949f
@@ -52,18 +52,12 @@ struct _OsinfoPlatformDeviceLink {
4c949f
     gchar *driver;
4c949f
 };
4c949f
 
4c949f
-static void osinfo_device_link_free(gpointer data, gpointer opaque G_GNUC_UNUSED)
4c949f
-{
4c949f
-    g_object_unref(OSINFO_DEVICELINK(data));
4c949f
-}
4c949f
-
4c949f
 static void
4c949f
 osinfo_platform_finalize(GObject *object)
4c949f
 {
4c949f
     OsinfoPlatform *platform = OSINFO_PLATFORM(object);
4c949f
 
4c949f
-    g_list_foreach(platform->priv->deviceLinks, osinfo_device_link_free, NULL);
4c949f
-    g_list_free(platform->priv->deviceLinks);
4c949f
+    g_list_free_full(platform->priv->deviceLinks, g_object_unref);
4c949f
 
4c949f
     /* Chain up to the parent class */
4c949f
     G_OBJECT_CLASS(osinfo_platform_parent_class)->finalize(object);
4c949f
diff --git a/osinfo/osinfo_product.c b/osinfo/osinfo_product.c
4c949f
index 1bd7017..27cb89c 100644
4c949f
--- a/osinfo/osinfo_product.c
4c949f
+++ b/osinfo/osinfo_product.c
4c949f
@@ -82,7 +82,7 @@ enum {
4c949f
     PROP_LOGO,
4c949f
 };
4c949f
 
4c949f
-static void osinfo_product_link_free(gpointer data, gpointer opaque G_GNUC_UNUSED)
4c949f
+static void osinfo_product_link_free(gpointer data)
4c949f
 {
4c949f
     struct _OsinfoProductProductLink *prodlink = data;
4c949f
     g_object_unref(prodlink->otherProduct);
4c949f
@@ -95,8 +95,7 @@ osinfo_product_finalize(GObject *object)
4c949f
 {
4c949f
     OsinfoProduct *product = OSINFO_PRODUCT(object);
4c949f
 
4c949f
-    g_list_foreach(product->priv->productLinks, osinfo_product_link_free, NULL);
4c949f
-    g_list_free(product->priv->productLinks);
4c949f
+    g_list_free_full(product->priv->productLinks, osinfo_product_link_free);
4c949f
 
4c949f
     /* Chain up to the parent class */
4c949f
     G_OBJECT_CLASS(osinfo_product_parent_class)->finalize(object);
4c949f
diff --git a/osinfo/osinfo_productfilter.c b/osinfo/osinfo_productfilter.c
4c949f
index 16976c2..addd3dc 100644
4c949f
--- a/osinfo/osinfo_productfilter.c
4c949f
+++ b/osinfo/osinfo_productfilter.c
4c949f
@@ -97,17 +97,10 @@ OsinfoProductFilter *osinfo_productfilter_new(void)
4c949f
 }
4c949f
 
4c949f
 
4c949f
-static void
4c949f
-osinfo_productfilter_product_constraint_free(gpointer value, gpointer opaque G_GNUC_UNUSED)
4c949f
-{
4c949f
-    g_object_unref(value);
4c949f
-}
4c949f
-
4c949f
 static void
4c949f
 osinfo_productfilter_product_constraints_free(gpointer relshps)
4c949f
 {
4c949f
-    g_list_foreach(relshps, osinfo_productfilter_product_constraint_free, NULL);
4c949f
-    g_list_free(relshps);
4c949f
+    g_list_free_full(relshps, g_object_unref);
4c949f
 }
4c949f
 
4c949f
 static void
4c949f
diff --git a/tests/test-isodetect.c b/tests/test-isodetect.c
4c949f
index 7214531..b5591bc 100644
4c949f
--- a/tests/test-isodetect.c
4c949f
+++ b/tests/test-isodetect.c
4c949f
@@ -46,6 +46,14 @@ static void free_iso(struct ISOInfo *info)
4c949f
     g_free(info);
4c949f
 }
4c949f
 
4c949f
+/* void* wrapper for free_iso, so it can be used where a void* parameter
4c949f
+ * is required (e.g. g_list_free_full), with no need for casts.
4c949f
+ */
4c949f
+static void free_iso_void(void *info)
4c949f
+{
4c949f
+    free_iso((struct ISOInfo *)info);
4c949f
+}
4c949f
+
4c949f
 static gboolean load_langs(GFile *file, struct ISOInfo *info, GError **error)
4c949f
 {
4c949f
     char *path;
4c949f
@@ -242,8 +250,7 @@ static GList *load_distro(GFile *dir, const gchar *shortid, GError **error) {
4c949f
     return ret;
4c949f
 
4c949f
  error:
4c949f
-    g_list_foreach(ret, (GFunc)free_iso, NULL);
4c949f
-    g_list_free(ret);
4c949f
+    g_list_free_full(ret, free_iso_void);
4c949f
     ret = NULL;
4c949f
     goto cleanup;
4c949f
 }
4c949f
@@ -288,8 +295,7 @@ static GList *load_distros(GFile *dir, GError **error)
4c949f
     return ret;
4c949f
 
4c949f
  error:
4c949f
-    g_list_foreach(ret, (GFunc)free_iso, NULL);
4c949f
-    g_list_free(ret);
4c949f
+    g_list_free_full(ret, free_iso_void);
4c949f
     ret = NULL;
4c949f
     goto cleanup;
4c949f
 }
4c949f
@@ -370,8 +376,7 @@ static void test_one(const gchar *vendor)
4c949f
         tmp = tmp->next;
4c949f
     }
4c949f
 
4c949f
-    g_list_foreach(isos, (GFunc)free_iso, NULL);
4c949f
-    g_list_free(isos);
4c949f
+    g_list_free_full(isos, free_iso_void);
4c949f
 
4c949f
     g_object_unref(loader);
4c949f
 }
4c949f
-- 
4c949f
2.21.0
4c949f