telepathy-glib: TpAccountChannelRequest: copy the hash table with a specific memory model

Simon McVittie smcv at kemper.freedesktop.org
Mon Apr 30 11:57:28 PDT 2012


Module: telepathy-glib
Branch: master
Commit: 40c12e5ec863922f62a053f8feeb1ed414188430
URL:    http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=40c12e5ec863922f62a053f8feeb1ed414188430

Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date:   Mon Apr 16 16:13:37 2012 +0100

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 <simon.mcvittie at collabora.co.uk>
Reviewed-by: Jonny Lamb <jonny.lamb at collabora.co.uk>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=48780

---

 telepathy-glib/account-channel-request.c |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/telepathy-glib/account-channel-request.c b/telepathy-glib/account-channel-request.c
index 86cbc16..2c376ca 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:



More information about the telepathy-commits mailing list