X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/58e8de26aa99eb713a50cdd872ff7c86b372e0fd..00421206821da3373ddc075d63149826b3be38af:/src/common/dynlib.cpp diff --git a/src/common/dynlib.cpp b/src/common/dynlib.cpp index 57820da629..b4a60768fb 100644 --- a/src/common/dynlib.cpp +++ b/src/common/dynlib.cpp @@ -27,46 +27,43 @@ #pragma hdrstop #endif //__BORLANDC__ -// TODO should be done by configure -#if defined(__UNIX__) && !(defined(HAVE_DLOPEN) || defined(HAVE_SHLLOAD)) - #if defined(__LINUX__) || defined(__SOLARIS__) || defined(__SUNOS__) || defined(__FREEBSD__) - #ifndef HAVE_DLOPEN - #define HAVE_DLOPEN - #endif - #elif defined(__HPUX__) - #ifndef HAVE_SHLLOAD - #define HAVE_SHLLOAD - #endif - #endif // Unix flavour -#endif // !Unix or already have some HAVE_xxx defined +#if wxUSE_DYNLIB_CLASS #include "wx/dynlib.h" #include "wx/filefn.h" #include "wx/intl.h" #include "wx/log.h" +#include "wx/tokenzr.h" // ---------------------------------------------------------------------------- // conditional compilation // ---------------------------------------------------------------------------- #if defined(HAVE_DLOPEN) - #define wxDllOpen(lib) dlopen(lib, RTLD_LAZY) - #define wxDllGetSymbol(handle, name) dlsym(handle, (char *)name) + #define wxDllOpen(lib) dlopen(lib.fn_str(), RTLD_LAZY) + #define wxDllGetSymbol(handle, name) dlsym(handle, name.mb_str()) #define wxDllClose dlclose -#elif defined(HAVE_SHLLOAD) - #define wxDllOpen(lib) shl_open(lib, BIND_DEFERRED, 0) +#elif defined(HAVE_SHL_LOAD) + #define wxDllOpen(lib) shl_load(lib.fn_str(), BIND_DEFERRED, 0) #define wxDllClose shl_unload - static inline void *wxDllGetSymbol(shl_t *handle, const char *name) + static inline void *wxDllGetSymbol(shl_t handle, const wxString& name) { void *sym; - if ( shl_findsym(handle, name, TYPE_UNDEFINED, &sym) == 0 ) + if ( shl_findsym(&handle, name.mb_str(), TYPE_UNDEFINED, &sym) == 0 ) return sym; else return (void *)0; } #elif defined(__WINDOWS__) - #define wxDllOpen(lib) ::LoadLibrary(lib) + #include + + // using LoadLibraryEx under Win32 to avoid name clash with LoadLibrary + #ifdef __WIN32__ + #define wxDllOpen(lib) ::LoadLibraryEx(lib, 0, 0) + #else // Win16 + #define wxDllOpen(lib) ::LoadLibrary(lib) + #endif // Win32/16 #define wxDllGetSymbol(handle, name) ::GetProcAddress(handle, name) #define wxDllClose ::FreeLibrary #else @@ -90,7 +87,11 @@ static wxString ConstructLibraryName(const wxString& basename) wxString fullname(basename); #if defined(__UNIX__) - fullname << ".so"; + #if defined(__HPUX__) + fullname << ".sl"; + #else //__HPUX__ + fullname << ".so"; + #endif //__HPUX__ #elif defined(__WINDOWS__) fullname << ".dll"; #endif @@ -178,9 +179,7 @@ void *wxLibrary::GetSymbol(const wxString& symbname) symbol = (void *)symAddress ; } #else - // VZ: hmm... why is WXSTRINGCAST needed? if it's really modified, we - // should make a copy of it - symbol = wxDllGetSymbol(m_handle, WXSTRINGCAST symbname); + symbol = wxDllGetSymbol(m_handle, symbname); #endif if ( !symbol ) @@ -228,11 +227,30 @@ wxLibrary *wxLibraries::LoadLibrary(const wxString& name) wxString lib_name = ConstructLibraryName(name); #if defined(__UNIX__) - // TODO use LD_LIBRARY_PATH! - lib_name.Prepend("/lib"); + // found the first file in LD_LIBRARY_PATH with this name + wxString libPath("/lib:/usr/lib"); // system path first + const char *envLibPath = getenv("LD_LIBRARY_PATH"); + if ( envLibPath ) + libPath << ':' << envLibPath; + wxStringTokenizer tokenizer(libPath, _T(':')); + while ( tokenizer.HasMoreToken() ) + { + wxString fullname(tokenizer.NextToken()); + + fullname << '/' << lib_name; + if ( wxFileExists(fullname) ) + { + lib_name = fullname; + + // found the library + break; + } + } + //else: not found in the path, leave the name as is (secutiry risk?) + #endif // __UNIX__ - wxDllType handle ; + wxDllType handle; #if defined(__WXMAC__) FSSpec myFSSpec ; @@ -282,3 +300,5 @@ wxObject *wxLibraries::CreateObject(const wxString& path) } return NULL; } + +#endif // wxUSE_DYNLIB_CLASS