GNOME Bugzilla – Bug 677359
libxml-2.0: libxml2 uses xmlChar* for strings, different signedness from gchar*
Last modified: 2013-10-12 04:00:32 UTC
I'm not sure exactly how to correct this. For libxml2 structures and methods that deal with strings, they use xmlChar* and not char* or gchar*. xmlChar is an unsigned char, defined in /usr/include/libxml2/libxml/xmlstring.h, with the note: /** * xmlChar: * * This is a basic byte in an UTF-8 encoded string. * It's unsigned allowing to pinpoint case where char * are assigned * to xmlChar * (possibly making serialization back impossible). */ This of course results in numerous warnings when compiling: make[1]: Entering directory `/home/richard/mine/development/gnome/gdom/gxml/gxml' CC Attr.lo Attr.c: In function 'gxml_dom_attr_real_get_namespace_uri': Attr.c:519:10: warning: pointer targets in assignment differ in signedness [-Wpointer-sign] Attr.c: In function 'gxml_dom_attr_real_get_prefix': Attr.c:550:10: warning: pointer targets in assignment differ in signedness [-Wpointer-sign] I'm not sure if it's a Good Practise, but I usually attentively cast strings to explicitly acknowledge how I'm using them. Is there a solution within the .vapi file that we/I could implement that could deal with the type difference?
Strings in Vala are UTF-8, and gchar* is used throughout the GLib ecosystem for UTF-8 strings. My understanding is that, historically, people have put character encodings other than UTF-8 and ASCII (e.g., ISO 8859-1) into char* buffers, and libxml2 is just requiring a cast to make sure you're actually thinking about what you're passing. In other words, if you're really using UTF-8 (and again, string is UTF-8 in Vala), those warnings are just useless noise. If you really want you can sprinkle [CCode (type = "xmlChar*")] attributes on every string argument (I can't remember whether it will work for return values) in libxml2.vapi.
Created attachment 247781 [details] [review] Sets type attribute for xmlChar* params This adds [CCode (type = "xmlChar*")] before string parametres that are actually xmlChar* in C. This had to be carefully done, since libxml2 sometimes uses char* strings.
Created attachment 247782 [details] [review] Sets type attribute for xmlChar* fields This adds [CCode (type = "xmlChar*")] before string fields that are actually xmlChar* in C. This had to be carefully done, since libxml2 sometimes uses char* strings. (NOTE: this won't make a difference until bug 703086 is resolved, since type does not currently apply to fields.)
Created attachment 247783 [details] [review] Sets type attribute for xmlChar* return values This adds [CCode (type = "xmlChar*")] before string return values that are actually xmlChar* in C. This had to be carefully done, since libxml2 sometimes uses char* strings. (NOTE: this won't make a difference until bug 703086 is resolved, since type does not currently apply to return values.)
Created attachment 247784 [details] [review] Sets type attribute for xmlChar* return values For return types. Previous attempt included a chunk that won't apply without yet another patch. :)
commit 49b5b326f77e3643e55b9b3a832b2a0ad4a5e0a8 Author: Richard Schwarting <aquarichy@gmail.com> Date: Fri Oct 11 20:56:52 2013 -0700 libxml-2.0: add CCode type annotations for xmlChar* strings. Fixes bug 677359.