Consolidate all the X11 libraries, so you don't have to update 12 different
authorRyan C. Gordon <icculus@icculus.org>
Thu, 23 Mar 2006 02:47:56 +0000
changeset 15935115439d67b1
parent 1592 802de24df8d9
child 1594 c439dad53df8
Consolidate all the X11 libraries, so you don't have to update 12 different
places in the source when adding a new one. Also handles build systems that
don't define a given library.
src/video/x11/SDL_x11dyn.c
     1.1 --- a/src/video/x11/SDL_x11dyn.c	Wed Mar 22 22:42:44 2006 +0000
     1.2 +++ b/src/video/x11/SDL_x11dyn.c	Thu Mar 23 02:47:56 2006 +0000
     1.3 @@ -30,41 +30,46 @@
     1.4  #endif
     1.5  
     1.6  #ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC
     1.7 +
     1.8  #include <dlfcn.h>
     1.9  #include "SDL_name.h"
    1.10  #include "SDL_loadso.h"
    1.11 -static const char *x11_library = SDL_VIDEO_DRIVER_X11_DYNAMIC;
    1.12 -static void *x11_handle = NULL;
    1.13 -static const char *x11ext_library = SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT;
    1.14 -static void *x11ext_handle = NULL;
    1.15 -static const char *xrender_library = SDL_VIDEO_DRIVER_X11_DYNAMIC_XRENDER;
    1.16 -static void *xrender_handle = NULL;
    1.17 -static const char *xrandr_library = SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR;
    1.18 -static void *xrandr_handle = NULL;
    1.19  
    1.20  typedef struct
    1.21  {
    1.22      void *lib;
    1.23      const char *libname;
    1.24 -} x11libitem;
    1.25 +} x11dynlib;
    1.26 +
    1.27 +#ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC
    1.28 +#define SDL_VIDEO_DRIVER_X11_DYNAMIC NULL
    1.29 +#endif
    1.30 +#ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT
    1.31 +#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT NULL
    1.32 +#endif
    1.33 +#ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRENDER
    1.34 +#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XRENDER NULL
    1.35 +#endif
    1.36 +#ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR
    1.37 +#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR NULL
    1.38 +#endif
    1.39 +
    1.40 +static x11dynlib x11libs[] =
    1.41 +{
    1.42 +    { NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC },
    1.43 +    { NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT },
    1.44 +    { NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XRENDER },
    1.45 +    { NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR },
    1.46 +};
    1.47  
    1.48  static void *X11_GetSym(const char *fnname, int *rc)
    1.49  {
    1.50  	int i;
    1.51  	void *fn = NULL;
    1.52 -	const x11libitem libs[] =
    1.53 -	{
    1.54 -		{ x11_handle, "libX11" },
    1.55 -		{ x11ext_handle, "libX11ext" },
    1.56 -		{ xrender_handle, "libXrender" },
    1.57 -		{ xrandr_handle, "libXrandr" },
    1.58 -	};
    1.59 -
    1.60 -	for (i = 0; i < (sizeof (libs) / sizeof (libs[0])); i++)
    1.61 -	{
    1.62 -		if (libs[i].lib != NULL)
    1.63 +	for (i = 0; i < SDL_TABLESIZE(x11libs); i++) {
    1.64 +		if (x11libs[i].lib != NULL)
    1.65  		{
    1.66 -			fn = SDL_LoadFunction(libs[i].lib, fnname);
    1.67 +			fn = SDL_LoadFunction(x11libs[i].lib, fnname);
    1.68  			if (fn != NULL)
    1.69  				break;
    1.70  		}
    1.71 @@ -72,7 +77,7 @@
    1.72  
    1.73  	#if DEBUG_DYNAMIC_X11
    1.74  	if (fn != NULL)
    1.75 -	    printf("X11: Found '%s' in %s (%p)\n", fnname, libs[i].libname, fn);
    1.76 +		printf("X11: Found '%s' in %s (%p)\n", fnname, x11libs[i].libname, fn);
    1.77  	else
    1.78  		printf("X11: Symbol '%s' NOT FOUND!\n", fnname);
    1.79  	#endif
    1.80 @@ -115,6 +120,8 @@
    1.81  	/* Don't actually unload if more than one module is using the libs... */
    1.82  	if (x11_load_refcount > 0) {
    1.83  		if (--x11_load_refcount == 0) {
    1.84 +			int i;
    1.85 +
    1.86  			/* set all the function pointers to NULL. */
    1.87  			#define SDL_X11_MODULE(modname) SDL_X11_HAVE_##modname = 1;
    1.88  			#define SDL_X11_SYM(rc,fn,params,args,ret) p##fn = NULL;
    1.89 @@ -122,25 +129,15 @@
    1.90  			#undef SDL_X11_MODULE
    1.91  			#undef SDL_X11_SYM
    1.92  
    1.93 -            #ifdef X_HAVE_UTF8_STRING
    1.94 -            pXCreateIC = NULL;
    1.95 -            #endif
    1.96 +			#ifdef X_HAVE_UTF8_STRING
    1.97 +			pXCreateIC = NULL;
    1.98 +			#endif
    1.99  
   1.100 -			if (x11_handle != NULL) {
   1.101 -				SDL_UnloadObject(x11_handle);
   1.102 -				x11_handle = NULL;
   1.103 -			}
   1.104 -			if (x11ext_handle != NULL) {
   1.105 -				SDL_UnloadObject(x11ext_handle);
   1.106 -				x11ext_handle = NULL;
   1.107 -			}
   1.108 -			if (xrender_handle != NULL) {
   1.109 -				SDL_UnloadObject(xrender_handle);
   1.110 -				xrender_handle = NULL;
   1.111 -			}
   1.112 -			if (xrandr_handle != NULL) {
   1.113 -				SDL_UnloadObject(xrandr_handle);
   1.114 -				xrandr_handle = NULL;
   1.115 +			for (i = 0; i < SDL_TABLESIZE(x11libs); i++) {
   1.116 +				if (x11libs[i].lib != NULL) {
   1.117 +					SDL_UnloadObject(x11libs[i].lib);
   1.118 +					x11libs[i].lib = NULL;
   1.119 +				}
   1.120  			}
   1.121  		}
   1.122  	}
   1.123 @@ -155,11 +152,13 @@
   1.124  	#ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC
   1.125  	/* deal with multiple modules (dga, x11, etc) needing these symbols... */
   1.126  	if (x11_load_refcount++ == 0) {
   1.127 +		int i;
   1.128  		int *thismod = NULL;
   1.129 -		x11_handle = SDL_LoadObject(x11_library);
   1.130 -		x11ext_handle = SDL_LoadObject(x11ext_library);
   1.131 -		xrender_handle = SDL_LoadObject(xrender_library);
   1.132 -		xrandr_handle = SDL_LoadObject(xrandr_library);
   1.133 +		for (i = 0; i < SDL_TABLESIZE(x11libs); i++) {
   1.134 +			if (x11libs[i].libname != NULL) {
   1.135 +				x11libs[i].lib = SDL_LoadObject(x11libs[i].libname);
   1.136 +			}
   1.137 +		}
   1.138  		#define SDL_X11_MODULE(modname) thismod = &SDL_X11_HAVE_##modname;
   1.139  		#define SDL_X11_SYM(a,fn,x,y,z) p##fn = X11_GetSym(#fn,thismod);
   1.140  		#include "SDL_x11sym.h"