|
From: Brian M. <ma...@us...> - 2005-05-29 21:24:26
|
Update of /cvsroot/java-game-lib/LWJGL/src/native/common/devil In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15647/src/native/common/devil Modified Files: extil.c extilu.c extilut.c Log Message: use dlopen to load dynamic libraries Index: extilut.c =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/common/devil/extilut.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- extilut.c 22 May 2005 11:14:00 -0000 1.7 +++ extilut.c 29 May 2005 21:24:18 -0000 1.8 @@ -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 <mach-o/dyld.h> -#include <stdlib.h> -#include <string.h> -static const struct mach_header* devILUThandle; -#include "extilut.h" + #include "extilut.h" + static HMODULE devILUThandle; +#else + #include <dlfcn.h> + #include "extilut.h" + static void* devILUThandle; #endif /** @@ -22,22 +15,9 @@ 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 @@ 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,15 +82,11 @@ 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; } Index: extil.c =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/common/devil/extil.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- extil.c 18 May 2005 17:36:42 -0000 1.9 +++ extil.c 29 May 2005 21:24:18 -0000 1.10 @@ -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 <mach-o/dyld.h> -#include <stdlib.h> -#include <string.h> -const struct mach_header* devILhandle = NULL; -#include "extil.h" + #include "extil.h" + static HMODULE devILhandle; +#else + #include <dlfcn.h> + #include "extil.h" + static void* devILhandle; #endif /** @@ -22,22 +15,9 @@ 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 @@ 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,15 +82,11 @@ 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; } Index: extilu.c =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/common/devil/extilu.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- extilu.c 22 May 2005 11:14:00 -0000 1.8 +++ extilu.c 29 May 2005 21:24:18 -0000 1.9 @@ -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 <mach-o/dyld.h> -#include <stdlib.h> -#include <string.h> -static const struct mach_header* devILUhandle; -#include "extilu.h" + #include "extilu.h" + static HMODULE devILUhandle; +#else + #include <dlfcn.h> + #include "extilu.h" + static void* devILUhandle; #endif /** @@ -22,22 +15,9 @@ 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 @@ 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 @@ 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; } |