aboutsummaryrefslogtreecommitdiff
path: root/libdbusmenu-glib
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2011-03-09 08:38:12 -0600
committerTed Gould <ted@gould.cx>2011-03-09 08:38:12 -0600
commit16bc55aa8a22ed835707685c02e7b4f480a819da (patch)
treee327c98d6a5a61580e4ec7b74df7658f0bb7015c /libdbusmenu-glib
parentad8d65a45264aa052f3d3ae07af62c92954449bb (diff)
parent928640380912e340917701f3a32bc30b07a76f67 (diff)
downloadlibdbusmenu-16bc55aa8a22ed835707685c02e7b4f480a819da.tar.gz
libdbusmenu-16bc55aa8a22ed835707685c02e7b4f480a819da.tar.bz2
libdbusmenu-16bc55aa8a22ed835707685c02e7b4f480a819da.zip
Make sure to remove the value from the hash before signaling it's changed
Diffstat (limited to 'libdbusmenu-glib')
-rw-r--r--libdbusmenu-glib/menuitem.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c
index f7867e4..2e5a345 100644
--- a/libdbusmenu-glib/menuitem.c
+++ b/libdbusmenu-glib/menuitem.c
@@ -1180,17 +1180,23 @@ dbusmenu_menuitem_property_set_variant (DbusmenuMenuitem * mi, const gchar * pro
}
}
-
gboolean replaced = FALSE;
gboolean remove = FALSE;
- gpointer currentval = g_hash_table_lookup(priv->properties, property);
+ gchar * hash_key = NULL;
+ GVariant * hash_variant = NULL;
+ gboolean inhash = g_hash_table_lookup_extended(priv->properties, property, (gpointer *)&hash_key, (gpointer *)&hash_variant);
+
+ if (inhash && hash_variant == NULL) {
+ g_warning("The property '%s' is in the hash with a NULL variant", property);
+ inhash = FALSE;
+ }
if (value != NULL) {
/* NOTE: We're only marking this as replaced if this is true
but we're actually replacing it no matter. This is so that
the variant passed in sticks around which the caller may
expect. They shouldn't, but it's low cost to remove bugs. */
- if (currentval == NULL || !g_variant_equal((GVariant*)currentval, value)) {
+ if (!inhash || !g_variant_equal(hash_variant, value)) {
replaced = TRUE;
}
@@ -1204,7 +1210,7 @@ dbusmenu_menuitem_property_set_variant (DbusmenuMenuitem * mi, const gchar * pro
bad value */
g_hash_table_insert(priv->properties, lprop, value);
} else {
- if (currentval != NULL) {
+ if (inhash) {
/* So the question you should be asking if you're paying attention
is "Why not just do the remove here?" It's a good question with
an interesting answer. Bascially it's the same reason as above,
@@ -1213,6 +1219,7 @@ dbusmenu_menuitem_property_set_variant (DbusmenuMenuitem * mi, const gchar * pro
it) after the signal emition */
remove = TRUE;
replaced = TRUE;
+ g_hash_table_steal(priv->properties, property);
}
}
@@ -1220,7 +1227,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 (currentval == NULL || replaced) {
+ if (!inhash || replaced) {
GVariant * signalval = value;
if (signalval == NULL) {
@@ -1233,7 +1240,8 @@ dbusmenu_menuitem_property_set_variant (DbusmenuMenuitem * mi, const gchar * pro
}
if (remove) {
- g_hash_table_remove(priv->properties, property);
+ g_free(hash_key);
+ g_variant_unref(hash_variant);
}
return TRUE;