MCPcopy Create free account
hub / github.com/audacity/audacity / Load

Method Load

libraries/lib-module-manager/ModuleManager.cpp:96–168  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

94}
95
96bool Module::Load(wxString &deferredErrorMessage)
97{
98 deferredErrorMessage.clear();
99 // Will this ever happen???
100 if (mLib->IsLoaded()) {
101 if (mDispatch) {
102 return true;
103 }
104
105 // Any messages should have already been generated the first time it was loaded.
106 return false;
107 }
108
109 auto ShortName = wxFileName(mName).GetName();
110
111 // If we hit an error in libdl, it doesn't set errno; you instead
112 // have to use dlerror(), and there is no public integer representation.
113 // Similarly, if Load() fails for anything else that isn't a system
114 // call, errno won't be set, but wxSysErrorMsg() uses errno. So at
115 // least 0 it out beforehand, and let wxDynamicLibrary log errors.
116 errno = 0;
117 if (!mLib->Load(mName, wxDL_NOW | wxDL_GLOBAL)) {
118 // For this failure path, only, there is a possibility of retrial
119 // after some other dependency of this module is loaded. So the
120 // error is not immediately reported.
121 deferredErrorMessage = wxString(wxSysErrorMsg());
122 return false;
123 }
124
125 // Check if the version matches
126 tVersionFn versionFn = (tVersionFn)(mLib->GetSymbol(wxT(versionFnName)));
127 if (versionFn == NULL){
128 DoMessageBox(
129 XO("The module \"%s\" does not provide a version string.\n\nIt will not be loaded.")
130 .Format( ShortName));
131 wxLogMessage(wxT("The module \"%s\" does not provide a version string. It will not be loaded."), mName);
132 mLib->Unload();
133 return false;
134 }
135
136 wxString moduleVersion = versionFn();
137 if (!IsVersionCompatible(moduleVersion)) {
138 DoMessageBox(
139 XO("The module \"%s\" is matched with Audacity version \"%s\".\n\nIt will not be loaded.")
140 .Format(ShortName, moduleVersion));
141 wxLogMessage(wxT("The module \"%s\" is matched with Audacity version \"%s\". It will not be loaded."), mName, moduleVersion);
142 mLib->Unload();
143 return false;
144 }
145
146 mDispatch = (fnModuleDispatch) mLib->GetSymbol(wxT(ModuleDispatchName));
147 if (!mDispatch) {
148 // Module does not provide a dispatch function.
149 return true;
150 }
151
152 // However if we do have it and it does not work,
153 // then the module is bad.

Callers 1

TryLoadModulesMethod · 0.45

Calls 8

IsVersionCompatibleFunction · 0.85
DoMessageBoxFunction · 0.70
wxFileNameClass · 0.50
wxStringClass · 0.50
clearMethod · 0.45
GetNameMethod · 0.45
GetSymbolMethod · 0.45
UnloadMethod · 0.45

Tested by

no test coverage detected