Update
CI / GCC 16 / C++26 / default (pull_request) Has been cancelled
CI / GCC 16 / C++26 / sanitizers (pull_request) Has been cancelled
CI / GCC 16 / C++26 / werror (pull_request) Has been cancelled

Signed-off-by: faumaray <faumaray@gmail.com>
This commit is contained in:
faumaray committed 2026-07-12 02:37:49 +03:00
1 parent 9a54f15e7e
commit f94366104e
7 files changed
+100 -13

No files matched your search

+23 -4
View File
@@ -23,6 +23,7 @@ std::string_view to_string(LoadError e) noexcept
case LoadError::CreateFailed: return "plugin create() returned null";
case LoadError::NotSupported: return "platform does not support dlopen";
case LoadError::StateRejected: return "new instance rejected state";
case LoadError::ActivationFailed: return "plugin activation failed";
case LoadError::UnknownPlugin: return "no plugin registered under name";
}
return "unknown";
@@ -44,6 +45,7 @@ void PluginLoader::destroy_current() noexcept
}
destroy_ = nullptr;
transfer_ = nullptr;
ready_ = nullptr;
state_version_ = nullptr;
serialize_ = nullptr;
free_string_ = nullptr;
@@ -121,6 +123,7 @@ PluginLoader::load_from(const std::filesystem::path& path)
plugin_ = static_cast<IPlugin*>(raw);
destroy_ = sym_destroy;
transfer_ = reinterpret_cast<transfer_fn>(dlsym(h, kTransferSymbol));
ready_ = reinterpret_cast<ready_fn>(dlsym(h, kReadySymbol));
state_version_ = reinterpret_cast<state_version_fn>(
dlsym(h, kStateVersionSymbol));
serialize_ = reinterpret_cast<serialize_fn>(dlsym(h, kSerializeSymbol));
@@ -153,7 +156,14 @@ PluginLoader::load(std::filesystem::path path)
return std::unexpected{r.error()};
}
ldr.plugin_->on_load();
try {
ldr.plugin_->on_load();
} catch (...) {
return std::unexpected{LoadError::ActivationFailed};
}
if (ldr.ready_ && ldr.ready_(ldr.plugin_) != 0) {
return std::unexpected{LoadError::ActivationFailed};
}
Void::Log::info("Plugin", "loaded '{}' ({} v{})", path.string(),
ldr.info_.name, ldr.info_.plugin_version);
return ldr;
@@ -166,6 +176,7 @@ PluginLoader::PluginLoader(PluginLoader&& o) noexcept
, plugin_ {std::exchange(o.plugin_, nullptr)}
, destroy_ {std::exchange(o.destroy_, nullptr)}
, transfer_ {std::exchange(o.transfer_, nullptr)}
, ready_ {std::exchange(o.ready_, nullptr)}
, state_version_{std::exchange(o.state_version_, nullptr)}
, serialize_ {std::exchange(o.serialize_, nullptr)}
, free_string_ {std::exchange(o.free_string_, nullptr)}
@@ -182,6 +193,7 @@ PluginLoader& PluginLoader::operator=(PluginLoader&& o) noexcept
plugin_ = std::exchange(o.plugin_, nullptr);
destroy_ = std::exchange(o.destroy_, nullptr);
transfer_ = std::exchange(o.transfer_, nullptr);
ready_ = std::exchange(o.ready_, nullptr);
state_version_ = std::exchange(o.state_version_, nullptr);
serialize_ = std::exchange(o.serialize_, nullptr);
free_string_ = std::exchange(o.free_string_, nullptr);
@@ -228,11 +240,18 @@ std::expected<void, LoadError> PluginLoader::reload()
return std::unexpected{LoadError::StateRejected};
}
// Destroy old, install new.
try {
next.plugin_->on_load();
} catch (...) {
return std::unexpected{LoadError::ActivationFailed};
}
if (next.ready_ && next.ready_(next.plugin_) != 0) {
return std::unexpected{LoadError::ActivationFailed};
}
// Activation succeeded; only now destroy old and install new.
destroy_current();
*this = std::move(next);
plugin_->on_load();
Void::Log::info("Plugin", "reloaded '{}' ({} v{})", path_.string(),
info_.name, info_.plugin_version);