X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Fdlopen.h;h=a5366a14e0fcca7b0007c9676aaebf34ac470c12;hb=1a1db1746db82efc7f0643508886dfc78a15eb71;hp=9895a22549ae2a7d51dfff40dbb578d7c5088d5a;hpb=a3ee0aa1bb7c3f9dfc5b13b4e72522c10a22ad05;p=mesa.git diff --git a/src/mesa/main/dlopen.h b/src/mesa/main/dlopen.h index 9895a22549a..a5366a14e0f 100644 --- a/src/mesa/main/dlopen.h +++ b/src/mesa/main/dlopen.h @@ -25,18 +25,85 @@ #ifndef DLOPEN_H #define DLOPEN_H +/** + * Wrapper functions for dlopen(), dlsym(), dlclose(). + * Note that the #ifdef tests for various environments should be expanded. + */ -typedef void (*GenericFunc)(void); - +#if defined(HAVE_DLOPEN) +#include +#endif +#if defined(_WIN32) +#include +#endif -extern void * -_mesa_dlopen(const char *libname, int flags); +typedef void (*GenericFunc)(void); -extern GenericFunc -_mesa_dlsym(void *handle, const char *fname); +/** + * Wrapper for dlopen(). + * Note that 'flags' isn't used at this time. + */ +static inline void * +_mesa_dlopen(const char *libname, int flags) +{ +#if defined(__blrts) + return NULL; +#elif defined(HAVE_DLOPEN) + flags = RTLD_LAZY | RTLD_GLOBAL; /* Overriding flags at this time */ + return dlopen(libname, flags); +#elif defined(__MINGW32__) + return LoadLibraryA(libname); +#else + return NULL; +#endif +} -extern void -_mesa_dlclose(void *handle); +/** + * Wrapper for dlsym() that does a cast to a generic function type, + * rather than a void *. This reduces the number of warnings that are + * generated. + */ +static inline GenericFunc +_mesa_dlsym(void *handle, const char *fname) +{ + union { + void *v; + GenericFunc f; + } u; +#if defined(__blrts) + u.v = NULL; +#elif defined(__DJGPP__) + /* need '_' prefix on symbol names */ + char fname2[1000]; + fname2[0] = '_'; + strncpy(fname2 + 1, fname, 998); + fname2[999] = 0; + u.v = dlsym(handle, fname2); +#elif defined(HAVE_DLOPEN) + u.v = dlsym(handle, fname); +#elif defined(__MINGW32__) + u.v = (void *) GetProcAddress(handle, fname); +#else + u.v = NULL; +#endif + return u.f; +} +/** + * Wrapper for dlclose(). + */ +static inline void +_mesa_dlclose(void *handle) +{ +#if defined(__blrts) + (void) handle; +#elif defined(HAVE_DLOPEN) + dlclose(handle); +#elif defined(__MINGW32__) + FreeLibrary(handle); +#else + (void) handle; +#endif +} #endif