From 0d8e8e6f562b3e3f33e4997df8a382adf8262866 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 16 Apr 2012 16:13:37 +0100 Subject: [PATCH 01/14] TpAccountChannelRequest: copy the hash table with a specific memory model Forcing use of a particular key and value destructor makes it safe to edit the hash table after the request has been created. (Setting every property in the constructor doesn't scale, in the presence of optional properties, and we want high-level API for this so apps can be a bit less D-Bus-API-dependent.) Signed-off-by: Simon McVittie --- telepathy-glib/account-channel-request.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/telepathy-glib/account-channel-request.c b/telepathy-glib/account-channel-request.c index 9a28a93..4742b74 100644 --- a/telepathy-glib/account-channel-request.c +++ b/telepathy-glib/account-channel-request.c @@ -127,6 +127,10 @@ typedef enum struct _TpAccountChannelRequestPrivate { TpAccount *account; + /* dup'd string => slice-allocated GValue + * + * Do not use tp_asv_new() and friends, because they expect static + * string keys. */ GHashTable *request; gint64 user_action_time; @@ -265,7 +269,14 @@ tp_account_channel_request_set_property (GObject *object, break; case PROP_REQUEST: - self->priv->request = g_value_dup_boxed (value); + /* We do not use tp_asv_new() and friends, because in principle, + * the request can contain user-defined keys. */ + self->priv->request = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, (GDestroyNotify) tp_g_value_slice_free); + tp_g_hash_table_update (self->priv->request, + g_value_get_boxed (value), + (GBoxedCopyFunc) g_strdup, + (GBoxedCopyFunc) tp_g_value_slice_dup); break; case PROP_USER_ACTION_TIME: -- 1.7.10