Merge lp:~ted/libdbusmenu/i-love-the-ping-of-ken-in-the-morning into lp:libdbusmenu/0.5

Proposed by Ted Gould
Status: Merged
Merged at revision: 260
Proposed branch: lp:~ted/libdbusmenu/i-love-the-ping-of-ken-in-the-morning
Merge into: lp:libdbusmenu/0.5
Diff against target: 66 lines (+14/-6)
1 file modified
libdbusmenu-glib/menuitem.c (+14/-6)
To merge this branch: bzr merge lp:~ted/libdbusmenu/i-love-the-ping-of-ken-in-the-morning
Reviewer Review Type Date Requested Status
Conor Curran (community) Approve
Review via email: mp+52463@code.launchpad.net

Description of the change

Changes that instead of removing the items we instead steal them and free the memory ourselves later. This should make it so that handlers of the signal can check to see if the value is in the hashtable and get correct results.

To post a comment you must log in.
Revision history for this message
Conor Curran (cjcurran) wrote :

I believe you :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libdbusmenu-glib/menuitem.c'
2--- libdbusmenu-glib/menuitem.c 2011-03-02 03:12:03 +0000
3+++ libdbusmenu-glib/menuitem.c 2011-03-07 19:38:10 +0000
4@@ -1180,17 +1180,23 @@
5 }
6 }
7
8-
9 gboolean replaced = FALSE;
10 gboolean remove = FALSE;
11- gpointer currentval = g_hash_table_lookup(priv->properties, property);
12+ gchar * hash_key = NULL;
13+ GVariant * hash_variant = NULL;
14+ gboolean inhash = g_hash_table_lookup_extended(priv->properties, property, (gpointer *)&hash_key, (gpointer *)&hash_variant);
15+
16+ if (inhash && hash_variant == NULL) {
17+ g_warning("The property '%s' is in the hash with a NULL variant", property);
18+ inhash = FALSE;
19+ }
20
21 if (value != NULL) {
22 /* NOTE: We're only marking this as replaced if this is true
23 but we're actually replacing it no matter. This is so that
24 the variant passed in sticks around which the caller may
25 expect. They shouldn't, but it's low cost to remove bugs. */
26- if (currentval == NULL || !g_variant_equal((GVariant*)currentval, value)) {
27+ if (!inhash || !g_variant_equal(hash_variant, value)) {
28 replaced = TRUE;
29 }
30
31@@ -1204,7 +1210,7 @@
32 bad value */
33 g_hash_table_insert(priv->properties, lprop, value);
34 } else {
35- if (currentval != NULL) {
36+ if (inhash) {
37 /* So the question you should be asking if you're paying attention
38 is "Why not just do the remove here?" It's a good question with
39 an interesting answer. Bascially it's the same reason as above,
40@@ -1213,6 +1219,7 @@
41 it) after the signal emition */
42 remove = TRUE;
43 replaced = TRUE;
44+ g_hash_table_steal(priv->properties, property);
45 }
46 }
47
48@@ -1220,7 +1227,7 @@
49 becuse it has been unref'd when replaced in the hash
50 table. But the fact that there was a value is
51 the imporant part. */
52- if (currentval == NULL || replaced) {
53+ if (!inhash || replaced) {
54 GVariant * signalval = value;
55
56 if (signalval == NULL) {
57@@ -1233,7 +1240,8 @@
58 }
59
60 if (remove) {
61- g_hash_table_remove(priv->properties, property);
62+ g_free(hash_key);
63+ g_variant_unref(hash_variant);
64 }
65
66 return TRUE;

Subscribers

People subscribed via source and target branches