X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0b9ab0bd824b6b9c93849928d67de1ec71e7c167..fbf456aa8952c6d2d3edeea1208b0e3159a3cb8d:/src/common/dynlib.cpp diff --git a/src/common/dynlib.cpp b/src/common/dynlib.cpp index 025667914b..91981e3061 100644 --- a/src/common/dynlib.cpp +++ b/src/common/dynlib.cpp @@ -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 // ---------------------------------------------------------------------------- @@ -105,7 +109,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 @@ -207,6 +211,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 +248,7 @@ wxDllType wxDllLoader::LoadLibrary(const wxString & libname, bool *success) kCFragGoesToEOF, "\p", kPrivateCFragCopy, - &handle, + &((CFragConnectionID)handle), &myMainAddr, myErrName ) != noErr ) { @@ -268,7 +274,7 @@ wxDllType wxDllLoader::LoadLibrary(const wxString & libname, bool *success) wxString msg(_("Failed to load shared library '%s'")); #ifdef HAVE_DLERROR - wxChar *err = dlerror(); + const wxChar *err = dlerror(); if( err ) { failed = TRUE; @@ -310,7 +316,7 @@ void *wxDllLoader::GetSymbol(wxDllType dllHandle, const wxString &name, bool *su strcpy( (char *) symName, name ); c2pstr( (char *) symName ); #endif - if( FindSymbol( dllHandle, symName, &symAddress, &symClass ) == noErr ) + if( FindSymbol( ((CFragConnectionID)dllHandle), symName, &symAddress, &symClass ) == noErr ) symbol = (void *)symAddress; #elif defined(__WXPM__) || defined(__EMX__) @@ -327,7 +333,7 @@ void *wxDllLoader::GetSymbol(wxDllType dllHandle, const wxString &name, bool *su wxString msg(_("wxDllLoader failed to GetSymbol '%s'")); #ifdef HAVE_DLERROR - wxChar *err = dlerror(); + const wxChar *err = dlerror(); if( err ) { failed = TRUE; @@ -410,25 +416,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 +445,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() @@ -474,20 +466,21 @@ 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; } @@ -504,6 +497,4 @@ void *dlsym(void *handle, const char *symbol) return addr; } -#endif // __DARWIN__ - -#endif // wxUSE_DYNLIB_CLASS +#endif // defined(__DARWIN__) && (wxUSE_DYNLIB_CLASS || wxUSE_DYNAMIC_LOADER)