After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 677359 - libxml-2.0: libxml2 uses xmlChar* for strings, different signedness from gchar*
libxml-2.0: libxml2 uses xmlChar* for strings, different signedness from gchar*
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Bindings
0.17.x
Other Linux
: Low trivial
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2012-06-02 21:52 UTC by Richard Schwarting
Modified: 2013-10-12 04:00 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Sets type attribute for xmlChar* params (36.90 KB, patch)
2013-06-25 23:20 UTC, Richard Schwarting
none Details | Review
Sets type attribute for xmlChar* fields (4.78 KB, patch)
2013-06-25 23:23 UTC, Richard Schwarting
none Details | Review
Sets type attribute for xmlChar* return values (9.51 KB, patch)
2013-06-25 23:24 UTC, Richard Schwarting
none Details | Review
Sets type attribute for xmlChar* return values (9.24 KB, patch)
2013-06-25 23:26 UTC, Richard Schwarting
none Details | Review

Description Richard Schwarting 2012-06-02 21:52:35 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?
Comment 1 Evan Nemerson 2012-06-07 22:32:01 UTC
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.
Comment 2 Richard Schwarting 2013-06-25 23:20:42 UTC
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.
Comment 3 Richard Schwarting 2013-06-25 23:23:23 UTC
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.)
Comment 4 Richard Schwarting 2013-06-25 23:24:14 UTC
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.)
Comment 5 Richard Schwarting 2013-06-25 23:26:20 UTC
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. :)
Comment 6 Evan Nemerson 2013-10-12 04:00:32 UTC
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.