
On Tue, May 13, 2008 at 12:54:58PM +0100, Daniel P. Berrange wrote:
On Tue, May 13, 2008 at 10:31:10AM +0200, Jim Meyering wrote:
"Daniel P. Berrange" <berrange@redhat.com> wrote:
in spite of the proliferation of casts -- That's not good for readability/maintainability.
What do you think of this?
static inline char *xml2char(xmlChar *x) { return (char *) x; }
The uses are still ugly, but at least they're safer: (note that the parameter cannot be a "const" pointer because the incoming xmlChar* is almost always non-const, as it must be, since it's going to be freed).
I'd suggest going one better and defining a thing wrapper around the xmlNodeGetProp method
char *virXMLGetProp(xmlNodePtr *node, const char *name) { return (char *)xmlNodeGetProp(node, BAD_CAST name); }
That should let us get rid of all these casts throughout the code
The explanation for the casts is that libxml2 uses xmlChar * to indicate that the target string is UTF-8, i.e. you can actually know what's inside without guessing ...
The only potential issue would be that xmlChar * is technically supposed to be free via the xmlFree() method, rather than free(), but I believe they're defined to be identical unless special debug allocators are registered ?
Right, Daniel -- Red Hat Virtualization group http://redhat.com/virtualization/ Daniel Veillard | virtualization library http://libvirt.org/ veillard@redhat.com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/