From 4592b138187df94f644aae46bd1a6f0913a4c05b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 1 Mar 2012 10:55:24 -0600 Subject: Clean up a goto and make the lifecycles of the variables more clear --- libdbusmenu-glib/client.c | 86 ++++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 42 deletions(-) (limited to 'libdbusmenu-glib') diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index e64d923..01f063d 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -601,64 +601,66 @@ get_properties_callback (GObject *obj, GAsyncResult * res, gpointer user_data) listener->callback(NULL, error, listener->user_data); } g_error_free(error); - goto out; } /* Callback all the folks we can find */ - GVariant * parent = g_variant_get_child_value(params, 0); - GVariantIter iter; - g_variant_iter_init(&iter, parent); - GVariant * child; - while ((child = g_variant_iter_next_value(&iter)) != NULL) { - if (g_strcmp0(g_variant_get_type_string(child), "(ia{sv})") != 0) { - g_warning("Properties return signature is not '(ia{sv})' it is '%s'", g_variant_get_type_string(child)); - g_variant_unref(child); - continue; - } + if (error == NULL) { + GVariant * parent = g_variant_get_child_value(params, 0); + GVariantIter iter; + g_variant_iter_init(&iter, parent); + GVariant * child; + while ((child = g_variant_iter_next_value(&iter)) != NULL) { + if (g_strcmp0(g_variant_get_type_string(child), "(ia{sv})") != 0) { + g_warning("Properties return signature is not '(ia{sv})' it is '%s'", g_variant_get_type_string(child)); + g_variant_unref(child); + continue; + } - GVariant * idv = g_variant_get_child_value(child, 0); - gint id = g_variant_get_int32(idv); - g_variant_unref(idv); + GVariant * idv = g_variant_get_child_value(child, 0); + gint id = g_variant_get_int32(idv); + g_variant_unref(idv); + + GVariant * properties = g_variant_get_child_value(child, 1); - GVariant * properties = g_variant_get_child_value(child, 1); + properties_listener_t * listener = find_listener(listeners, 0, id); + if (listener == NULL) { + g_warning("Unable to find listener for ID %d", id); + g_variant_unref(properties); + g_variant_unref(child); + continue; + } - properties_listener_t * listener = find_listener(listeners, 0, id); - if (listener == NULL) { - g_warning("Unable to find listener for ID %d", id); + if (!listener->replied) { + listener->callback(properties, NULL, listener->user_data); + listener->replied = TRUE; + } else { + g_warning("Odd, we've already replied to the listener on ID %d", id); + } g_variant_unref(properties); g_variant_unref(child); - continue; } - - if (!listener->replied) { - listener->callback(properties, NULL, listener->user_data); - listener->replied = TRUE; - } else { - g_warning("Odd, we've already replied to the listener on ID %d", id); - } - g_variant_unref(properties); - g_variant_unref(child); + g_variant_unref(parent); + g_variant_unref(params); } - g_variant_unref(parent); - g_variant_unref(params); /* Provide errors for those who we can't */ - GError * localerror = NULL; - for (i = 0; i < listeners->len; i++) { - properties_listener_t * listener = &g_array_index(listeners, properties_listener_t, i); - if (!listener->replied) { - g_warning("Generating properties error for: %d", listener->id); - if (localerror == NULL) { - g_set_error_literal(&localerror, error_domain(), 0, "Error getting properties for ID"); + if (error == NULL && listeners->len > 0) { + GError * localerror = NULL; + for (i = 0; i < listeners->len; i++) { + properties_listener_t * listener = &g_array_index(listeners, properties_listener_t, i); + if (!listener->replied) { + g_warning("Generating properties error for: %d", listener->id); + if (localerror == NULL) { + g_set_error_literal(&localerror, error_domain(), 0, "Error getting properties for ID"); + } + listener->callback(NULL, localerror, listener->user_data); } - listener->callback(NULL, localerror, listener->user_data); } - } - if (localerror != NULL) { - g_error_free(localerror); + if (localerror != NULL) { + g_error_free(localerror); + } } -out: /* Clean up */ g_array_free(listeners, TRUE); g_object_unref(cbdata->client); -- cgit v1.2.3 From e11292ff7e55e6eeeef7ebb9260b238601db49c7 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 2 Mar 2012 15:19:45 -0600 Subject: Not sending the update signal if the value is being cleared and it was already cleared --- libdbusmenu-glib/menuitem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-glib') diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 18db4ef..46546d6 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -1253,7 +1253,8 @@ dbusmenu_menuitem_property_set_variant (DbusmenuMenuitem * mi, const gchar * pro becuse it has been unref'd when replaced in the hash table. But the fact that there was a value is the imporant part. */ - if (!inhash || replaced) { + if ((!inhash || replaced) && + !(!inhash && value == NULL)) { GVariant * signalval = value; if (signalval == NULL) { -- cgit v1.2.3 From a19fad6da18d3aec7aed4a4cddf3aeeb87249319 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Mar 2012 08:51:49 -0600 Subject: Switching out logic, we're using replaced now because it gets set everytime that the hashtable is modified, and if we weren't modifying the hash table in some way, we don't want to signal. And, conversely, no one cares if we didn't modify the hash table. --- libdbusmenu-glib/menuitem.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'libdbusmenu-glib') diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 46546d6..253fe6e 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -1253,8 +1253,7 @@ dbusmenu_menuitem_property_set_variant (DbusmenuMenuitem * mi, const gchar * pro becuse it has been unref'd when replaced in the hash table. But the fact that there was a value is the imporant part. */ - if ((!inhash || replaced) && - !(!inhash && value == NULL)) { + if (replaced) { GVariant * signalval = value; if (signalval == NULL) { -- cgit v1.2.3 From 9834879581e4f4ba16983b289c9b0442a48d5bdd Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Mar 2012 09:44:05 -0600 Subject: Fixing a trivial annotation bug --- libdbusmenu-glib/menuitem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-glib') diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 253fe6e..c81c36e 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -1462,8 +1462,8 @@ dbusmenu_menuitem_property_remove (DbusmenuMenuitem * mi, const gchar * property * by the menuitem but the list is not and should be freed using * g_list_free() when the calling function is done with it. * - * Return value: (transfer container): A list of strings or NULL if there are - * none. + * Return value: (transfer container) (element-type utf8): A list of + * strings or NULL if there are none. */ GList * dbusmenu_menuitem_properties_list (DbusmenuMenuitem * mi) -- cgit v1.2.3