Add 20+ new modules with tests: Pipeline, Matrix, Tokenizer, ScopeGuard, Bitset, Optional, Counted, Curry, TypeMap, Bench, DisjointSet, Histogram, StopWatch, and more
Also fixes Diff/Memo/PriorityQueue from previous session: LineDiff is now an alias for Edit<string> so count_op/apply work on line diffs; Memoized uses std::apply instead of type-based get to handle duplicate arg types. 874/877 tests pass (3 are platform-gated plugin tests). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
cb4dd58500
commit
58ff7b38a0
65 files changed
+8987
-37
No files matched your search
@@ -0,0 +1,73 @@
|
||||
#pragma once
|
||||
|
||||
#include <Void/Plugin/Plugin.hpp>
|
||||
|
||||
#include <expected>
|
||||
#include <filesystem>
|
||||
#include <string_view>
|
||||
|
||||
namespace Void::Plugin
|
||||
{
|
||||
|
||||
enum class LoadError {
|
||||
FileNotFound,
|
||||
DlopenFailed,
|
||||
SymbolMissing,
|
||||
AbiMismatch,
|
||||
CreateFailed,
|
||||
NotSupported, // platform does not support dlopen
|
||||
};
|
||||
|
||||
[[nodiscard]] std::string_view to_string(LoadError e) noexcept;
|
||||
|
||||
// ── PluginLoader ──────────────────────────────────────────────────────────────
|
||||
// Owns one plugin instance loaded from a shared library.
|
||||
//
|
||||
// Hot-reload protocol:
|
||||
// 1. The new .so (at the same canonical path) is copied to a temp file so
|
||||
// dlopen gets a fresh inode even if the path was already cached.
|
||||
// 2. New instance is created and optional transfer_state() called (both
|
||||
// old and new instances are alive simultaneously at this point).
|
||||
// 3. Old instance is destroyed and old handle is closed.
|
||||
//
|
||||
// Thread safety: not thread-safe. Protect with external locking if needed.
|
||||
|
||||
class PluginLoader {
|
||||
public:
|
||||
[[nodiscard]] static std::expected<PluginLoader, LoadError>
|
||||
load(std::filesystem::path path);
|
||||
|
||||
~PluginLoader();
|
||||
PluginLoader(PluginLoader&&) noexcept;
|
||||
PluginLoader& operator=(PluginLoader&&) noexcept;
|
||||
PluginLoader(const PluginLoader&) = delete;
|
||||
PluginLoader& operator=(const PluginLoader&) = delete;
|
||||
|
||||
[[nodiscard]] IPlugin* plugin() noexcept { return plugin_; }
|
||||
[[nodiscard]] const IPlugin* plugin() const noexcept { return plugin_; }
|
||||
[[nodiscard]] const PluginInfo& info() const noexcept { return info_; }
|
||||
[[nodiscard]] bool loaded() const noexcept { return handle_ != nullptr; }
|
||||
|
||||
IPlugin* operator->() noexcept { return plugin_; }
|
||||
|
||||
// Hot-reload: copies current .so to a temp file (fresh inode), loads it,
|
||||
// transfers state, then destroys old instance and swaps handles.
|
||||
[[nodiscard]] std::expected<void, LoadError> reload();
|
||||
|
||||
private:
|
||||
PluginLoader() = default;
|
||||
|
||||
void* handle_ {};
|
||||
IPlugin* plugin_ {};
|
||||
destroy_fn destroy_ {};
|
||||
transfer_fn transfer_{};
|
||||
PluginInfo info_ {};
|
||||
std::filesystem::path path_;
|
||||
|
||||
[[nodiscard]] std::expected<void, LoadError>
|
||||
load_from(const std::filesystem::path& path);
|
||||
|
||||
void destroy_current() noexcept;
|
||||
};
|
||||
|
||||
} // namespace Void::Plugin
|
||||
Reference in new issue
Block a user