[Bug 30423] Provide convenience API for GVariant-based a{sv}s

bugzilla-daemon at freedesktop.org bugzilla-daemon at freedesktop.org
Thu Oct 14 19:54:33 CEST 2010


https://bugs.freedesktop.org/show_bug.cgi?id=30423

--- Comment #4 from Simon McVittie <simon.mcvittie at collabora.co.uk> 2010-10-14 10:54:33 PDT ---
(In reply to comment #3)
> Perhaps: A reference to @dict is taken via g_variant_ref_sink(). If @dict is a
> floating reference, the new #TpVariantMap takes ownership of @dict.

That sounds good wording, thanks.

> What about cases where you want to pass a TpVariantMap
> to a function, but then continue to make changes to it (e.g. launching several
> channels with the same TargetID), which is something that's possible with a{sv}
> maps at the moment.

That's an interesting case.

> Is any function that accepts a TpVariantMap going to freeze your map on you?
> Perhaps immutability needs to be separated from building the variant?

Potentially, yes: when you send a request off onto D-Bus, it'll need to be
serialized into a GVariant. Hmm.

Perhaps instead we ought to have a vaguely Qt-like copy-on-write mechanism in
which instances look as though they're all independent, but in fact they share
data behind the scenes as much as possible. Something like this:

- TpVariantMap is a boxed, mutable value-type, and is not refcounted

- a TpVariantMap contains a hash table, a GVariant or both

- "copying" a TpVariantMap ensures that its GVariant and hash table exist, then
puts a ref to each in the copy

- whenever a TpVariantMap is modified, if the GVariant exists, it first makes
itself independent of any other copies, which means deep-copying its own hash
table (strdup keys, ref values) (or setting up a new hash table if it doesn't
have one), and setting the GVariant to NULL

(Or, we could have the "I am independent" flag be explicit, rather than using
presence/absence of the GVariant.)

Then we could get rid of the concept of freezing altogether, and just have:

GVariant *
tp_variant_map_dup_variant (TpVariantMap *self)
{
  if (self->variant == NULL)
    {
      /* reconstitute the GVariant from the GHashTable */
    }

  return g_variant_ref (self->variant);
}

There could even be a version that borrows a GVariant valid until the
TpVariantMap is next modified, although that might be a bit error-prone.

-- 
Configure bugmail: https://bugs.freedesktop.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.



More information about the telepathy-bugs mailing list