From e8cebdd573c584dc51c396b35810ca08cb350c82 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 11 Feb 2026 15:42:42 +0100 Subject: feat: CK: Improve codebase and introduce new concepts in DLL.h.. Signed-off-by: Amlal El Mahrouss --- include/CompilerKit/Utilities/DLL.h | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'include/CompilerKit/Utilities') 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 +#include #include #include 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 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(::dlsym(this->mDLL, entrypoint)); + this->fEntrypoint = reinterpret_cast(::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; +using WeakDLLRef = WeakRef; +#else +#error No ModuleLoader defined. +#endif + } // namespace CompilerKit #endif // NECTAR_COMPILERKIT_UTILITIES_DLL_H -- cgit v1.2.3