updated boost on windows
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// Copyright 2014 Renato Tegon Forti, Antony Polukhin.
|
||||
// Copyright 2015 Antony Polukhin.
|
||||
// Copyright 2015-2019 Antony Polukhin.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt
|
||||
@@ -8,11 +8,10 @@
|
||||
#ifndef BOOST_DLL_DETAIL_WINDOWS_PATH_FROM_HANDLE_HPP
|
||||
#define BOOST_DLL_DETAIL_WINDOWS_PATH_FROM_HANDLE_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/dll/config.hpp>
|
||||
#include <boost/dll/detail/system_error.hpp>
|
||||
#include <boost/detail/winapi/dll.hpp>
|
||||
#include <boost/detail/winapi/get_last_error.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/winapi/dll.hpp>
|
||||
#include <boost/winapi/get_last_error.hpp>
|
||||
|
||||
#ifdef BOOST_HAS_PRAGMA_ONCE
|
||||
# pragma once
|
||||
@@ -20,40 +19,43 @@
|
||||
|
||||
namespace boost { namespace dll { namespace detail {
|
||||
|
||||
static inline boost::system::error_code last_error_code() BOOST_NOEXCEPT {
|
||||
boost::detail::winapi::DWORD_ err = boost::detail::winapi::GetLastError();
|
||||
return boost::system::error_code(
|
||||
err,
|
||||
boost::system::system_category()
|
||||
inline boost::dll::fs::error_code last_error_code() BOOST_NOEXCEPT {
|
||||
boost::winapi::DWORD_ err = boost::winapi::GetLastError();
|
||||
return boost::dll::fs::error_code(
|
||||
static_cast<int>(err),
|
||||
boost::dll::fs::system_category()
|
||||
);
|
||||
}
|
||||
|
||||
inline boost::filesystem::path path_from_handle(boost::detail::winapi::HMODULE_ handle, boost::system::error_code &ec) {
|
||||
BOOST_STATIC_CONSTANT(boost::detail::winapi::DWORD_, ERROR_INSUFFICIENT_BUFFER_ = 0x7A);
|
||||
BOOST_STATIC_CONSTANT(boost::detail::winapi::DWORD_, DEFAULT_PATH_SIZE_ = 260);
|
||||
inline boost::dll::fs::path path_from_handle(boost::winapi::HMODULE_ handle, boost::dll::fs::error_code &ec) {
|
||||
BOOST_STATIC_CONSTANT(boost::winapi::DWORD_, ERROR_INSUFFICIENT_BUFFER_ = 0x7A);
|
||||
BOOST_STATIC_CONSTANT(boost::winapi::DWORD_, DEFAULT_PATH_SIZE_ = 260);
|
||||
|
||||
// On success, GetModuleFileNameW() doesn't reset last error to ERROR_SUCCESS. Resetting it manually.
|
||||
boost::winapi::GetLastError();
|
||||
|
||||
// If `handle` parameter is NULL, GetModuleFileName retrieves the path of the
|
||||
// executable file of the current process.
|
||||
boost::detail::winapi::WCHAR_ path_hldr[DEFAULT_PATH_SIZE_];
|
||||
boost::detail::winapi::GetModuleFileNameW(handle, path_hldr, DEFAULT_PATH_SIZE_);
|
||||
ec = last_error_code();
|
||||
boost::winapi::WCHAR_ path_hldr[DEFAULT_PATH_SIZE_];
|
||||
boost::winapi::GetModuleFileNameW(handle, path_hldr, DEFAULT_PATH_SIZE_);
|
||||
ec = boost::dll::detail::last_error_code();
|
||||
if (!ec) {
|
||||
return boost::filesystem::path(path_hldr);
|
||||
return boost::dll::fs::path(path_hldr);
|
||||
}
|
||||
|
||||
for (unsigned i = 2; i < 1025 && static_cast<boost::detail::winapi::DWORD_>(ec.value()) == ERROR_INSUFFICIENT_BUFFER_; i *= 2) {
|
||||
for (unsigned i = 2; i < 1025 && static_cast<boost::winapi::DWORD_>(ec.value()) == ERROR_INSUFFICIENT_BUFFER_; i *= 2) {
|
||||
std::wstring p(DEFAULT_PATH_SIZE_ * i, L'\0');
|
||||
const std::size_t size = boost::detail::winapi::GetModuleFileNameW(handle, &p[0], DEFAULT_PATH_SIZE_ * i);
|
||||
ec = last_error_code();
|
||||
const std::size_t size = boost::winapi::GetModuleFileNameW(handle, &p[0], DEFAULT_PATH_SIZE_ * i);
|
||||
ec = boost::dll::detail::last_error_code();
|
||||
|
||||
if (!ec) {
|
||||
p.resize(size);
|
||||
return boost::filesystem::path(p);
|
||||
return boost::dll::fs::path(p);
|
||||
}
|
||||
}
|
||||
|
||||
// Error other than ERROR_INSUFFICIENT_BUFFER_ occurred or failed to allocate buffer big enough
|
||||
return boost::filesystem::path();
|
||||
// Error other than ERROR_INSUFFICIENT_BUFFER_ occurred or failed to allocate buffer big enough.
|
||||
return boost::dll::fs::path();
|
||||
}
|
||||
|
||||
}}} // namespace boost::dll::detail
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright 2014 Renato Tegon Forti, Antony Polukhin.
|
||||
// Copyright 2015-2016 Antony Polukhin.
|
||||
// Copyright 2015-2019 Antony Polukhin.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt
|
||||
@@ -8,7 +8,7 @@
|
||||
#ifndef BOOST_DLL_SHARED_LIBRARY_IMPL_HPP
|
||||
#define BOOST_DLL_SHARED_LIBRARY_IMPL_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/dll/config.hpp>
|
||||
#include <boost/dll/shared_library_load_mode.hpp>
|
||||
#include <boost/dll/detail/aggressive_ptr_cast.hpp>
|
||||
#include <boost/dll/detail/system_error.hpp>
|
||||
@@ -16,10 +16,8 @@
|
||||
|
||||
#include <boost/move/utility.hpp>
|
||||
#include <boost/swap.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
#include <boost/detail/winapi/dll.hpp>
|
||||
#include <boost/winapi/dll.hpp>
|
||||
|
||||
#ifdef BOOST_HAS_PRAGMA_ONCE
|
||||
# pragma once
|
||||
@@ -31,7 +29,7 @@ class shared_library_impl {
|
||||
BOOST_MOVABLE_BUT_NOT_COPYABLE(shared_library_impl)
|
||||
|
||||
public:
|
||||
typedef boost::detail::winapi::HMODULE_ native_handle_t;
|
||||
typedef boost::winapi::HMODULE_ native_handle_t;
|
||||
|
||||
shared_library_impl() BOOST_NOEXCEPT
|
||||
: handle_(NULL)
|
||||
@@ -40,7 +38,7 @@ public:
|
||||
~shared_library_impl() BOOST_NOEXCEPT {
|
||||
unload();
|
||||
}
|
||||
|
||||
|
||||
shared_library_impl(BOOST_RV_REF(shared_library_impl) sl) BOOST_NOEXCEPT
|
||||
: handle_(sl.handle_)
|
||||
{
|
||||
@@ -52,14 +50,20 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
void load(boost::filesystem::path sl, load_mode::type mode, boost::system::error_code &ec) {
|
||||
typedef boost::detail::winapi::DWORD_ native_mode_t;
|
||||
static boost::dll::fs::path decorate(const boost::dll::fs::path& sl) {
|
||||
boost::dll::fs::path actual_path = sl;
|
||||
actual_path += suffix();
|
||||
return actual_path;
|
||||
}
|
||||
|
||||
void load(boost::dll::fs::path sl, load_mode::type mode, boost::dll::fs::error_code &ec) {
|
||||
typedef boost::winapi::DWORD_ native_mode_t;
|
||||
unload();
|
||||
|
||||
if (!sl.is_absolute() && !(mode & load_mode::search_system_folders)) {
|
||||
boost::dll::fs::error_code current_path_ec;
|
||||
boost::dll::fs::path prog_loc = boost::dll::fs::current_path(current_path_ec);
|
||||
|
||||
boost::system::error_code current_path_ec;
|
||||
boost::filesystem::path prog_loc = boost::filesystem::current_path(current_path_ec);
|
||||
if (!current_path_ec) {
|
||||
prog_loc /= sl;
|
||||
sl.swap(prog_loc);
|
||||
@@ -71,18 +75,17 @@ public:
|
||||
if (!!(mode & load_mode::append_decorations)) {
|
||||
mode &= ~load_mode::append_decorations;
|
||||
|
||||
handle_ = boost::detail::winapi::LoadLibraryExW((sl.native() + L".dll").c_str(), 0, static_cast<native_mode_t>(mode));
|
||||
if (!handle_) {
|
||||
// MinGW loves 'lib' prefix and puts it even on Windows platform
|
||||
const boost::filesystem::path load_path = (sl.has_parent_path() ? sl.parent_path() / L"lib" : L"lib").native() + sl.filename().native() + L".dll";
|
||||
handle_ = boost::detail::winapi::LoadLibraryExW(
|
||||
load_path.c_str(),
|
||||
0,
|
||||
static_cast<native_mode_t>(mode)
|
||||
);
|
||||
if (load_impl(decorate(sl), static_cast<native_mode_t>(mode), ec)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (handle_) {
|
||||
// MinGW loves 'lib' prefix and puts it even on Windows platform.
|
||||
const boost::dll::fs::path mingw_load_path = (
|
||||
sl.has_parent_path()
|
||||
? sl.parent_path() / L"lib"
|
||||
: L"lib"
|
||||
).native() + sl.filename().native() + suffix().native();
|
||||
if (load_impl(mingw_load_path, static_cast<native_mode_t>(mode), ec)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -95,14 +98,13 @@ public:
|
||||
// we have some path. So we do not check for path, only for extension. We can not be sure that
|
||||
// such behavior remain across all platforms, so we add L"." by hand.
|
||||
if (sl.has_extension()) {
|
||||
handle_ = boost::detail::winapi::LoadLibraryExW(sl.c_str(), 0, static_cast<native_mode_t>(mode));
|
||||
handle_ = boost::winapi::LoadLibraryExW(sl.c_str(), 0, static_cast<native_mode_t>(mode));
|
||||
} else {
|
||||
handle_ = boost::detail::winapi::LoadLibraryExW((sl.native() + L".").c_str(), 0, static_cast<native_mode_t>(mode));
|
||||
handle_ = boost::winapi::LoadLibraryExW((sl.native() + L".").c_str(), 0, static_cast<native_mode_t>(mode));
|
||||
}
|
||||
|
||||
// LoadLibraryExW method is capable of self loading from program_location() path. No special actions
|
||||
// must be taken to allow self loading.
|
||||
|
||||
if (!handle_) {
|
||||
ec = boost::dll::detail::last_error_code();
|
||||
}
|
||||
@@ -114,7 +116,7 @@ public:
|
||||
|
||||
void unload() BOOST_NOEXCEPT {
|
||||
if (handle_) {
|
||||
boost::detail::winapi::FreeLibrary(handle_);
|
||||
boost::winapi::FreeLibrary(handle_);
|
||||
handle_ = 0;
|
||||
}
|
||||
}
|
||||
@@ -123,22 +125,21 @@ public:
|
||||
boost::swap(handle_, rhs.handle_);
|
||||
}
|
||||
|
||||
boost::filesystem::path full_module_path(boost::system::error_code &ec) const {
|
||||
boost::dll::fs::path full_module_path(boost::dll::fs::error_code &ec) const {
|
||||
return boost::dll::detail::path_from_handle(handle_, ec);
|
||||
}
|
||||
|
||||
static boost::filesystem::path suffix() {
|
||||
static boost::dll::fs::path suffix() {
|
||||
return L".dll";
|
||||
}
|
||||
|
||||
void* symbol_addr(const char* sb, boost::system::error_code &ec) const BOOST_NOEXCEPT {
|
||||
void* symbol_addr(const char* sb, boost::dll::fs::error_code &ec) const BOOST_NOEXCEPT {
|
||||
if (is_resource()) {
|
||||
// `GetProcAddress` could not be called for libraries loaded with
|
||||
// `LOAD_LIBRARY_AS_DATAFILE`, `LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE`
|
||||
// or `LOAD_LIBRARY_AS_IMAGE_RESOURCE`.
|
||||
ec = boost::system::error_code(
|
||||
boost::system::errc::operation_not_supported,
|
||||
boost::system::generic_category()
|
||||
ec = boost::dll::fs::make_error_code(
|
||||
boost::dll::fs::errc::operation_not_supported
|
||||
);
|
||||
|
||||
return NULL;
|
||||
@@ -148,7 +149,7 @@ public:
|
||||
// there is no version for UNICODE on desktop/server Windows, because
|
||||
// names of functions are stored in narrow characters.
|
||||
void* const symbol = boost::dll::detail::aggressive_ptr_cast<void*>(
|
||||
boost::detail::winapi::get_proc_address(handle_, sb)
|
||||
boost::winapi::get_proc_address(handle_, sb)
|
||||
);
|
||||
if (symbol == NULL) {
|
||||
ec = boost::dll::detail::last_error_code();
|
||||
@@ -162,9 +163,26 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
// Returns true if this load attempt should be the last one.
|
||||
bool load_impl(const boost::dll::fs::path &load_path, boost::winapi::DWORD_ mode, boost::dll::fs::error_code &ec) {
|
||||
handle_ = boost::winapi::LoadLibraryExW(load_path.c_str(), 0, mode);
|
||||
if (handle_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
ec = boost::dll::detail::last_error_code();
|
||||
if (boost::dll::fs::exists(load_path)) {
|
||||
// decorated path exists : current error is not a bad file descriptor
|
||||
return true;
|
||||
}
|
||||
|
||||
ec.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool is_resource() const BOOST_NOEXCEPT {
|
||||
return false; /*!!(
|
||||
reinterpret_cast<boost::detail::winapi::ULONG_PTR_>(handle_) & static_cast<boost::detail::winapi::ULONG_PTR_>(3)
|
||||
reinterpret_cast<boost::winapi::ULONG_PTR_>(handle_) & static_cast<boost::winapi::ULONG_PTR_>(3)
|
||||
);*/
|
||||
}
|
||||
|
||||
@@ -174,4 +192,3 @@ private:
|
||||
}}} // boost::dll::detail
|
||||
|
||||
#endif // BOOST_DLL_SHARED_LIBRARY_IMPL_HPP
|
||||
|
||||
|
||||
Reference in New Issue
Block a user