From 52e4837f3ca4cbf558c562863a7b66f6b9b67314 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Sun, 15 Dec 2024 18:13:51 +0300 Subject: [PATCH] Drop dependency on Boost.Move --- build.jam | 1 - .../dll/detail/posix/shared_library_impl.hpp | 22 ++++----- .../detail/windows/shared_library_impl.hpp | 23 ++++----- include/boost/dll/import.hpp | 21 ++++----- include/boost/dll/import_mangled.hpp | 19 ++++---- include/boost/dll/shared_library.hpp | 47 ++++++++----------- include/boost/dll/smart_library.hpp | 8 ++-- 7 files changed, 61 insertions(+), 80 deletions(-) diff --git a/build.jam b/build.jam index 6c49a765..91c4eeb3 100644 --- a/build.jam +++ b/build.jam @@ -11,7 +11,6 @@ constant boost_dependencies : /boost/core//boost_core /boost/filesystem//boost_filesystem /boost/function//boost_function - /boost/move//boost_move /boost/predef//boost_predef /boost/smart_ptr//boost_smart_ptr /boost/spirit//boost_spirit diff --git a/include/boost/dll/detail/posix/shared_library_impl.hpp b/include/boost/dll/detail/posix/shared_library_impl.hpp index c8858f37..5dd204cb 100644 --- a/include/boost/dll/detail/posix/shared_library_impl.hpp +++ b/include/boost/dll/detail/posix/shared_library_impl.hpp @@ -13,7 +13,6 @@ #include #include -#include #include #include @@ -33,27 +32,24 @@ namespace boost { namespace dll { namespace detail { class shared_library_impl { - - BOOST_MOVABLE_BUT_NOT_COPYABLE(shared_library_impl) - public: typedef void* native_handle_t; - shared_library_impl() BOOST_NOEXCEPT + shared_library_impl() noexcept : handle_(NULL) {} - ~shared_library_impl() BOOST_NOEXCEPT { + ~shared_library_impl() noexcept { unload(); } - shared_library_impl(BOOST_RV_REF(shared_library_impl) sl) BOOST_NOEXCEPT + shared_library_impl(shared_library_impl&& sl) noexcept : handle_(sl.handle_) { sl.handle_ = NULL; } - shared_library_impl & operator=(BOOST_RV_REF(shared_library_impl) sl) BOOST_NOEXCEPT { + shared_library_impl & operator=(shared_library_impl&& sl) noexcept { swap(sl); return *this; } @@ -163,11 +159,11 @@ class shared_library_impl { } } - bool is_loaded() const BOOST_NOEXCEPT { + bool is_loaded() const noexcept { return (handle_ != 0); } - void unload() BOOST_NOEXCEPT { + void unload() noexcept { if (!is_loaded()) { return; } @@ -176,7 +172,7 @@ class shared_library_impl { handle_ = 0; } - void swap(shared_library_impl& rhs) BOOST_NOEXCEPT { + void swap(shared_library_impl& rhs) noexcept { boost::core::invoke_swap(handle_, rhs.handle_); } @@ -193,7 +189,7 @@ class shared_library_impl { #endif } - void* symbol_addr(const char* sb, boost::dll::fs::error_code &ec) const BOOST_NOEXCEPT { + void* symbol_addr(const char* sb, boost::dll::fs::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) { @@ -210,7 +206,7 @@ class shared_library_impl { return symbol; } - native_handle_t native() const BOOST_NOEXCEPT { + native_handle_t native() const noexcept { return handle_; } diff --git a/include/boost/dll/detail/windows/shared_library_impl.hpp b/include/boost/dll/detail/windows/shared_library_impl.hpp index 865265dc..4f64b834 100644 --- a/include/boost/dll/detail/windows/shared_library_impl.hpp +++ b/include/boost/dll/detail/windows/shared_library_impl.hpp @@ -14,7 +14,6 @@ #include #include -#include #include #include @@ -26,26 +25,24 @@ namespace boost { namespace dll { namespace detail { class shared_library_impl { - BOOST_MOVABLE_BUT_NOT_COPYABLE(shared_library_impl) - public: typedef boost::winapi::HMODULE_ native_handle_t; - shared_library_impl() BOOST_NOEXCEPT + shared_library_impl() noexcept : handle_(NULL) {} - ~shared_library_impl() BOOST_NOEXCEPT { + ~shared_library_impl() noexcept { unload(); } - shared_library_impl(BOOST_RV_REF(shared_library_impl) sl) BOOST_NOEXCEPT + shared_library_impl(shared_library_impl&& sl) noexcept : handle_(sl.handle_) { sl.handle_ = NULL; } - shared_library_impl & operator=(BOOST_RV_REF(shared_library_impl) sl) BOOST_NOEXCEPT { + shared_library_impl & operator=(shared_library_impl&& sl) noexcept { swap(sl); return *this; } @@ -111,18 +108,18 @@ class shared_library_impl { } } - bool is_loaded() const BOOST_NOEXCEPT { + bool is_loaded() const noexcept { return (handle_ != 0); } - void unload() BOOST_NOEXCEPT { + void unload() noexcept { if (handle_) { boost::winapi::FreeLibrary(handle_); handle_ = 0; } } - void swap(shared_library_impl& rhs) BOOST_NOEXCEPT { + void swap(shared_library_impl& rhs) noexcept { boost::core::invoke_swap(handle_, rhs.handle_); } @@ -134,7 +131,7 @@ class shared_library_impl { return L".dll"; } - void* symbol_addr(const char* sb, boost::dll::fs::error_code &ec) const BOOST_NOEXCEPT { + void* symbol_addr(const char* sb, boost::dll::fs::error_code &ec) const noexcept { if (is_resource()) { // `GetProcAddress` could not be called for libraries loaded with // `LOAD_LIBRARY_AS_DATAFILE`, `LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE` @@ -159,7 +156,7 @@ class shared_library_impl { return symbol; } - native_handle_t native() const BOOST_NOEXCEPT { + native_handle_t native() const noexcept { return handle_; } @@ -181,7 +178,7 @@ class shared_library_impl { return false; } - bool is_resource() const BOOST_NOEXCEPT { + bool is_resource() const noexcept { return false; /*!!( reinterpret_cast(handle_) & static_cast(3) );*/ diff --git a/include/boost/dll/import.hpp b/include/boost/dll/import.hpp index 6a8fce85..7b10307f 100644 --- a/include/boost/dll/import.hpp +++ b/include/boost/dll/import.hpp @@ -14,7 +14,6 @@ #include #include #include -#include #if defined(BOOST_NO_CXX11_TRAILING_RESULT_TYPES) || defined(BOOST_NO_CXX11_DECLTYPE) || defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) # include @@ -40,12 +39,12 @@ namespace detail { boost::shared_ptr f_; public: - inline library_function(const boost::shared_ptr& lib, T* func_ptr) BOOST_NOEXCEPT + inline library_function(const boost::shared_ptr& lib, T* func_ptr) noexcept : f_(lib, func_ptr) {} #if defined(BOOST_NO_CXX11_TRAILING_RESULT_TYPES) || defined(BOOST_NO_CXX11_DECLTYPE) || defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) - operator T*() const BOOST_NOEXCEPT { + operator T*() const noexcept { return f_.get(); } #else @@ -163,19 +162,19 @@ BOOST_DLL_IMPORT_RESULT_TYPE import_symbol(const shared_library& lib, const std: //! \overload boost::dll::import_symbol(const boost::dll::fs::path& lib, const char* name, load_mode::type mode) template -BOOST_DLL_IMPORT_RESULT_TYPE import_symbol(BOOST_RV_REF(shared_library) lib, const char* name) { +BOOST_DLL_IMPORT_RESULT_TYPE import_symbol(shared_library&& lib, const char* name) { typedef typename boost::dll::detail::import_type::base_type type; boost::shared_ptr p = boost::make_shared( - boost::move(lib) + std::move(lib) ); return type(p, boost::addressof(p->get(name))); } //! \overload boost::dll::import_symbol(const boost::dll::fs::path& lib, const char* name, load_mode::type mode) template -BOOST_DLL_IMPORT_RESULT_TYPE import_symbol(BOOST_RV_REF(shared_library) lib, const std::string& name) { - return dll::import_symbol(boost::move(lib), name.c_str()); +BOOST_DLL_IMPORT_RESULT_TYPE import_symbol(shared_library&& lib, const std::string& name) { + return dll::import_symbol(std::move(lib), name.c_str()); } @@ -253,19 +252,19 @@ BOOST_DLL_IMPORT_RESULT_TYPE import_alias(const shared_library& lib, const std:: //! \overload boost::dll::import_alias(const boost::dll::fs::path& lib, const char* name, load_mode::type mode) template -BOOST_DLL_IMPORT_RESULT_TYPE import_alias(BOOST_RV_REF(shared_library) lib, const char* name) { +BOOST_DLL_IMPORT_RESULT_TYPE import_alias(shared_library&& lib, const char* name) { typedef typename boost::dll::detail::import_type::base_type type; boost::shared_ptr p = boost::make_shared( - boost::move(lib) + std::move(lib) ); return type(p, p->get(name)); } //! \overload boost::dll::import_alias(const boost::dll::fs::path& lib, const char* name, load_mode::type mode) template -BOOST_DLL_IMPORT_RESULT_TYPE import_alias(BOOST_RV_REF(shared_library) lib, const std::string& name) { - return dll::import_alias(boost::move(lib), name.c_str()); +BOOST_DLL_IMPORT_RESULT_TYPE import_alias(shared_library&& lib, const std::string& name) { + return dll::import_alias(std::move(lib), name.c_str()); } #undef BOOST_DLL_IMPORT_RESULT_TYPE diff --git a/include/boost/dll/import_mangled.hpp b/include/boost/dll/import_mangled.hpp index 6dc8d3c0..a2aa7b22 100644 --- a/include/boost/dll/import_mangled.hpp +++ b/include/boost/dll/import_mangled.hpp @@ -19,7 +19,6 @@ #endif #include -#include #include #include #include @@ -43,7 +42,7 @@ class mangled_library_function { boost::shared_ptr lib_; function_tuple f_; public: - constexpr mangled_library_function(const boost::shared_ptr& lib, Ts*... func_ptr) BOOST_NOEXCEPT + constexpr mangled_library_function(const boost::shared_ptr& lib, Ts*... func_ptr) noexcept : lib_(lib) , f_(func_ptr...) {} @@ -77,7 +76,7 @@ class mangled_library_mem_fn> { call_tuple_t f_; public: - constexpr mangled_library_mem_fn(const boost::shared_ptr& lib, typename Ts::mem_fn... func_ptr) BOOST_NOEXCEPT + constexpr mangled_library_mem_fn(const boost::shared_ptr& lib, typename Ts::mem_fn... func_ptr) noexcept : lib_(lib) , f_(func_ptr...) {} @@ -264,7 +263,7 @@ BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(const smart_library& lib, co //! \overload boost::dll::import(const boost::dll::fs::path& lib, const char* name, load_mode::type mode) template -BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(BOOST_RV_REF(smart_library) lib, const char* name) { +BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(smart_library&& lib, const char* name) { typedef typename boost::dll::experimental::detail::mangled_import_type> type; return type::make(lib, name); @@ -272,8 +271,8 @@ BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(BOOST_RV_REF(smart_library) //! \overload boost::dll::import(const boost::dll::fs::path& lib, const char* name, load_mode::type mode) template -BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(BOOST_RV_REF(smart_library) lib, const std::string& name) { - return import_mangled(boost::move(lib), name.c_str()); +BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(smart_library&& lib, const std::string& name) { + return import_mangled(std::move(lib), name.c_str()); } //! \overload boost::dll::import(const boost::dll::fs::path& lib, const char* name, load_mode::type mode) @@ -293,18 +292,18 @@ BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(const shared_library& lib, c //! \overload boost::dll::import(const boost::dll::fs::path& lib, const char* name, load_mode::type mode) template -BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(BOOST_RV_REF(shared_library) lib, const char* name) { +BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(shared_library&& lib, const char* name) { typedef typename boost::dll::experimental::detail::mangled_import_type> type; - boost::dll::experimental::smart_library p(boost::move(lib)); + boost::dll::experimental::smart_library p(std::move(lib)); return type::make(p, name); } //! \overload boost::dll::import(const boost::dll::fs::path& lib, const char* name, load_mode::type mode) template -BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(BOOST_RV_REF(shared_library) lib, const std::string& name) { - return import_mangled(boost::move(lib), name.c_str()); +BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(shared_library&& lib, const std::string& name) { + return import_mangled(std::move(lib), name.c_str()); } #undef BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE diff --git a/include/boost/dll/shared_library.hpp b/include/boost/dll/shared_library.hpp index dd76b019..b1ccfa41 100644 --- a/include/boost/dll/shared_library.hpp +++ b/include/boost/dll/shared_library.hpp @@ -50,7 +50,6 @@ class shared_library /// @endcond { typedef boost::dll::detail::shared_library_impl base_t; - BOOST_COPYABLE_AND_MOVABLE(shared_library) public: #ifdef BOOST_DLL_DOXYGEN @@ -65,7 +64,7 @@ class shared_library * \post this->is_loaded() returns false. * \throw Nothing. */ - shared_library() BOOST_NOEXCEPT {} + shared_library() noexcept = default; /*! * Copy constructor that increments the reference count of an underlying shared library. @@ -103,8 +102,8 @@ class shared_library * \post lib.is_loaded() returns false, this->is_loaded() return true. * \throw Nothing. */ - shared_library(BOOST_RV_REF(shared_library) lib) BOOST_NOEXCEPT - : base_t(boost::move(static_cast(lib))) + shared_library(shared_library&& lib) noexcept + : base_t(std::move(lib)) {} /*! @@ -144,7 +143,7 @@ class shared_library * \post lib == *this * \throw \forcedlinkfs{system_error}, std::bad_alloc in case of insufficient memory. */ - shared_library& operator=(BOOST_COPY_ASSIGN_REF(shared_library) lib) { + shared_library& operator=(const shared_library& lib) { boost::dll::fs::error_code ec; assign(lib, ec); if (ec) { @@ -161,7 +160,7 @@ class shared_library * \post lib.is_loaded() returns false. * \throw Nothing. */ - shared_library& operator=(BOOST_RV_REF(shared_library) lib) BOOST_NOEXCEPT { + shared_library& operator=(shared_library&& lib) noexcept { if (lib.native() != native()) { swap(lib); } @@ -176,7 +175,7 @@ class shared_library * * \throw Nothing. */ - ~shared_library() BOOST_NOEXCEPT {} + ~shared_library() = default; /*! * Makes *this share the same shared object as lib. If *this is loaded, then unloads it. @@ -282,7 +281,7 @@ class shared_library * \post this->is_loaded() returns false. * \throw Nothing. */ - void unload() BOOST_NOEXCEPT { + void unload() noexcept { base_t::unload(); } @@ -292,27 +291,19 @@ class shared_library * \return true if a library has been loaded. * \throw Nothing. */ - bool is_loaded() const BOOST_NOEXCEPT { + bool is_loaded() const noexcept { return base_t::is_loaded(); } - /*! - * Check if an library is not loaded. - * - * \return true if a library has not been loaded. - * \throw Nothing. - */ - bool operator!() const BOOST_NOEXCEPT { - return !is_loaded(); - } - /*! * Check if an library is loaded. * * \return true if a library has been loaded. * \throw Nothing. */ - BOOST_EXPLICIT_OPERATOR_BOOL() + explicit operator bool() const noexcept { + return is_loaded(); + } /*! * Search for a given symbol on loaded library. Works for all symbols, including alias names. @@ -321,13 +312,13 @@ class shared_library * \return `true` if the loaded library contains a symbol with a given name. * \throw Nothing. */ - bool has(const char* symbol_name) const BOOST_NOEXCEPT { + bool has(const char* symbol_name) const noexcept { boost::dll::fs::error_code ec; return is_loaded() && !!base_t::symbol_addr(symbol_name, ec) && !ec; } //! \overload bool has(const char* symbol_name) const - bool has(const std::string& symbol_name) const BOOST_NOEXCEPT { + bool has(const std::string& symbol_name) const noexcept { return has(symbol_name.c_str()); } @@ -433,7 +424,7 @@ class shared_library * * \return Platform-specific handle. */ - native_handle_t native() const BOOST_NOEXCEPT { + native_handle_t native() const noexcept { return base_t::native(); } @@ -537,7 +528,7 @@ class shared_library * \param rhs Library to swap with. * \throw Nothing. */ - void swap(shared_library& rhs) BOOST_NOEXCEPT { + void swap(shared_library& rhs) noexcept { base_t::swap(rhs); } }; @@ -545,22 +536,22 @@ class shared_library /// Very fast equality check that compares the actual DLL/DSO objects. Throws nothing. -inline bool operator==(const shared_library& lhs, const shared_library& rhs) BOOST_NOEXCEPT { +inline bool operator==(const shared_library& lhs, const shared_library& rhs) noexcept { return lhs.native() == rhs.native(); } /// Very fast inequality check that compares the actual DLL/DSO objects. Throws nothing. -inline bool operator!=(const shared_library& lhs, const shared_library& rhs) BOOST_NOEXCEPT { +inline bool operator!=(const shared_library& lhs, const shared_library& rhs) noexcept { return lhs.native() != rhs.native(); } /// Compare the actual DLL/DSO objects without any guarantee to be stable between runs. Throws nothing. -inline bool operator<(const shared_library& lhs, const shared_library& rhs) BOOST_NOEXCEPT { +inline bool operator<(const shared_library& lhs, const shared_library& rhs) noexcept { return lhs.native() < rhs.native(); } /// Swaps two shared libraries. Does not invalidate symbols and functions loaded from libraries. Throws nothing. -inline void swap(shared_library& lhs, shared_library& rhs) BOOST_NOEXCEPT { +inline void swap(shared_library& lhs, shared_library& rhs) noexcept { lhs.swap(rhs); } diff --git a/include/boost/dll/smart_library.hpp b/include/boost/dll/smart_library.hpp index 1f02843e..6a8366fa 100644 --- a/include/boost/dll/smart_library.hpp +++ b/include/boost/dll/smart_library.hpp @@ -127,8 +127,8 @@ class smart_library { * * \throw Nothing. */ - smart_library(BOOST_RV_REF(smart_library) lib) BOOST_NOEXCEPT - : _lib(boost::move(lib._lib)), _storage(boost::move(lib._storage)) + smart_library(smart_library&& lib) BOOST_NOEXCEPT + : _lib(std::move(lib._lib)), _storage(std::move(lib._storage)) {} /*! @@ -150,8 +150,8 @@ class smart_library { * * \throw Nothing. */ - explicit smart_library(BOOST_RV_REF(shared_library) lib) BOOST_NOEXCEPT - : _lib(boost::move(static_cast(lib))) + explicit smart_library(shared_library&& lib) BOOST_NOEXCEPT + : _lib(std::move(lib)) { _storage.load(lib.location()); }