From 8ace61ce7ddaaf2d756f405669ac004046683e64 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sun, 23 Feb 2020 02:17:27 +0100 Subject: [PATCH] DynLib: Posix fixes --- src/Nazara/Core/Posix/DynLibImpl.cpp | 27 +++++++++++++-------------- src/Nazara/Core/Posix/DynLibImpl.hpp | 7 ++++--- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Nazara/Core/Posix/DynLibImpl.cpp b/src/Nazara/Core/Posix/DynLibImpl.cpp index f519c916f..6311b44e6 100644 --- a/src/Nazara/Core/Posix/DynLibImpl.cpp +++ b/src/Nazara/Core/Posix/DynLibImpl.cpp @@ -10,12 +10,18 @@ namespace Nz { - DynLibImpl::DynLibImpl(DynLib* parent) + DynLibImpl::DynLibImpl(DynLib*) : + m_handle(nullptr) { - NazaraUnused(parent); } - DynLibFunc DynLibImpl::GetSymbol(const String& symbol, String* errorMessage) const + DynLibImpl::~DynLibImpl() + { + if (m_handle) + dlclose(m_handle); + } + + DynLibFunc DynLibImpl::GetSymbol(const char* symbol, std::string* errorMessage) const { /* Il n'est pas standard de cast un pointeur d'objet vers un pointeur de fonction. @@ -31,19 +37,17 @@ namespace Nz dlerror(); // Clear error flag - converter.pointer = dlsym(m_handle, symbol.GetConstBuffer()); + converter.pointer = dlsym(m_handle, symbol); if (!converter.pointer) *errorMessage = dlerror(); return converter.func; } - bool DynLibImpl::Load(const String& libraryPath, String* errorMessage) + bool DynLibImpl::Load(const std::filesystem::path& libraryPath, std::string* errorMessage) { - String path = libraryPath; - - size_t pos = path.FindLast(".so"); - if (pos == String::npos || (path.GetLength() > pos+3 && path[pos+3] != '.')) + std::filesystem::path path = libraryPath; + if (path.extension() != ".so") path += ".so"; dlerror(); // Clear error flag @@ -57,9 +61,4 @@ namespace Nz return false; } } - - void DynLibImpl::Unload() - { - dlclose(m_handle); - } } diff --git a/src/Nazara/Core/Posix/DynLibImpl.hpp b/src/Nazara/Core/Posix/DynLibImpl.hpp index e101abc84..10b38addf 100644 --- a/src/Nazara/Core/Posix/DynLibImpl.hpp +++ b/src/Nazara/Core/Posix/DynLibImpl.hpp @@ -8,6 +8,8 @@ #define NAZARA_DYNLIBIMPL_HPP #include +#include +#include namespace Nz { @@ -19,9 +21,8 @@ namespace Nz DynLibImpl(DynLib* m_parent); ~DynLibImpl() = default; - DynLibFunc GetSymbol(const String& symbol, String* errorMessage) const; - bool Load(const String& libraryPath, String* errorMessage); - void Unload(); + DynLibFunc GetSymbol(const char* symbol, std::string* errorMessage) const; + bool Load(const std::filesystem::path& libraryPath, std::string* errorMessage); private: void* m_handle;