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

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

 



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: pgpW_DTitjYTX.pgp
Description: PGP signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]