glib bindings and memory management

Havoc Pennington hp at redhat.com
Wed May 4 13:46:50 PDT 2005


On Wed, 2005-05-04 at 16:09 -0400, Colin Walters wrote:
> 
> In particular I feel fairly strongly that "a{s?}" must map to
> GHashTable, or we haven't actually gained a lot from the glib bindings
> except that stuff is allocated using g_malloc and variants are GValue,
> which to me is nearly negligible.

I'm not sure this is true (you've still avoided a bunch of manual
boilerplate code - "native types" isn't the whole point of a binding)
but I don't disagree with the substance of your point, just footnoting
that there is other value.

> for (i = 0; i < arr->len; i++) {
>    FooValue *elt = &(g_array_index (arr, i]));
>    g_free (elt->name);
>    g_value_unset (elt->val);
>    g_hash_table_destroy (elt->table);
> }

What if we introduce a dbus_g_free_complex_value() (OK, let's work on
the name) and put the above code snippet in a destructor at the front of
the malloc block? i.e. for simple cases where there's an existing GLib
call to free (g_free, g_hash_table_destroy()) then that existing call
has to be used. For complex cases you have to call the special dbus free
thing.

I pretty strongly agree with your point that we should be sure the basic
cases are really nice, even if it's at the expense of the complex
cases. 

Havoc




More information about the dbus mailing list