[gssdp] all: More GLib utility functions



commit e9771f54685dfbb516d9fc52cd94dde7a20eed9d
Author: Jens Georg <mail jensge org>
Date:   Tue Oct 30 19:39:08 2018 +0100

    all: More GLib utility functions
    
    Bump glib requirement to 2.34 because of g_list_copy_deep

 libgssdp/gssdp-client.c           | 10 +++-------
 libgssdp/gssdp-resource-browser.c | 32 +++++++++++---------------------
 libgssdp/gssdp-resource-group.c   | 13 ++++---------
 meson.build                       |  6 +++---
 4 files changed, 21 insertions(+), 40 deletions(-)
---
diff --git a/libgssdp/gssdp-client.c b/libgssdp/gssdp-client.c
index 964f329..ce9755b 100644
--- a/libgssdp/gssdp-client.c
+++ b/libgssdp/gssdp-client.c
@@ -1249,16 +1249,12 @@ socket_source_cb (GSSDPSocketSource *socket_source, GSSDPClient *client)
         }
 
 out:
-        if (error)
-                g_error_free (error);
+        g_clear_error (&error);
 
         g_free (ip_string);
 
-        if (headers)
-                soup_message_headers_free (headers);
-
-        if (address)
-                g_object_unref (address);
+        g_clear_pointer (&headers, soup_message_headers_free);
+        g_clear_object (&address);
 
         if (messages) {
                 int i;
diff --git a/libgssdp/gssdp-resource-browser.c b/libgssdp/gssdp-resource-browser.c
index e6fc3ce..c5cbe92 100644
--- a/libgssdp/gssdp-resource-browser.c
+++ b/libgssdp/gssdp-resource-browser.c
@@ -249,8 +249,7 @@ gssdp_resource_browser_finalize (GObject *object)
         resource_browser = GSSDP_RESOURCE_BROWSER (object);
         priv = gssdp_resource_browser_get_instance_private (resource_browser);
 
-        if (priv->target_regex)
-                g_regex_unref (priv->target_regex);
+        g_clear_pointer (&priv->target_regex, g_regex_unref);
 
         g_free (priv->target);
 
@@ -489,8 +488,7 @@ gssdp_resource_browser_set_target (GSSDPResourceBrowser *resource_browser,
         g_free (priv->target);
         priv->target = g_strdup (target);
 
-        if (priv->target_regex)
-                g_regex_unref (priv->target_regex);
+        g_clear_pointer (&priv->target_regex, g_regex_unref);
 
         version_pattern = "([0-9]+)";
         /* Make sure we have enough room for version pattern */
@@ -511,9 +509,9 @@ gssdp_resource_browser_set_target (GSSDPResourceBrowser *resource_browser,
 
         error = NULL;
         priv->target_regex = g_regex_new (pattern,
-                                                            0,
-                                                            0,
-                                                            &error);
+                                          0,
+                                          0,
+                                          &error);
         if (error) {
                 g_warning ("Error compiling regular expression '%s': %s",
                            pattern,
@@ -821,8 +819,7 @@ resource_available (GSSDPResourceBrowser *resource_browser,
                 canonical_usn = NULL;
         }
 
-        if (canonical_usn != NULL)
-                g_free (canonical_usn);
+        g_free (canonical_usn);
 
         /* Calculate new timeout */
         header = soup_message_headers_get_one (headers, "Cache-Control");
@@ -962,8 +959,7 @@ check_target_compat (GSSDPResourceBrowser *resource_browser,
 
         priv = gssdp_resource_browser_get_instance_private (resource_browser);
 
-        if (strcmp (priv->target,
-                    GSSDP_ALL_RESOURCES) == 0)
+        if (g_str_equal (priv->target, GSSDP_ALL_RESOURCES))
                 return TRUE;
 
         if (!g_regex_match (priv->target_regex,
@@ -1218,18 +1214,12 @@ stop_discovery (GSSDPResourceBrowser *resource_browser)
 
         priv = gssdp_resource_browser_get_instance_private (resource_browser);
         if (priv->timeout_src) {
-                g_source_destroy (priv->timeout_src);
-                priv->timeout_src = NULL;
                 priv->num_discovery = 0;
         }
-        if (priv->refresh_cache_src) {
-                g_source_destroy (priv->refresh_cache_src);
-                priv->refresh_cache_src = NULL;
-        }
-        if (priv->fresh_resources) {
-                g_hash_table_unref (priv->fresh_resources);
-                priv->fresh_resources = NULL;
-        }
+
+        g_clear_pointer (&priv->timeout_src, g_source_destroy);
+        g_clear_pointer (&priv->refresh_cache_src, g_source_destroy);
+        g_clear_pointer (&priv->fresh_resources, g_hash_table_destroy);
 }
 
 static gboolean
diff --git a/libgssdp/gssdp-resource-group.c b/libgssdp/gssdp-resource-group.c
index 7b309f2..1f9e9b0 100644
--- a/libgssdp/gssdp-resource-group.c
+++ b/libgssdp/gssdp-resource-group.c
@@ -623,10 +623,9 @@ gssdp_resource_group_add_resource (GSSDPResourceGroup *resource_group,
                                    const char         *usn,
                                    GList              *locations)
 {
-        GSSDPResourceGroupPrivate *priv;
-        Resource *resource;
-        GList *l;
-        GError *error;
+        GSSDPResourceGroupPrivate *priv = NULL;
+        Resource *resource = NULL;
+        GError *error = NULL;
 
         g_return_val_if_fail (GSSDP_IS_RESOURCE_GROUP (resource_group), 0);
         g_return_val_if_fail (target != NULL, 0);
@@ -642,7 +641,6 @@ gssdp_resource_group_add_resource (GSSDPResourceGroup *resource_group,
         resource->target = g_strdup (target);
         resource->usn    = g_strdup (usn);
 
-        error = NULL;
         resource->target_regex = create_target_regex (target,
                                                       &resource->version,
                                                       &error);
@@ -659,10 +657,7 @@ gssdp_resource_group_add_resource (GSSDPResourceGroup *resource_group,
 
         resource->initial_byebye_sent = FALSE;
 
-        for (l = locations; l; l = l->next) {
-                resource->locations = g_list_append (resource->locations,
-                                                     g_strdup (l->data));
-        }
+        resource->locations = g_list_copy_deep (locations, (GCopyFunc) g_strdup, NULL);
 
         priv->resources = g_list_prepend (priv->resources, resource);
 
diff --git a/meson.build b/meson.build
index f6153a8..57a9902 100644
--- a/meson.build
+++ b/meson.build
@@ -64,9 +64,9 @@ endif
 generic_unix = not bionic_available and host_machine.system() != 'windows'
 
 dependencies = [
-    dependency('glib-2.0', version : '>= 2.32'),
-    dependency('gobject-2.0', version : '>= 2.32'),
-    dependency('gio-2.0', version : '>= 2.32'),
+    dependency('glib-2.0', version : '>= 2.34'),
+    dependency('gobject-2.0', version : '>= 2.34'),
+    dependency('gio-2.0', version : '>= 2.34'),
     dependency('libsoup-2.4', version : '>= 2.26.1')
 ]
 


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