Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add constructor taking native_handle_t #82

Merged
merged 2 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions include/boost/dll/detail/posix/shared_library_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
);
Expand Down
12 changes: 8 additions & 4 deletions include/boost/dll/detail/windows/shared_library_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -142,7 +146,7 @@ class shared_library_impl {
std::errc::operation_not_supported
);

return NULL;
return nullptr;
}

// Judging by the documentation of GetProcAddress
Expand All @@ -151,7 +155,7 @@ class shared_library_impl {
void* const symbol = boost::dll::detail::aggressive_ptr_cast<void*>(
boost::winapi::get_proc_address(handle_, sb)
);
if (symbol == NULL) {
if (symbol == nullptr) {
ec = boost::dll::detail::last_error_code();
}

Expand Down
9 changes: 9 additions & 0 deletions include/boost/dll/shared_library.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Loading