Merge lp:~ted/libdbusmenu/lp940651 into lp:libdbusmenu/0.6

Proposed by Ted Gould
Status: Merged
Merged at revision: 378
Proposed branch: lp:~ted/libdbusmenu/lp940651
Merge into: lp:libdbusmenu/0.6
Diff against target: 117 lines (+49/-47)
1 file modified
libdbusmenu-glib/client.c (+49/-47)
To merge this branch: bzr merge lp:~ted/libdbusmenu/lp940651
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
DBus Menu Team Pending
Review via email: mp+95413@code.launchpad.net

Description of the change

Fix some goto cleanups so things are more explicit

To post a comment you must log in.
Revision history for this message
Charles Kerr (charlesk) wrote :

Approved because the code looks fine, but I have a two minor suggestions for cleanup:

1. g_clear_error(&localerror) instead of "if (localerror != NULL) { g_error_free(localerror); }

2. The "callback all the folks we can find" section can be simpler:

    properties_listener_t * listener = find_listener(listeners, 0, id);
    if (listener == NULL) {
        g_warning("Unable to find listener for ID %d", id);
    } else if (listener->replied) {
        g_warning("Odd, we've already replied to the listener on ID %d", id);
    } else {
        GVariant * properties = g_variant_get_child_value(child, 1);
        listener->callback(properties, NULL, listener->user_data);
        listener->replied = TRUE;
        g_variant_unref(properties);
    }

    g_variant_unref(child);

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libdbusmenu-glib/client.c'
2--- libdbusmenu-glib/client.c 2012-02-15 17:17:18 +0000
3+++ libdbusmenu-glib/client.c 2012-03-01 17:00:35 +0000
4@@ -601,64 +601,66 @@
5 listener->callback(NULL, error, listener->user_data);
6 }
7 g_error_free(error);
8- goto out;
9 }
10
11 /* Callback all the folks we can find */
12- GVariant * parent = g_variant_get_child_value(params, 0);
13- GVariantIter iter;
14- g_variant_iter_init(&iter, parent);
15- GVariant * child;
16- while ((child = g_variant_iter_next_value(&iter)) != NULL) {
17- if (g_strcmp0(g_variant_get_type_string(child), "(ia{sv})") != 0) {
18- g_warning("Properties return signature is not '(ia{sv})' it is '%s'", g_variant_get_type_string(child));
19- g_variant_unref(child);
20- continue;
21- }
22-
23- GVariant * idv = g_variant_get_child_value(child, 0);
24- gint id = g_variant_get_int32(idv);
25- g_variant_unref(idv);
26-
27- GVariant * properties = g_variant_get_child_value(child, 1);
28-
29- properties_listener_t * listener = find_listener(listeners, 0, id);
30- if (listener == NULL) {
31- g_warning("Unable to find listener for ID %d", id);
32+ if (error == NULL) {
33+ GVariant * parent = g_variant_get_child_value(params, 0);
34+ GVariantIter iter;
35+ g_variant_iter_init(&iter, parent);
36+ GVariant * child;
37+ while ((child = g_variant_iter_next_value(&iter)) != NULL) {
38+ if (g_strcmp0(g_variant_get_type_string(child), "(ia{sv})") != 0) {
39+ g_warning("Properties return signature is not '(ia{sv})' it is '%s'", g_variant_get_type_string(child));
40+ g_variant_unref(child);
41+ continue;
42+ }
43+
44+ GVariant * idv = g_variant_get_child_value(child, 0);
45+ gint id = g_variant_get_int32(idv);
46+ g_variant_unref(idv);
47+
48+ GVariant * properties = g_variant_get_child_value(child, 1);
49+
50+ properties_listener_t * listener = find_listener(listeners, 0, id);
51+ if (listener == NULL) {
52+ g_warning("Unable to find listener for ID %d", id);
53+ g_variant_unref(properties);
54+ g_variant_unref(child);
55+ continue;
56+ }
57+
58+ if (!listener->replied) {
59+ listener->callback(properties, NULL, listener->user_data);
60+ listener->replied = TRUE;
61+ } else {
62+ g_warning("Odd, we've already replied to the listener on ID %d", id);
63+ }
64 g_variant_unref(properties);
65 g_variant_unref(child);
66- continue;
67- }
68-
69- if (!listener->replied) {
70- listener->callback(properties, NULL, listener->user_data);
71- listener->replied = TRUE;
72- } else {
73- g_warning("Odd, we've already replied to the listener on ID %d", id);
74- }
75- g_variant_unref(properties);
76- g_variant_unref(child);
77+ }
78+ g_variant_unref(parent);
79+ g_variant_unref(params);
80 }
81- g_variant_unref(parent);
82- g_variant_unref(params);
83
84 /* Provide errors for those who we can't */
85- GError * localerror = NULL;
86- for (i = 0; i < listeners->len; i++) {
87- properties_listener_t * listener = &g_array_index(listeners, properties_listener_t, i);
88- if (!listener->replied) {
89- g_warning("Generating properties error for: %d", listener->id);
90- if (localerror == NULL) {
91- g_set_error_literal(&localerror, error_domain(), 0, "Error getting properties for ID");
92+ if (error == NULL && listeners->len > 0) {
93+ GError * localerror = NULL;
94+ for (i = 0; i < listeners->len; i++) {
95+ properties_listener_t * listener = &g_array_index(listeners, properties_listener_t, i);
96+ if (!listener->replied) {
97+ g_warning("Generating properties error for: %d", listener->id);
98+ if (localerror == NULL) {
99+ g_set_error_literal(&localerror, error_domain(), 0, "Error getting properties for ID");
100+ }
101+ listener->callback(NULL, localerror, listener->user_data);
102 }
103- listener->callback(NULL, localerror, listener->user_data);
104- }
105- }
106- if (localerror != NULL) {
107- g_error_free(localerror);
108+ }
109+ if (localerror != NULL) {
110+ g_error_free(localerror);
111+ }
112 }
113
114-out:
115 /* Clean up */
116 g_array_free(listeners, TRUE);
117 g_object_unref(cbdata->client);

Subscribers

People subscribed via source and target branches

to all changes: