X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Fdlopen.h;h=4d20ff2c7cdab2c381e745642309354aea53ed03;hb=f04d7439a0ad6e13ff2912ff824553b6bcf511a4;hp=9895a22549ae2a7d51dfff40dbb578d7c5088d5a;hpb=9136c9b29ed5c14bc89a4c4e3a391e0b097092e1;p=mesa.git diff --git a/src/mesa/main/dlopen.h b/src/mesa/main/dlopen.h index 9895a22549a..4d20ff2c7cd 100644 --- a/src/mesa/main/dlopen.h +++ b/src/mesa/main/dlopen.h @@ -16,27 +16,82 @@ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. */ #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(HAVE_DLOPEN) + flags = RTLD_LAZY | RTLD_GLOBAL; /* Overriding flags at this time */ + return dlopen(libname, flags); +#elif defined(_WIN32) + 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(HAVE_DLOPEN) + u.v = dlsym(handle, fname); +#elif defined(_WIN32) + 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(HAVE_DLOPEN) + dlclose(handle); +#elif defined(_WIN32) + FreeLibrary(handle); +#else + (void) handle; +#endif +} #endif