diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2026-02-11 15:42:42 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2026-02-11 15:42:42 +0100 |
| commit | e8cebdd573c584dc51c396b35810ca08cb350c82 (patch) | |
| tree | 266e3cd9af7095cf8b53ace8332827ab80507d83 /include/CompilerKit/Utilities/DLL.h | |
| parent | 270dfb1ebd40a848bb5c79cf69cf31325457b20c (diff) | |
feat: CK: Improve codebase and introduce new concepts in DLL.h..
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'include/CompilerKit/Utilities/DLL.h')
| -rw-r--r-- | include/CompilerKit/Utilities/DLL.h | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/include/CompilerKit/Utilities/DLL.h b/include/CompilerKit/Utilities/DLL.h index 92e6a63..f57ec4f 100644 --- a/include/CompilerKit/Utilities/DLL.h +++ b/include/CompilerKit/Utilities/DLL.h @@ -7,11 +7,14 @@ #define NECTAR_COMPILERKIT_UTILITIES_DLL_H #include <CompilerKit/Detail/Config.h> +#include <CompilerKit/Ref.h> #include <dlfcn.h> #include <mutex> namespace CompilerKit { -class DLLLoader final { + +#ifdef CK_POSIX +class ModuleLoader final { public: using EntryT = Int32 (*)(Int32 argc, Char const* argv[]); using HandleT = VoidPtr; @@ -24,40 +27,39 @@ class DLLLoader final { MutexT mMutex; public: - explicit operator bool() { return this->mDLL; } + explicit operator bool() { return this->mDLL != nullptr; } - DLLLoader& operator()(const Char* path, const Char* entrypoint) { - if (!path || !entrypoint) return *this; + ModuleLoader& operator()(const std::string& path, const std::string& entrypoint) { + if (path.empty() || entrypoint.empty()) return *this; std::lock_guard<MutexT> lock(this->mMutex); if (this->mDLL) { - this->Destroy(); + this->Reset(); } - this->mDLL = ::dlopen(path, RTLD_LAZY); + this->mDLL = ::dlopen(path.data(), RTLD_LAZY); if (!this->mDLL) { return *this; } - this->fEntrypoint = reinterpret_cast<EntryT>(::dlsym(this->mDLL, entrypoint)); + this->fEntrypoint = reinterpret_cast<EntryT>(::dlsym(this->mDLL, entrypoint.data())); if (!this->fEntrypoint) { - this->Destroy(); + this->Reset(); return *this; } return *this; } - NECTAR_COPY_DELETE(DLLLoader) + NECTAR_COPY_DELETE(ModuleLoader) - DLLLoader() = default; - ~DLLLoader() { this->Destroy(); } + ModuleLoader() = default; + ~ModuleLoader() { this->Reset(); } - private: - void Destroy() noexcept { + void Reset() noexcept { if (this->mDLL) { ::dlclose(this->mDLL); this->mDLL = nullptr; @@ -66,6 +68,13 @@ class DLLLoader final { this->fEntrypoint = nullptr; } }; + +using StrongDLLRef = StrongRef<ModuleLoader>; +using WeakDLLRef = WeakRef<ModuleLoader>; +#else +#error No ModuleLoader defined. +#endif + } // namespace CompilerKit #endif // NECTAR_COMPILERKIT_UTILITIES_DLL_H |
