diff --git a/src/native/common/devil/extil.c b/src/native/common/devil/extil.c index 74c6a151..1750b7c1 100644 --- a/src/native/common/devil/extil.c +++ b/src/native/common/devil/extil.c @@ -1,18 +1,11 @@ /* Handle to devil Library */ #ifdef _WIN32 -#include "extil.h" -static HMODULE devILhandle; -#endif -#ifdef _X11 -#include "extil.h" -static void* devILhandle; -#endif -#ifdef _MACOSX -#include -#include -#include -const struct mach_header* devILhandle = NULL; -#include "extil.h" + #include "extil.h" + static HMODULE devILhandle; +#else + #include + #include "extil.h" + static void* devILhandle; #endif /** @@ -22,22 +15,9 @@ const struct mach_header* devILhandle = NULL; static void *NativeGetFunctionPointer(const char *function) { #ifdef _WIN32 return GetProcAddress(devILhandle, function); -#endif -#ifdef _X11 +#else return dlsym(devILhandle, function); #endif -#ifdef _MACOSX - char *mac_symbol_name = (char *)malloc((strlen(function) + 2)*sizeof(char)); - if (mac_symbol_name == NULL) - return NULL; - mac_symbol_name[0] = '_'; - strcpy(&(mac_symbol_name[1]), function); - NSSymbol symbol = NSLookupSymbolInImage(devILhandle, mac_symbol_name, NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); - free(mac_symbol_name); - if (symbol == NULL) - return NULL; - return NSAddressOfSymbol(symbol); -#endif } /** @@ -77,12 +57,11 @@ bool extil_Open(JNIEnv *env, jobjectArray ilPaths) { printfDebug("Testing '%s'\n", path_str); #ifdef _WIN32 devILhandle = LoadLibrary(path_str); -#endif -#ifdef _X11 +#else devILhandle = dlopen(path_str, RTLD_LAZY); -#endif -#ifdef _MACOSX - devILhandle = NSAddImage(path_str, NSADDIMAGE_OPTION_RETURN_ON_ERROR); + if(devILhandle == NULL) { + printfDebug("dlopen failure: %s", dlerror()); + } #endif if (devILhandle != NULL) { printfDebug("Found devil at '%s'\n", path_str); @@ -103,14 +82,10 @@ bool extil_Open(JNIEnv *env, jobjectArray ilPaths) { void extil_Close(void) { #ifdef _WIN32 FreeLibrary(devILhandle); -#endif -#ifdef _X11 +#else if (devILhandle != NULL) { dlclose(devILhandle); } -#endif -#ifdef _MACOSX - // Cannot remove the image #endif devILhandle = NULL; } diff --git a/src/native/common/devil/extilu.c b/src/native/common/devil/extilu.c index 04c829e7..bba59c72 100644 --- a/src/native/common/devil/extilu.c +++ b/src/native/common/devil/extilu.c @@ -1,18 +1,11 @@ /* Handle to ilu Library */ #ifdef _WIN32 -#include "extilu.h" -static HMODULE devILUhandle; -#endif -#ifdef _X11 -#include "extilu.h" -static void* devILUhandle; -#endif -#ifdef _MACOSX -#include -#include -#include -static const struct mach_header* devILUhandle; -#include "extilu.h" + #include "extilu.h" + static HMODULE devILUhandle; +#else + #include + #include "extilu.h" + static void* devILUhandle; #endif /** @@ -22,22 +15,9 @@ static const struct mach_header* devILUhandle; static void *NativeGetFunctionPointer(const char *function) { #ifdef _WIN32 return GetProcAddress(devILUhandle, function); -#endif -#ifdef _X11 +#else return dlsym(devILUhandle, function); #endif -#ifdef _MACOSX - char *mac_symbol_name = (char *)malloc((strlen(function) + 2)*sizeof(char)); - if (mac_symbol_name == NULL) - return NULL; - mac_symbol_name[0] = '_'; - strcpy(&(mac_symbol_name[1]), function); - NSSymbol symbol = NSLookupSymbolInImage(devILUhandle, mac_symbol_name, NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); - free(mac_symbol_name); - if (symbol == NULL) - return NULL; - return NSAddressOfSymbol(symbol); -#endif } /** @@ -77,12 +57,11 @@ bool extilu_Open(JNIEnv *env, jobjectArray ilPaths) { printfDebug("Testing '%s'\n", path_str); #ifdef _WIN32 devILUhandle = LoadLibrary(path_str); -#endif -#ifdef _X11 +#else devILUhandle = dlopen(path_str, RTLD_LAZY); -#endif -#ifdef _MACOSX - devILUhandle = NSAddImage(path_str, NSADDIMAGE_OPTION_RETURN_ON_ERROR); + if(devILUhandle == NULL) { + printfDebug("dlopen failure: %s", dlerror()); + } #endif if (devILUhandle != NULL) { printfDebug("Found ilu at '%s'\n", path_str); @@ -103,14 +82,10 @@ bool extilu_Open(JNIEnv *env, jobjectArray ilPaths) { void extilu_Close(void) { #ifdef _WIN32 FreeLibrary(devILUhandle); -#endif -#ifdef _X11 +#else if (devILUhandle != NULL) { dlclose(devILUhandle); } -#endif -#ifdef _MACOSX - // Cannot remove the image #endif devILUhandle = NULL; } diff --git a/src/native/common/devil/extilut.c b/src/native/common/devil/extilut.c index 35544e58..b90ee43c 100644 --- a/src/native/common/devil/extilut.c +++ b/src/native/common/devil/extilut.c @@ -1,18 +1,11 @@ /* Handle to ilut Library */ #ifdef _WIN32 -#include "extilut.h" -static HMODULE devILUThandle; -#endif -#ifdef _X11 -#include "extilut.h" -static void* devILUThandle; -#endif -#ifdef _MACOSX -#include -#include -#include -static const struct mach_header* devILUThandle; -#include "extilut.h" + #include "extilut.h" + static HMODULE devILUThandle; +#else + #include + #include "extilut.h" + static void* devILUThandle; #endif /** @@ -22,22 +15,9 @@ static const struct mach_header* devILUThandle; static void *NativeGetFunctionPointer(const char *function) { #ifdef _WIN32 return GetProcAddress(devILUThandle, function); -#endif -#ifdef _X11 +#else return dlsym(devILUThandle, function); #endif -#ifdef _MACOSX - char *mac_symbol_name = (char *)malloc((strlen(function) + 2)*sizeof(char)); - if (mac_symbol_name == NULL) - return NULL; - mac_symbol_name[0] = '_'; - strcpy(&(mac_symbol_name[1]), function); - NSSymbol symbol = NSLookupSymbolInImage(devILUThandle, mac_symbol_name, NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); - free(mac_symbol_name); - if (symbol == NULL) - return NULL; - return NSAddressOfSymbol(symbol); -#endif } /** @@ -77,12 +57,11 @@ bool extilut_Open(JNIEnv *env, jobjectArray ilPaths) { printfDebug("Testing '%s'\n", path_str); #ifdef _WIN32 devILUThandle = LoadLibrary(path_str); -#endif -#ifdef _X11 +#else devILUThandle = dlopen(path_str, RTLD_LAZY); -#endif -#ifdef _MACOSX - devILUThandle = NSAddImage(path_str, NSADDIMAGE_OPTION_RETURN_ON_ERROR); + if(devILUThandle == NULL) { + printfDebug("dlopen failure: %s", dlerror()); + } #endif if (devILUThandle != NULL) { printfDebug("Found ilut at '%s'\n", path_str); @@ -103,14 +82,10 @@ bool extilut_Open(JNIEnv *env, jobjectArray ilPaths) { void extilut_Close(void) { #ifdef _WIN32 FreeLibrary(devILUThandle); -#endif -#ifdef _X11 +#else if (devILUThandle != NULL) { dlclose(devILUThandle); } -#endif -#ifdef _MACOSX - // Cannot remove the image #endif devILUThandle = NULL; }