X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d0166913d81bcf0b3e47ea2406dfbc9da672e566..d2b354f9c9f1473b2d6ff0ab643ebf57dcbfb656:/src/common/dynlib.cpp diff --git a/src/common/dynlib.cpp b/src/common/dynlib.cpp index 6b824855ad..a452cb2c82 100644 --- a/src/common/dynlib.cpp +++ b/src/common/dynlib.cpp @@ -6,7 +6,7 @@ // Created: 20/07/98 // RCS-ID: $Id$ // Copyright: (c) Guilhem Lavaux -// Licence: wxWindows license +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -27,7 +27,7 @@ #pragma hdrstop #endif -#if wxUSE_DYNLIB_CLASS +#if wxUSE_DYNLIB_CLASS && !wxUSE_DYNAMIC_LOADER #if defined(__WINDOWS__) #include "wx/msw/private.h" @@ -38,6 +38,10 @@ #include "wx/intl.h" #include "wx/log.h" +#if defined(__WXMAC__) + #include "wx/mac/private.h" +#endif + // ---------------------------------------------------------------------------- // conditional compilation // ---------------------------------------------------------------------------- @@ -95,7 +99,11 @@ const char *dlerror(void); // using LoadLibraryEx under Win32 to avoid name clash with LoadLibrary # ifdef __WIN32__ #ifdef _UNICODE +#ifdef __WXWINCE__ +# define wxDllOpen(lib) ::LoadLibrary(lib) +#else # define wxDllOpen(lib) ::LoadLibraryExW(lib, 0, 0) +#endif #else # define wxDllOpen(lib) ::LoadLibraryExA(lib, 0, 0) #endif @@ -105,7 +113,7 @@ const char *dlerror(void); # define wxDllGetSymbol(handle, name) ::GetProcAddress(handle, name) # define wxDllClose ::FreeLibrary #elif defined(__WXMAC__) -# define wxDllClose(handle) CloseConnection(&handle) +# define wxDllClose(handle) CloseConnection(&((CFragConnectionID)handle)) #else # error "Don't know how to load shared libraries on this platform." #endif // OS @@ -142,7 +150,7 @@ wxLibrary::wxLibrary(wxDllType handle) m_handle = handle; // Some system may use a local heap for library. - get_first = (t_get_first)GetSymbol("wxGetClassFirst"); + get_first = (t_get_first)GetSymbol(_T("wxGetClassFirst")); // It is a wxWindows DLL. if (get_first) PrepareClasses(get_first()); @@ -207,6 +215,8 @@ const wxString wxDllLoader::ms_dllext( _T(".sl") ); #else const wxString wxDllLoader::ms_dllext( _T(".so") ); #endif +#elif defined(__WXMAC__) +const wxString wxDllLoader::ms_dllext( _T("") ); #endif /* static */ @@ -242,7 +252,7 @@ wxDllType wxDllLoader::LoadLibrary(const wxString & libname, bool *success) kCFragGoesToEOF, "\p", kPrivateCFragCopy, - &handle, + &((CFragConnectionID)handle), &myMainAddr, myErrName ) != noErr ) { @@ -304,34 +314,34 @@ void *wxDllLoader::GetSymbol(wxDllType dllHandle, const wxString &name, bool *su CFragSymbolClass symClass; Str255 symName; -#if TARGET_CARBON - c2pstrcpy( (StringPtr) symName, name ); -#else - strcpy( (char *) symName, name ); - c2pstr( (char *) symName ); -#endif - if( FindSymbol( dllHandle, symName, &symAddress, &symClass ) == noErr ) + wxMacStringToPascal( name.c_str() , symName ) ; + + if( FindSymbol( ((CFragConnectionID)dllHandle), symName, &symAddress, &symClass ) == noErr ) symbol = (void *)symAddress; #elif defined(__WXPM__) || defined(__EMX__) wxDllGetSymbol(dllHandle, symbol); -#else - // mb_str() is necessary in Unicode build - symbol = wxDllGetSymbol(dllHandle, name.mb_str()); +#else // Windows or Unix + // mb_str() is necessary in Unicode build + // + // "void *" cast is needed by gcc 3.1 + w32api 1.4, don't ask me why +#ifdef __WXWINCE__ + symbol = (void *) wxDllGetSymbol(dllHandle, name.c_str()); +#else + symbol = (void *) wxDllGetSymbol(dllHandle, name.mb_str()); #endif +#endif // OS + if ( !symbol ) { - wxString msg(_("wxDllLoader failed to GetSymbol '%s'")); - #ifdef HAVE_DLERROR const wxChar *err = dlerror(); if( err ) { - failed = TRUE; - wxLogError( msg, err ); + wxLogError(wxT("%s"), err); } #else failed = TRUE; @@ -410,25 +420,21 @@ wxObject *wxLibraries::CreateObject(const wxString& path) return NULL; } -#ifdef __DARWIN__ +#endif // wxUSE_DYNLIB_CLASS && !wxUSE_DYNAMIC_LOADER + +#if defined(__DARWIN__) && (wxUSE_DYNLIB_CLASS || wxUSE_DYNAMIC_LOADER) // --------------------------------------------------------------------------- // For Darwin/Mac OS X // supply the sun style dlopen functions in terms of Darwin NS* // --------------------------------------------------------------------------- -extern "C" { -#import -}; - -enum dyldErrorSource -{ - OFImage, -}; +#include +#include static char dl_last_error[1024]; static -void TranslateError(const char *path, enum dyldErrorSource type, int number) +void TranslateError(const char *path, int number) { unsigned int index; static char *OFIErrorStrings[] = @@ -443,21 +449,11 @@ void TranslateError(const char *path, enum dyldErrorSource type, int number) }; #define NUM_OFI_ERRORS (sizeof(OFIErrorStrings) / sizeof(OFIErrorStrings[0])) - switch (type) - { - case OFImage: - index = number; - if (index > NUM_OFI_ERRORS - 1) { - index = NUM_OFI_ERRORS - 1; - } - sprintf(dl_last_error, OFIErrorStrings[index], path, number); - break; - - default: - sprintf(dl_last_error, "%s(%d): Totally unknown error type %d\n", - path, number, type); - break; + index = number; + if (index > NUM_OFI_ERRORS - 1) { + index = NUM_OFI_ERRORS - 1; } + sprintf(dl_last_error, OFIErrorStrings[index], path, number); } const char *dlerror() @@ -465,7 +461,7 @@ const char *dlerror() return dl_last_error; } -void *dlopen(const char *path, int mode /* mode is ignored */) +void *dlopen(const char *path, int WXUNUSED(mode) /* mode is ignored */) { int dyld_result; NSObjectFileImage ofile; @@ -474,36 +470,39 @@ void *dlopen(const char *path, int mode /* mode is ignored */) dyld_result = NSCreateObjectFileImageFromFile(path, &ofile); if (dyld_result != NSObjectFileImageSuccess) { - TranslateError(path, OFImage, dyld_result); + TranslateError(path, dyld_result); } else { // NSLinkModule will cause the run to abort on any link error's // not very friendly but the error recovery functionality is limited. - handle = NSLinkModule(ofile, path, TRUE); + handle = NSLinkModule(ofile, path, NSLINKMODULE_OPTION_BINDNOW); } return handle; } -int dlclose(void *handle) /* stub only */ +int dlclose(void *handle) { + NSUnLinkModule( handle, NSUNLINKMODULE_OPTION_NONE); return 0; } void *dlsym(void *handle, const char *symbol) { void *addr; + + NSSymbol nsSymbol = NSLookupSymbolInModule( handle , symbol ) ; - if (NSIsSymbolNameDefined(symbol)) { - addr = NSAddressOfSymbol(NSLookupAndBindSymbol(symbol)); + if ( nsSymbol) + { + addr = NSAddressOfSymbol(nsSymbol); } - else { - addr = NULL; + else + { + addr = NULL; } return addr; } -#endif // __DARWIN__ - -#endif // wxUSE_DYNLIB_CLASS +#endif // defined(__DARWIN__) && (wxUSE_DYNLIB_CLASS || wxUSE_DYNAMIC_LOADER)