MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / load

Method load

Libraries/Plugin/Plugin.cpp:807–858  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

805}
806
807SC::Result SC::PluginDynamicLibrary::load(const PluginCompiler& compiler, const PluginSysroot& sysroot,
808 StringSpan executablePath)
809{
810 SC_TRY_MSG(not dynamicLibrary.isValid(), "Dynamic Library must be unloaded first");
811 ProcessEnvironment environment;
812 PluginCompilerEnvironment compilerEnvironment;
813
814 size_t index;
815 StringSpan name;
816 if (environment.contains("CFLAGS", &index))
817 {
818 SC_TRY(environment.get(index, name, compilerEnvironment.cFlags));
819 }
820 if (environment.contains("LDFLAGS", &index))
821 {
822 SC_TRY(environment.get(index, name, compilerEnvironment.ldFlags));
823 }
824 lastErrorLog = {};
825
826 Span<char> lastErrorLogCopy = {errorStorage, sizeof(errorStorage) - 1};
827
828 auto deferWrite = MakeDeferred(
829 [&]
830 {
831 if (lastErrorLogCopy.sizeInBytes() > 0)
832 {
833 const size_t last = lastErrorLogCopy.sizeInBytes() - 1;
834 lastErrorLogCopy[last] = 0;
835 }
836 lastErrorLog = {lastErrorLogCopy, true, StringEncoding::Ascii};
837 });
838 SC_TRY_MSG(compiler.compile(definition, sysroot, compilerEnvironment, lastErrorLogCopy), "Compile failed");
839#if SC_PLATFORM_WINDOWS
840 ::Sleep(400); // Sometimes file is locked...
841#endif
842 lastErrorLogCopy = {errorStorage, sizeof(errorStorage) - 1};
843 SC_TRY_MSG(compiler.link(definition, sysroot, compilerEnvironment, executablePath, lastErrorLogCopy), "Link fails");
844 deferWrite.disarm();
845 StringPath buffer;
846 SC_TRY(definition.getDynamicLibraryAbsolutePath(buffer));
847 SC_TRY(dynamicLibrary.load(buffer.view()));
848
849 SC_TRY(PluginString::assign(buffer, {definition.identity.identifier.view(), "Init"}));
850 SC_TRY_MSG(dynamicLibrary.getSymbol(buffer.view(), pluginInit), "Missing #PluginName#Init");
851 SC_TRY(PluginString::assign(buffer, {definition.identity.identifier.view(), "Close"}));
852 SC_TRY_MSG(dynamicLibrary.getSymbol(buffer.view(), pluginClose), "Missing #PluginName#Close");
853 SC_TRY(PluginString::assign(buffer, {definition.identity.identifier.view(), "QueryInterface"}));
854 (void)(dynamicLibrary.getSymbol(buffer.view(), pluginQueryInterface)); // QueryInterface is optional
855 numReloads += 1;
856 lastLoadTime = PluginNow();
857 return Result(true);
858}
859
860void SC::PluginRegistry::init(Span<PluginDynamicLibrary> librariesStorage)
861{

Callers 9

check_dependenciesFunction · 0.45
build_library_recordFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
loadPluginMethod · 0.45
consumePendingWakeUpsMethod · 0.45
getPendingWakeUpsMethod · 0.45
monitoringLoopThreadMethod · 0.45

Calls 14

MakeDeferredFunction · 0.85
PluginNowFunction · 0.85
linkMethod · 0.80
disarmMethod · 0.80
getSymbolMethod · 0.80
assignFunction · 0.50
ResultClass · 0.50
isValidMethod · 0.45
containsMethod · 0.45
getMethod · 0.45
sizeInBytesMethod · 0.45

Tested by

no test coverage detected