aboutsummaryrefslogtreecommitdiff
path: root/libdbusmenu-glib
diff options
context:
space:
mode:
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;