//----------------------------------------------------------------------------- DynamicLibrary::DynamicLibrary( const char *filename, bool reportErrors ) { char realname[1024]; hInst = NULL; #if defined(TORQUE_OS_MAC_CARB) if (platState.osX) { dSprintf(realname, 1024, "%s.framework", filename); err = LoadFrameworkBundle(CFSTR(realname), &((CFBundleRef)hInst)); } else #endif { dSprintf(realname, 1024, "\p%s", filename); err = GetSharedLibrary (realname, kAnyCFragArch, // as we want whatever form it is in kReferenceCFrag, // the new name for the kLoadLib flag &((CFragConnectionID)hInst), // holder of codefrag connection identifier NULL, // we don't care NULL); // we don't care } mError = false; mErrorReport = reportErrors; if ( !mInst ) { Con::errorf( "DynamicLibrary: Failed to load %s.", realname ); mInst = NULL; } }
/* ioLoadModule: Load a module from disk. WARNING: this always loads a *new* module. Don't even attempt to find a loaded one. WARNING: never primitiveFail() within, just return 0 */ void* ioLoadModule(char *pluginName) { char pluginDirPath[DOCUMENT_NAME_SIZE+1]; CFragConnectionID libHandle; #ifndef BROWSERPLUGIN #if !defined ( __APPLE__ ) && !defined ( __MACH__ ) Ptr mainAddr; Str255 errorMsg,tempPluginName; OSErr err; #endif #endif /* first, look in the "<Squeak VM directory>Plugins" directory for the library */ getVMPathWithEncoding(pluginDirPath,gCurrentVMEncoding); #ifdef BROWSERPLUGIN createBrowserPluginPath(pluginDirPath); #else strcat(pluginDirPath, "Plugins"); #endif libHandle = LoadLibViaPath(pluginName, pluginDirPath); if (libHandle != nil) return (void *) libHandle; #ifndef BROWSERPLUGIN /* second, look directly in Squeak VM directory for the library */ getVMPathWithEncoding(pluginDirPath,gCurrentVMEncoding); libHandle = LoadLibViaPath(pluginName, pluginDirPath); if (libHandle != nil) return (void*) libHandle; #if !defined ( __APPLE__ ) && !defined ( __MACH__ ) /* Lastly look for it as a shared import library */ CopyCStringToPascal(pluginName,tempPluginName); err = GetSharedLibrary(tempPluginName, kAnyCFragArch, kLoadCFrag, &libHandle, &mainAddr, errorMsg); if (err == noErr) err = GetSharedLibrary(tempPluginName, kAnyCFragArch, kFindCFrag, &libHandle, &mainAddr, errorMsg); if (libHandle != nil) return (void*) libHandle; #else { CFBundleRef mainBundle; CFURLRef bundleURL,bundleURL2,resourceURL; CFStringRef filePath,resourcePathString; mainBundle = CFBundleGetMainBundle(); bundleURL = CFBundleCopyBundleURL(mainBundle); resourceURL = CFBundleCopyResourcesDirectoryURL(mainBundle); resourcePathString = CFURLCopyPath(resourceURL); CFRelease(resourceURL); bundleURL2 = CFURLCreateCopyAppendingPathComponent( kCFAllocatorSystemDefault, bundleURL, resourcePathString, false ); CFRelease(bundleURL); #ifdef MACINTOSHUSEUNIXFILENAMES filePath = CFURLCopyFileSystemPath (bundleURL2, kCFURLPOSIXPathStyle); #else filePath = CFURLCopyFileSystemPath (bundleURL2, kCFURLHFSPathStyle); #endif CFRelease(bundleURL2); CFStringGetCString (filePath,pluginDirPath,DOCUMENT_NAME_SIZE, gCurrentVMEncoding); CFRelease(filePath); libHandle = LoadLibViaPath(pluginName, pluginDirPath); if (libHandle != nil) return (void *) libHandle; } #endif #endif return nil; }