[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [libvirt-glib 1/6] Getters for GVirConfigDomainInterface attributes



On Wed, Feb 29, 2012 at 04:10:29PM +0200, Zeeshan Ali (Khattak) wrote:
> Ah, I just realized why that is so:
> 
> static char *libxml_str_to_glib(xmlChar *str)
> {
>     char *g_str;
> 
>     if (str == NULL)
>         return NULL;
>     g_str = g_strdup((char *)str);
>     xmlFree(str);
> 
>     return g_str;
> }
> 
> This function is not needed as all you needed was to cast the 'xmlChar
> *' to 'const gchar *' and return const from all users of this
> function. Since we still are not API/ABI stable, I propose we change
> this all over as there is no need to force apps to free strings all
> the time and waste processor/memory on all these string
> allocation/de-allocation.

You'll still need to free the input "str", and you have no guarantee that
xmlFree and g_free will call the same function to free memory in the end,
especially in a library. This function is sucky, but there is no clean way
around it as far as I know.
If you really insist on returning const from your getters, you'll need to
cache their value in GVirDomainDevicePrivate

Christophe

Attachment: pgpkjRGWCbBQh.pgp
Description: PGP signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]