win32: Move dynamic symbol loading to do_dlsym().

This should help get us better error handling when we accidentally
call the wrong loader path.
macos/v1.5.9
Eric Anholt 11 years ago
parent 417927e2eb
commit 5112b477c2
  1. 25
      src/dispatch_common.c

@ -156,7 +156,6 @@ static struct api api = {
#endif #endif
}; };
#ifndef _WIN32
static bool library_initialized; static bool library_initialized;
static void static void
@ -180,6 +179,9 @@ get_dlopen_handle(void **handle, const char *lib_name, bool exit_on_fail)
abort(); abort();
} }
#ifdef _WIN32
*handle = LoadLibraryA(lib_name);
#else
pthread_mutex_lock(&api.mutex); pthread_mutex_lock(&api.mutex);
if (!*handle) { if (!*handle) {
*handle = dlopen(lib_name, RTLD_LAZY | RTLD_LOCAL); *handle = dlopen(lib_name, RTLD_LAZY | RTLD_LOCAL);
@ -189,6 +191,7 @@ get_dlopen_handle(void **handle, const char *lib_name, bool exit_on_fail)
} }
} }
pthread_mutex_unlock(&api.mutex); pthread_mutex_unlock(&api.mutex);
#endif
} }
static void * static void *
@ -199,20 +202,18 @@ do_dlsym(void **handle, const char *lib_name, const char *name,
get_dlopen_handle(handle, lib_name, exit_on_fail); get_dlopen_handle(handle, lib_name, exit_on_fail);
#ifdef _WIN32
result = GetProcAddress(*handle, name);
#else
result = dlsym(*handle, name); result = dlsym(*handle, name);
if (!result) #endif
errx(1, "%s() not found in %s", name, lib_name); if (!result) {
fprintf(stderr,"%s() not found in %s", name, lib_name);
exit(1);
}
return result; return result;
} }
#else
static void *
do_dlsym(void **handle, const char *lib_name, const char *name,
bool exit_on_fail)
{
return NULL;
}
#endif
PUBLIC bool PUBLIC bool
epoxy_is_desktop_gl(void) epoxy_is_desktop_gl(void)
@ -361,7 +362,7 @@ void *
epoxy_gl_dlsym(const char *name) epoxy_gl_dlsym(const char *name)
{ {
#ifdef _WIN32 #ifdef _WIN32
return GetProcAddress(LoadLibraryA("OPENGL32"), name); return do_dlsym(&api.gl_handle, "OPENGL32", name, true);
#elif defined(__APPLE__) #elif defined(__APPLE__)
return do_dlsym(&api.gl_handle, return do_dlsym(&api.gl_handle,
"/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", "/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL",

Loading…
Cancel
Save