Warning on explicit cast in libuemf
Hello David, in libuemf/uemf_utf.c, there is
/** \cond */ /* iconv() has a funny cast on some older systems, on most recent ones it is just char **. This tries to work around the issue. If you build this on another funky system this code may need to be modified, or define ICONV_CAST on the compile line(but it may be tricky). */ #ifdef SOL8 #define ICONV_CAST (const char **) #endif //SOL8 #if !defined(ICONV_CAST) #define ICONV_CAST (char **) #endif //ICONV_CAST /** \endcond */
An example of the macro usage: ... status = iconv(conv, ICONV_CAST &src, &srclen, &dst, &dstlen); ...
This generates a warning because, at least on Windows, iconv expects a (const char **) and gcc complains about an unsafe cast. This is not at all trivial, and is a very valid compiler warning. Please read this: http://stackoverflow.com/questions/14562845/why-does-passing-char-as-const-c...
I do not know how to fix this at the moment. Of course I could do an #ifdef for Windows to replace the cast with what iconv wants, but....
Thanks for having a look, Johan
On Mar 20, 2014, at 3:38 PM, Johan Engelen wrote:
Hello David, in libuemf/uemf_utf.c, there is
/** \cond */ /* iconv() has a funny cast on some older systems, on most recent ones it is just char **. This tries to work around the issue. If you build this on another funky system this code may need to be modified, or define ICONV_CAST on the compile line(but it may be tricky). */ #ifdef SOL8 #define ICONV_CAST (const char **) #endif //SOL8 #if !defined(ICONV_CAST) #define ICONV_CAST (char **) #endif //ICONV_CAST /** \endcond */
An example of the macro usage: ... status = iconv(conv, ICONV_CAST &src, &srclen, &dst, &dstlen);
The more "big picture" solution is to just get rid of uemf_utf.c altogether. I'm not sure of all the usage there, but whichever of those reimplemented functions are actually used elsewhere in the folder can just be replaced with use of glib or Glibmm.
The raw C based routines:
https://developer.gnome.org/glib/2.37/glib-Unicode-Manipulation.html
C++ wrapped Glibmm routines (preferred):
https://developer.gnome.org/glibmm/2.37/group__CharsetConv.html ... std::string Glib::convert ( const std::string & str, const std::string & to_codeset, const std::string & from_codeset )
So a rough idea would be to delete uemf_utf.c and uemf_utc.h and replace the conversion use in other files with the standard Glibmm calls.
On 20-Mar-2014 15:38, Johan Engelen wrote:
Hello David, in libuemf/uemf_utf.c, there is
/** \cond */ /* iconv() has a funny cast on some older systems, on most recent ones it is just char **. This tries to work around the issue. If you build this on another funky system this code may need to be modified, or define ICONV_CAST on the compile line(but it may be tricky). */ #ifdef SOL8 #define ICONV_CAST (const char **) #endif //SOL8 #if !defined(ICONV_CAST) #define ICONV_CAST (char **) #endif //ICONV_CAST /** \endcond */
An example of the macro usage: ... status = iconv(conv, ICONV_CAST &src, &srclen, &dst, &dstlen); ...
This generates a warning because, at least on Windows, iconv expects a (const char **) and gcc complains about an unsafe cast.
It is a pain writing iconv code that compiles cleanly everywhere. However, on the systems I have in hand that is the case.
Windows:
gcc -DWIN32 -std=c99 -pedantic -Wall -g -o reademf reademf.c uemf.c uemf_endian.c \ uemf_utf.c uemf_print.c upmf.c upmf_print.c -lm -liconv
No warning generated (gcc 4.6.2 on mingw).
Linux is also clean (ubuntu 12.04LTS, gcc 4.6.3):
gcc -std=c99 -pedantic -Wall -g -o reademf reademf.c uemf.c uemf_endian.c uemf_utf.c \ uemf_print.c upmf.c upmf_print.c -lm
Solaris 8 and 9 (irrelevant for Inkscape) also compile cleanly with the appropriate compile line.
Please send the compiler line you used and the compiler version information. If it was on windows, was it missing the -DWIN32?
Thanks,
David Mathog mathog@...1176... Manager, Sequence Analysis Facility, Biology Division, Caltech
On 21-3-2014 0:36, mathog wrote:
On 20-Mar-2014 15:38, Johan Engelen wrote:
Hello David, in libuemf/uemf_utf.c, there is
/** \cond */ /* iconv() has a funny cast on some older systems, on most recent ones it is just char **. This tries to work around the issue. If you build this on another funky system this code may need to be modified, or define ICONV_CAST on the compile line(but it may be tricky). */ #ifdef SOL8 #define ICONV_CAST (const char **) #endif //SOL8 #if !defined(ICONV_CAST) #define ICONV_CAST (char **) #endif //ICONV_CAST /** \endcond */
An example of the macro usage: ... status = iconv(conv, ICONV_CAST &src, &srclen, &dst, &dstlen); ...
This generates a warning because, at least on Windows, iconv expects a (const char **) and gcc complains about an unsafe cast.
It is a pain writing iconv code that compiles cleanly everywhere. However, on the systems I have in hand that is the case.
Windows:
gcc -DWIN32 -std=c99 -pedantic -Wall -g -o reademf reademf.c uemf.c uemf_endian.c \ uemf_utf.c uemf_print.c upmf.c upmf_print.c -lm -liconv
No warning generated (gcc 4.6.2 on mingw).
Linux is also clean (ubuntu 12.04LTS, gcc 4.6.3):
gcc -std=c99 -pedantic -Wall -g -o reademf reademf.c uemf.c uemf_endian.c uemf_utf.c \ uemf_print.c upmf.c upmf_print.c -lm
Solaris 8 and 9 (irrelevant for Inkscape) also compile cleanly with the appropriate compile line.
Please send the compiler line you used and the compiler version information. If it was on windows, was it missing the -DWIN32?
The reason it compiles cleanly for you is probably due to differences in iconv version. Our devlibs version is: #define _LIBICONV_VERSION 0x0109 with function signature: extern LIBICONV_DLL_EXPORTED size_t iconv (iconv_t cd, const char* * inbuf, size_t *inbytesleft, char* * outbuf, size_t *outbytesleft);
Adding a check for iconv version to adjust the cast to the proper type is the best course of action I think.
thanks, Johan
participants (3)
-
Johan Engelen
-
Jon Cruz
-
mathog