GNOME Bugzilla – Bug 734516
GCC warnings on GLib.File.load_contents
Last modified: 2018-05-22 15:14:52 UTC
GLib.File.load_contents produces a warning[1] on gcc with the current vapi in valac 0.24. The warning appears for example in the test-program here: http://valadoc.org/#!api=gio-2.0/GLib.File.load_contents I attached a patch that fixes the warning but breaks backward-compatibility with existing code. [1] the warning ############## teemperor@teemperor-desktop:~/workspace/test$ valac test.vala --pkg gio-2.0 /home/teemperor/workspace/test/test.vala.c: In function ‘_vala_main’: /home/teemperor/workspace/test/test.vala.c:64:3: warning: passing argument 3 of ‘g_file_load_contents’ from incompatible pointer type [enabled by default] g_file_load_contents (_tmp7_, NULL, &_tmp8_, &_tmp9_, &_tmp10_, &_inner_error_); ^ In file included from /usr/include/glib-2.0/gio/gio.h:65:0, from /home/teemperor/workspace/test/test.vala.c:10: /usr/include/glib-2.0/gio/gfile.h:1179:10: note: expected ‘char **’ but argument is of type ‘guint8 **’ gboolean g_file_load_contents (GFile *file, ^ ################
Created attachment 282973 [details] [review] the patch
As general rule of thumb I would recommend just ignoring the C warnings in >99% of time in Vala. While gcc/clang warnings are useful for C programmers who needs to write a correct, clean and maintainable code (but 'codegen' can be quite complicated) it is not so useful for code generators which needs to produce correct code but cannot afford complicated codegen (and don't care about cleanness and correctness). Furthermore in most cases (other then this one) the warnings are moving goal - which is fine for C programmers who already have complicated but 'buggy' codegen (they were suppose to use this variable but they forgot - hence unused variable warning) as opposed to Vala where the simpler the codegen the better (just emit a variable and let C compiler optimize it out). [Note that above paragraph is my opinion only and might not reflect the opinion of Vala devs] For better or worse Vala chosen uint8 as a bytes which are distinct from chars which are (or should be) utf8 code unit. That is fine as C language explicitly allows to cast anything into char * or void * - so current code in Vala is 'correct' (i.e. it doesn't break any C or Vala rule). If you really want to silence the warning something along the line of using [CCode (type = "char **")] might be a better option though IMHO the much better option is just compile with -w option and don't bother with warnings at all - you'll run into even more of them as G/Object headers tend to be for C programmers use so it would require more metadata and more complicated codegen then it's sane.
Review of attachment 282973 [details] [review]: Thanks for the patch. As Maciej wrote, Vala uses `uint8` (always unsigned), not `char` (which may be signed or unsigned) for generic bytes and thus, this patch is incorrect.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/465.