/* findAndLoadModule: Find the module with the given name by, * first looking it up in some (external) shared library * then, by trying to find pluginName_setInterpreter. If the module is found and the initialisers work, add it to the list of loaded modules and return the new module. If anything goes wrong make sure the module is unloaded (WITHOUT calling shutdownModule()) and return NULL. */ static ModuleEntry *findAndLoadModule(char *pluginName, int ffiLoad) { void *handle; ModuleEntry *module; dprintf(("Looking for plugin %s\n", (pluginName ? pluginName : "<intrinsic>"))); /* Try to load the module externally */ handle = ioLoadModule(pluginName); if(ffiLoad) { /* When dealing with the FFI, don't attempt to mess around internally */ if(!handle) return NULL; return addToModuleList(pluginName, handle, ffiLoad); } /* NOT ffiLoad */ if(!handle) { /* might be internal, so go looking for setInterpreter() */ if(findInternalFunctionIn("setInterpreter", pluginName)) handle = squeakModule->handle; else return NULL; /* PluginName_setInterpreter() not found */ } module = addToModuleList(pluginName, handle, ffiLoad); if(!callInitializersIn(module)) { /* Initializers failed */ if(handle != squeakModule->handle) { /* physically unload module */ ioFreeModule(handle); } removeFromList(module); /* remove list entry */ free(module); /* give back space */ module = NULL; } return module; }
/* ioUnloadModule: Unload the module with the given name. */ sqInt ioUnloadModule(const char *moduleName) { ModuleEntry *entry, *temp; if(!squeakModule) return 0; /* Nothing has been loaded */ if(!moduleName || !moduleName[0]) return 0; /* nope */ entry = findLoadedModule(moduleName); if(!entry) return 1; /* module was never loaded */ /* Try to shutdown the module */ if(!shutdownModule(entry)) { /* Could not shut down the module. Bail out. */ return 0; } /* Notify all interested parties about the fact */ temp = firstModule; while(temp) { if(temp != entry) { /* Lookup moduleUnloaded: from the plugin */ void *fn = findFunctionIn("moduleUnloaded", temp); if(fn) { /* call it */ ((sqInt (*) (char *))fn)(entry->name); } } temp = temp->next; } /* And actually unload it if it isn't just the VM... */ if(entry->handle != squeakModule->handle) ioFreeModule(entry->handle); removeFromList(entry); free(entry); /* give back space */ return 1; }
void Private_Shutdown(void) { if (gWhere == NULL) return; if (GetPrivate_Shutdown == NULL) GetPrivate_Shutdown = (void *) ioFindExternalFunctionIn("Private_Shutdown",(int) gWhere); if (GetPrivate_Shutdown == NULL) return; GetPrivate_Shutdown(); ioFreeModule((int) gWhere); gWhere = 0; GetPrivate_Initialize = 0; GetPrivate_Shutdown = 0; GetPrivate_New = 0; GetPrivate_Destroy= 0; GetPrivate_SetWindow= 0; GetPrivate_NewStream= 0; GetPrivate_WriteReady= 0; GetPrivate_Write = 0; GetPrivate_StreamAsFile = 0; GetPrivate_DestroyStream = 0; GetPrivate_HandleEvent = 0; GetPrivate_Print = 0; GetPrivate_URLNotify = 0; GetPrivate_GetJavaClass = 0; }