Fix strict-aliasing issue in X11 dynamic loader.
Fixes dozens of compiler warnings on FreeBSD.
1.1 --- a/src/video/x11/SDL_x11dyn.c Wed Nov 16 05:20:17 2011 -0500
1.2 +++ b/src/video/x11/SDL_x11dyn.c Wed Nov 16 21:10:03 2011 -0500
1.3 @@ -61,27 +61,30 @@
1.4 { NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR },
1.5 };
1.6
1.7 -static void X11_GetSym(const char *fnname, int *rc, void **fn)
1.8 +static void *X11_GetSym(const char *fnname, int *rc)
1.9 {
1.10 + void *fn = NULL;
1.11 int i;
1.12 for (i = 0; i < SDL_TABLESIZE(x11libs); i++) {
1.13 if (x11libs[i].lib != NULL)
1.14 {
1.15 - *fn = SDL_LoadFunction(x11libs[i].lib, fnname);
1.16 - if (*fn != NULL)
1.17 + fn = SDL_LoadFunction(x11libs[i].lib, fnname);
1.18 + if (fn != NULL)
1.19 break;
1.20 }
1.21 }
1.22
1.23 #if DEBUG_DYNAMIC_X11
1.24 - if (*fn != NULL)
1.25 + if (fn != NULL)
1.26 printf("X11: Found '%s' in %s (%p)\n", fnname, x11libs[i].libname, *fn);
1.27 else
1.28 printf("X11: Symbol '%s' NOT FOUND!\n", fnname);
1.29 #endif
1.30
1.31 - if (*fn == NULL)
1.32 + if (fn == NULL)
1.33 *rc = 0; /* kill this module. */
1.34 +
1.35 + return fn;
1.36 }
1.37
1.38
1.39 @@ -158,14 +161,17 @@
1.40 }
1.41 }
1.42 #define SDL_X11_MODULE(modname) thismod = &SDL_X11_HAVE_##modname;
1.43 - #define SDL_X11_SYM(a,fn,x,y,z) X11_GetSym(#fn,thismod,(void**)&p##fn);
1.44 + #define SDL_X11_SYM(rc,fn,params,args,ret) \
1.45 + p##fn = (rc(*)params) X11_GetSym(#fn, thismod);
1.46 #include "SDL_x11sym.h"
1.47 #undef SDL_X11_MODULE
1.48 #undef SDL_X11_SYM
1.49
1.50 #ifdef X_HAVE_UTF8_STRING
1.51 - X11_GetSym("XCreateIC",&SDL_X11_HAVE_UTF8,(void **)&pXCreateIC);
1.52 - X11_GetSym("XGetICValues",&SDL_X11_HAVE_UTF8,(void **)&pXGetICValues);
1.53 + pXCreateIC = (XIC(*)(XIM,...)) X11_GetSym("XCreateIC",
1.54 + &SDL_X11_HAVE_UTF8);
1.55 + pXGetICValues = (char * (*)(XIC,...)) X11_GetSym("XGetICValues",
1.56 + &SDL_X11_HAVE_UTF8);
1.57 #endif
1.58
1.59 if (SDL_X11_HAVE_BASEXLIB) { /* all required symbols loaded. */