GNOME Bugzilla – Bug 570501
g_win32_get_system_data_dirs uses invalid conversion of function pointer to object pointer
Last modified: 2009-02-23 09:53:16 UTC
Please describe the problem: Attempting to build any GTK+ program under Windows using MinGW results in a warning. Example: If your application has 30 source file modules, you will see 30 warnings. Under MSYS this results in about 15 lines worth of crap. It can easily cloud other warnings. I am using -Wall in my CFLAGS. This is the only warning I am receiving. Warning: C:/msys/1.0/include/glib-2.0/glib/gutils.h: In function `g_win32_get_system_data_dirs': C:/msys/1.0/include/glib-2.0/glib/gutils.h:143: warning: ISO C forbids conversion of function pointer to object pointer type Steps to reproduce: Compile any GTK+ application in MSYS using MinGW. Actual results: Warning thrown. Expected results: No warnings. Does this happen every time? Yes. Other information: This bug is related to bug 173098.
Created attachment 127928 [details] [review] my ugly patch I am attaching my (ugly) patch to silence the warning while maintaining ABI type compatibility. Feel free to manipulate it as necessary.
What version of gcc is this, btw? Or do you specifically pass some flag that normally doesn't get used which makes gcc more picky?
Sorry, I should have included that bit of info. $ gcc -v Reading specs from c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/specs Configured with: ../gcc-3.4.5-20060117-3/configure --with-gcc --with-gnu-ld --with-gnu-as --host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --enable-languages=c,c++,f77,ada,objc,java --disable-win32-registry --disable-shared --enable-sjlj-exceptions --enable-libgcj --disable-java-awt --without-x --enable-java-gc=boehm --disable-libgcj-debug --enable-interpreter --enable-hash-synchronization --enable-libstdcxx-debug Thread model: win32 gcc version 3.4.5 (mingw-vista special r3) I am passing -Wall -pedantic -std=c99 It's -pedantic that's exposing this.
Unfortunately your patch removes the -pedantic warning, but it doesn't work. The point in the original code is to pass to g_win32_get_system_data_dirs_for_module() the address of something that is in the code of the module that the compiled inline g_win32_get_system_data_dirs() function has been linked into. It simply passes the address of itself;) The g_win32_get_system_data_dirs_for_module() function then looks up what module (dll or exe) contains that address. Your patch passes the random contents of the uninitialized local variable pfn in that function. Note that for instance passing pfn's address would work either, as it is local and thus on the stack and not in the code (or read-only data) of any module. Having a static const int variable and passing its address might work, but I wouldn't count on it. Instead, to avoid the warning, it should be enough to simply change the type of the parameter of g_win32_get_system_data_dirs_for_module() from gconstpointer to void (*f)(). BTW, I wonder if g_win32_get_system_data_dirs_for_module should be considered part of the documented API of GLib or not? (Unfortunately when I added this stuff, I didn't pay as much attention as I should have to such issues.) I think not, so it would be a good idea to add a comment pointing that out, and perhaps add an initial underscore to its name.
Created attachment 128578 [details] [review] Improved patch
The "unfortunately" is supposed to bind to the "it doesn't work", of course. Sorry for the unclear wording;)
Yes, I should have mentioned my patch just alleviates the warning and wasn't a real fix. Your patch does the job much better. Thanks!
Fixed in glib-2-18 and trunk.