glib bindings and memory management

David Zeuthen david at fubar.dk
Wed May 4 07:56:42 PDT 2005


On Tue, 2005-05-03 at 02:21 -0400, Colin Walters wrote:
> 2) Map these return values to the GLib types, and have a specific
> protocol for deallocation.  For example, we would do this:
> 
> gboolean
> my_object_foo (MyObject *obj, DBusGArray *array, GArray **ret, GError
                               ^^^^^^^^^^^

Shouldn't this IN parameter be a GArray?

> **error) 
> {
>   int i;
> 
>   *ret = g_array_new (FALSE, TRUE, sizeof (gchar *));
>   for (i = 0; i < array->length; i++) 
>   {
>     char *val = g_strdup_printf ("%d", array->values[i]);
>     g_array_append_val (*ret, val);
>   }
> }
> 
> Note that now we are requiring the dbus library to know that for an
> array of strings, it should individually free() each value, and to use
> g_array_free (arr, TRUE).   The complication here is variants; for those
> we really need the dbus_gvalue_* functions which basically wrap the
> message iter API.  I think this second option is nicer though since it
> feels more native.

I prefer a solution where we don't need DBusGArray.

Cheers,
David




More information about the dbus mailing list