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
=== modified file 'libdbusmenu-glib/menuitem.c'
--- libdbusmenu-glib/menuitem.c 2011-03-02 03:12:03 +0000
+++ libdbusmenu-glib/menuitem.c 2011-03-07 19:38:10 +0000
@@ -1180,17 +1180,23 @@
1180 }1180 }
1181 }1181 }
11821182
1183
1184 gboolean replaced = FALSE;1183 gboolean replaced = FALSE;
1185 gboolean remove = FALSE;1184 gboolean remove = FALSE;
1186 gpointer currentval = g_hash_table_lookup(priv->properties, property);1185 gchar * hash_key = NULL;
1186 GVariant * hash_variant = NULL;
1187 gboolean inhash = g_hash_table_lookup_extended(priv->properties, property, (gpointer *)&hash_key, (gpointer *)&hash_variant);
1188
1189 if (inhash && hash_variant == NULL) {
1190 g_warning("The property '%s' is in the hash with a NULL variant", property);
1191 inhash = FALSE;
1192 }
11871193
1188 if (value != NULL) {1194 if (value != NULL) {
1189 /* NOTE: We're only marking this as replaced if this is true1195 /* NOTE: We're only marking this as replaced if this is true
1190 but we're actually replacing it no matter. This is so that1196 but we're actually replacing it no matter. This is so that
1191 the variant passed in sticks around which the caller may1197 the variant passed in sticks around which the caller may
1192 expect. They shouldn't, but it's low cost to remove bugs. */1198 expect. They shouldn't, but it's low cost to remove bugs. */
1193 if (currentval == NULL || !g_variant_equal((GVariant*)currentval, value)) {1199 if (!inhash || !g_variant_equal(hash_variant, value)) {
1194 replaced = TRUE;1200 replaced = TRUE;
1195 }1201 }
11961202
@@ -1204,7 +1210,7 @@
1204 bad value */1210 bad value */
1205 g_hash_table_insert(priv->properties, lprop, value);1211 g_hash_table_insert(priv->properties, lprop, value);
1206 } else {1212 } else {
1207 if (currentval != NULL) {1213 if (inhash) {
1208 /* So the question you should be asking if you're paying attention1214 /* So the question you should be asking if you're paying attention
1209 is "Why not just do the remove here?" It's a good question with1215 is "Why not just do the remove here?" It's a good question with
1210 an interesting answer. Bascially it's the same reason as above,1216 an interesting answer. Bascially it's the same reason as above,
@@ -1213,6 +1219,7 @@
1213 it) after the signal emition */1219 it) after the signal emition */
1214 remove = TRUE;1220 remove = TRUE;
1215 replaced = TRUE;1221 replaced = TRUE;
1222 g_hash_table_steal(priv->properties, property);
1216 }1223 }
1217 }1224 }
12181225
@@ -1220,7 +1227,7 @@
1220 becuse it has been unref'd when replaced in the hash1227 becuse it has been unref'd when replaced in the hash
1221 table. But the fact that there was a value is1228 table. But the fact that there was a value is
1222 the imporant part. */1229 the imporant part. */
1223 if (currentval == NULL || replaced) {1230 if (!inhash || replaced) {
1224 GVariant * signalval = value;1231 GVariant * signalval = value;
12251232
1226 if (signalval == NULL) {1233 if (signalval == NULL) {
@@ -1233,7 +1240,8 @@
1233 }1240 }
12341241
1235 if (remove) {1242 if (remove) {
1236 g_hash_table_remove(priv->properties, property);1243 g_free(hash_key);
1244 g_variant_unref(hash_variant);
1237 }1245 }
12381246
1239 return TRUE;1247 return TRUE;

Subscribers

People subscribed via source and target branches