MCPcopy Create free account
hub / github.com/aui-framework/aui / load

Method load

aui.core/src/AUI/Platform/AProgramModule.cpp:24–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22#endif
23
24_<AProgramModule> AProgramModule::load(const AString& path) {
25#if AUI_PLATFORM_WIN
26 auto fullname = path + "." + getDllExtension();
27#else
28 auto doLoad = [](const APath& fp) -> _<AProgramModule> {
29 auto name = fp.toStdString();
30 auto lib = dlopen(name.c_str(), RTLD_LAZY);
31 if (lib) {
32 return aui::ptr::manage(new AProgramModule(lib));
33 }
34 return nullptr;
35 };
36
37 if (APath(path).isRegularFileExists()) {
38 return doLoad(path);
39 }
40 auto fullname = "lib" + path + "." + getDllExtension();
41#endif
42#if AUI_PLATFORM_WIN
43 auto lib = LoadLibrary(aui::win32::toWchar(fullname));
44 if (!lib) {
45 throw LoadException(
46 "Could not load shared library: " + fullname + ": " + AString::number(int(GetLastError())));
47 }
48 return aui::ptr::manage(new AProgramModule(lib));
49#elif AUI_PLATFORM_ANDROID
50 auto name = ("lib" + fullname).toStdString();
51 auto lib = dlopen(name.c_str(), RTLD_LAZY);
52 if (!lib) {
53 throw LoadException("Could not load shared library: " + fullname + ": " + dlerror());
54 }
55 return aui::ptr::manage(new AProgramModule(lib));
56#else
57 char buf[0x1000];
58 getcwd(buf, sizeof(buf));
59
60 APath paths[] = {
61 ""_as, "lib/"_as, AString(buf) + "/", AString(buf) + "/../lib/", "/usr/local/lib/"_as,
62 "/usr/lib/"_as, "/lib/"_as,
63 };
64
65 std::string dlErrors[std::size(paths)];
66
67 size_t counter = 0;
68 for (auto& fp : paths) {
69 try {
70 fp = APath(fp + fullname).absolute();
71 } catch (...) {
72 fp = fp + fullname;
73 }
74 try {
75 if (fp.isRegularFileExists()) {
76 if (auto dll = doLoad(fp)) {
77 return dll;
78 }
79 dlErrors[counter] = dlerror();
80 }
81 } catch (...) {

Callers 1

getMethod · 0.45

Calls 9

APathFunction · 0.85
toWcharFunction · 0.85
numberFunction · 0.85
toStdStringMethod · 0.80
isRegularFileExistsMethod · 0.80
absoluteMethod · 0.80
AStringClass · 0.70
sizeFunction · 0.50
emptyMethod · 0.45

Tested by

no test coverage detected