diff --git a/include/boost/dll/detail/posix/shared_library_impl.hpp b/include/boost/dll/detail/posix/shared_library_impl.hpp index ae22f1f4..594cddb0 100644 --- a/include/boost/dll/detail/posix/shared_library_impl.hpp +++ b/include/boost/dll/detail/posix/shared_library_impl.hpp @@ -38,7 +38,7 @@ class shared_library_impl { typedef void* native_handle_t; shared_library_impl() noexcept - : handle_(NULL) + : handle_(nullptr) {} ~shared_library_impl() noexcept { @@ -48,9 +48,13 @@ class shared_library_impl { shared_library_impl(shared_library_impl&& sl) noexcept : handle_(sl.handle_) { - sl.handle_ = NULL; + sl.handle_ = nullptr; } + explicit shared_library_impl(native_handle_t handle) noexcept + : handle_(handle) + {} + shared_library_impl & operator=(shared_library_impl&& sl) noexcept { swap(sl); return *this; @@ -152,7 +156,7 @@ class shared_library_impl { // returned handle is for the main program. ec.clear(); boost::dll::detail::reset_dlerror(); - handle_ = dlopen(NULL, native_mode); + handle_ = dlopen(nullptr, native_mode); if (!handle_) { ec = std::make_error_code( std::errc::bad_file_descriptor @@ -194,7 +198,7 @@ class shared_library_impl { void* symbol_addr(const char* sb, std::error_code &ec) const noexcept { // dlsym - obtain the address of a symbol from a dlopen object void* const symbol = dlsym(handle_, sb); - if (symbol == NULL) { + if (symbol == nullptr) { ec = std::make_error_code( std::errc::invalid_seek ); diff --git a/include/boost/dll/detail/windows/shared_library_impl.hpp b/include/boost/dll/detail/windows/shared_library_impl.hpp index 61fa4201..e573bc17 100644 --- a/include/boost/dll/detail/windows/shared_library_impl.hpp +++ b/include/boost/dll/detail/windows/shared_library_impl.hpp @@ -31,7 +31,7 @@ class shared_library_impl { typedef boost::winapi::HMODULE_ native_handle_t; shared_library_impl() noexcept - : handle_(NULL) + : shared_library_impl(nullptr) {} ~shared_library_impl() noexcept { @@ -41,9 +41,13 @@ class shared_library_impl { shared_library_impl(shared_library_impl&& sl) noexcept : handle_(sl.handle_) { - sl.handle_ = NULL; + sl.handle_ = nullptr; } + explicit shared_library_impl(native_handle_t handle) noexcept + : handle_(handle) + {} + shared_library_impl & operator=(shared_library_impl&& sl) noexcept { swap(sl); return *this; @@ -142,7 +146,7 @@ class shared_library_impl { std::errc::operation_not_supported ); - return NULL; + return nullptr; } // Judging by the documentation of GetProcAddress @@ -151,7 +155,7 @@ class shared_library_impl { void* const symbol = boost::dll::detail::aggressive_ptr_cast( boost::winapi::get_proc_address(handle_, sb) ); - if (symbol == NULL) { + if (symbol == nullptr) { ec = boost::dll::detail::last_error_code(); } diff --git a/include/boost/dll/shared_library.hpp b/include/boost/dll/shared_library.hpp index 30b44f13..f7d8853e 100644 --- a/include/boost/dll/shared_library.hpp +++ b/include/boost/dll/shared_library.hpp @@ -138,6 +138,15 @@ class shared_library shared_library::load(lib_path, mode, ec); } + /*! + * Takes ownership of a loaded library. + * + * \param handle The native handle. + */ + explicit shared_library(native_handle_t handle) noexcept + : base_t(handle) + {} + /*! * Assignment operator. If this->is_loaded() then calls this->unload(). Does not invalidate existing symbols and functions loaded from lib. *