diff --git a/CMakeLists.txt b/CMakeLists.txt index 25d59ff..42542d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,15 +18,11 @@ target_link_libraries(boost_dll Boost::config Boost::core Boost::filesystem - Boost::function - Boost::move Boost::predef Boost::smart_ptr - Boost::spirit Boost::system Boost::throw_exception Boost::type_index - Boost::type_traits Boost::winapi ) diff --git a/build.jam b/build.jam index 6c49a76..f5d93e2 100644 --- a/build.jam +++ b/build.jam @@ -10,15 +10,11 @@ constant boost_dependencies : /boost/config//boost_config /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 /boost/system//boost_system /boost/throw_exception//boost_throw_exception /boost/type_index//boost_type_index - /boost/type_traits//boost_type_traits /boost/winapi//boost_winapi ; project /boost/dll diff --git a/doc/Jamfile.v2 b/doc/Jamfile.v2 index 013e6cd..4f0c5d3 100644 --- a/doc/Jamfile.v2 +++ b/doc/Jamfile.v2 @@ -35,15 +35,8 @@ local doxygen_params = \"forcedlinkfs{1}=\\xmlonlyboost::dll::fs::\\1\\endxmlonly\" \\ \"forcedmacrolink{1}=\\xmlonly\\1\\endxmlonly\" " "PREDEFINED= \\ - \"BOOST_RV_REF(T)=T&&\" \\ - \"BOOST_RV_REF(shared_library)=shared_library&&\" \\ - \"BOOST_COPY_ASSIGN_REF(shared_library)=const shared_library&\" \\ - \"BOOST_MOVABLE_BUT_NOT_COPYABLE(shared_library)= \\ - shared_library(const shared_library&) = delete; \\ - shared_library& operator=(const shared_library&) = delete; \" \\ \"BOOST_DLL_IMPORT_RESULT_TYPE=result_type\" \\ \"BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE=result_type\" \\ - \"BOOST_EXPLICIT_OPERATOR_BOOL()=explicit operator bool() const noexcept;\" \\ \"BOOST_DLL_DOXYGEN\" " ; diff --git a/doc/dependencies.qbk b/doc/dependencies.qbk index c82db9f..3c8416d 100644 --- a/doc/dependencies.qbk +++ b/doc/dependencies.qbk @@ -10,12 +10,11 @@ The Boost.DLL is a header only library, but it depends on the following libraries and they must be available in order to compile programs that use Boost.DLL: -* Boost.System for the boost::system::error_code and boost::system::system_error classes. +* Boost.System for the boost::system::system_error class. * Boost.Filesystem for directory manipulation. Refcountable part of Boost.DLL also depends on: -* Boost.Function for creation of a callback system. * Boost.SharedPtr for reference counting. [endsect] diff --git a/doc/getting_started.qbk b/doc/getting_started.qbk index 4f900fc..27a78fc 100644 --- a/doc/getting_started.qbk +++ b/doc/getting_started.qbk @@ -17,7 +17,7 @@ boost::dll::shared_library lib("/test/boost/application/libtest_library.so"); Now you can easily import symbols from that library using the `get` and `get_alias` member functions: ``` int plugin_constant = lib.get("integer_variable"); -boost::function f = lib.get("function_returning_int"); +auto function_ptr = lib.get("function_returning_int"); int& i = lib.get_alias("alias_to_int_variable"); ``` In case of `boost::dll::shared_library` it is safe to use imported symbols only until `boost::dll::shared_library` diff --git a/example/tutorial2/tutorial2.cpp b/example/tutorial2/tutorial2.cpp index ca49b49..29e6d25 100644 --- a/example/tutorial2/tutorial2.cpp +++ b/example/tutorial2/tutorial2.cpp @@ -19,10 +19,9 @@ int main(int argc, char* argv[]) { /*<-*/ b2_workarounds::argv_to_path_guard guard(argc, argv); /*->*/ boost::dll::fs::path shared_library_path(argv[1]); // argv[1] contains path to directory with our plugin library shared_library_path /= "my_plugin_aggregator"; - typedef boost::shared_ptr (pluginapi_create_t)(); - boost::function creator; - creator = boost::dll::import_alias( // type of imported symbol must be explicitly specified + using pluginapi_create_t = boost::shared_ptr(); + auto creator = boost::dll::import_alias( // type of imported symbol must be explicitly specified shared_library_path, // path to library "create_plugin", // symbol to import dll::load_mode::append_decorations // do append extensions and prefixes diff --git a/example/tutorial3/tutorial3.cpp b/example/tutorial3/tutorial3.cpp index 7ebc682..165956f 100644 --- a/example/tutorial3/tutorial3.cpp +++ b/example/tutorial3/tutorial3.cpp @@ -27,9 +27,10 @@ std::size_t search_for_symbols(const std::vector& plugins) } // library has symbol, importing... - typedef boost::shared_ptr (pluginapi_create_t)(); - boost::function creator - = dll::import_alias(boost::move(lib), "create_plugin"); + using pluginapi_create_t = boost::shared_ptr(); + auto creator = dll::import_alias( + std::move(lib), "create_plugin" + ); std::cout << "Matching plugin name: " << creator()->name() << std::endl; ++ plugins_found; diff --git a/example/tutorial4/load_self.cpp b/example/tutorial4/load_self.cpp index 80528e1..7b8e83a 100644 --- a/example/tutorial4/load_self.cpp +++ b/example/tutorial4/load_self.cpp @@ -21,8 +21,7 @@ int main() { dll::shared_library self(dll::program_location()); std::cout << "Call function" << std::endl; - boost::function()> creator - = self.get_alias()>("create_plugin"); + auto creator = self.get_alias()>("create_plugin"); std::cout << "Computed Value: " << creator()->calculate(2, 2) << std::endl; //<- diff --git a/example/tutorial5/load_all.cpp b/example/tutorial5/load_all.cpp index de0a339..4a1464c 100644 --- a/example/tutorial5/load_all.cpp +++ b/example/tutorial5/load_all.cpp @@ -22,7 +22,7 @@ namespace dll = boost::dll; class plugins_collector { // Name => plugin - typedef boost::container::map plugins_t; + using plugins_t = boost::container::map; boost::dll::fs::path plugins_directory_; plugins_t plugins_; @@ -32,7 +32,7 @@ class plugins_collector { // Gets `my_plugin_api` instance using "create_plugin" or "plugin" imports, // stores plugin with its name in the `plugins_` map. - void insert_plugin(BOOST_RV_REF(dll::shared_library) lib); + void insert_plugin(dll::shared_library&& lib); public: plugins_collector(const boost::dll::fs::path& plugins_directory) @@ -52,8 +52,7 @@ public: //[plugcpp_plugins_collector_load_all void plugins_collector::load_all() { namespace fs = ::boost::dll::fs; - typedef fs::path::string_type string_type; - const string_type extension = dll::shared_library::suffix().native(); + const auto extension = dll::shared_library::suffix().native(); // Searching a folder for files with '.so' or '.dll' extension fs::recursive_directory_iterator endit; @@ -67,7 +66,7 @@ void plugins_collector::load_all() { } /*->*/ // We found a file. Trying to load it - boost::dll::fs::error_code error; + std::error_code error; dll::shared_library plugin(it->path(), error); if (error) { continue; @@ -75,17 +74,17 @@ void plugins_collector::load_all() { std::cout << "Loaded (" << plugin.native() << "):" << it->path() << '\n'; // Gets plugin using "create_plugin" or "plugin" function - insert_plugin(boost::move(plugin)); + insert_plugin(std::move(plugin)); } dll::shared_library plugin(dll::program_location()); std::cout << "Loaded self\n"; - insert_plugin(boost::move(plugin)); + insert_plugin(std::move(plugin)); } //] //[plugcpp_plugins_collector_insert_plugin -void plugins_collector::insert_plugin(BOOST_RV_REF(dll::shared_library) lib) { +void plugins_collector::insert_plugin(dll::shared_library&& lib) { std::string plugin_name; if (lib.has("create_plugin")) { plugin_name = lib.get_alias()>("create_plugin")()->name(); @@ -96,7 +95,7 @@ void plugins_collector::insert_plugin(BOOST_RV_REF(dll::shared_library) lib) { } if (plugins_.find(plugin_name) == plugins_.cend()) { - plugins_[plugin_name] = boost::move(lib); + plugins_[plugin_name] = std::move(lib); } } //] diff --git a/example/tutorial6/on_unload_lib.cpp b/example/tutorial6/on_unload_lib.cpp index 0b97226..bc4cbe9 100644 --- a/example/tutorial6/on_unload_lib.cpp +++ b/example/tutorial6/on_unload_lib.cpp @@ -10,14 +10,14 @@ //[plugcpp_on_unload #include // for BOOST_DLL_ALIAS -#include +#include #include namespace my_namespace { struct on_unload { - typedef boost::function callback_t; - typedef on_unload this_type; + using callback_t = std::function ; + using this_type = on_unload; ~on_unload() { for (std::size_t i = 0; i < callbacks_.size(); ++i) { diff --git a/example/tutorial6/tutorial6.cpp b/example/tutorial6/tutorial6.cpp index 11117e2..27169c4 100644 --- a/example/tutorial6/tutorial6.cpp +++ b/example/tutorial6/tutorial6.cpp @@ -9,10 +9,10 @@ //[callplugcpp_tutorial6 #include -#include +#include #include -typedef boost::function callback_t; +using callback_t = std::function ; void print_unloaded() { std::cout << "unloaded" << std::endl; @@ -23,16 +23,15 @@ int main(int argc, char* argv[]) { boost::dll::fs::path shared_library_path = /*<-*/ b2_workarounds::first_lib_from_argv(argc, argv); /*->*/ //=argv[1]; // loading library and getting a function from it - boost::function on_unload - = boost::dll::import_alias( - shared_library_path, "on_unload" - ); + std::function on_unload = boost::dll::import_alias( + shared_library_path, "on_unload" + ); on_unload(&print_unloaded); // adding a callback std::cout << "Before library unload." << std::endl; // Releasing last reference to the library, so that it gets unloaded - on_unload.clear(); + on_unload = {}; std::cout << "After library unload." << std::endl; } //] diff --git a/example/tutorial8/refcounting_api.hpp b/example/tutorial8/refcounting_api.hpp index e9e415d..b06d06e 100644 --- a/example/tutorial8/refcounting_api.hpp +++ b/example/tutorial8/refcounting_api.hpp @@ -54,8 +54,8 @@ inline boost::shared_ptr bind(my_refcounting_api* plugin) { inline boost::shared_ptr get_plugin( boost::dll::fs::path path, const char* func_name) { - typedef my_refcounting_api*(func_t)(); - boost::function creator = boost::dll::import_alias( + using func_t = my_refcounting_api*(); + auto creator = boost::dll::import_alias( path, func_name, boost::dll::load_mode::append_decorations // will be ignored for executable diff --git a/example/tutorial9/tutorial9.cpp b/example/tutorial9/tutorial9.cpp index 745c171..4412cb6 100644 --- a/example/tutorial9/tutorial9.cpp +++ b/example/tutorial9/tutorial9.cpp @@ -10,7 +10,7 @@ //[callplugcpp_tutorial9 #include // for dll::import #include // for dll::shared_library -#include +#include #include #include @@ -29,15 +29,14 @@ int main() { ); std::cout << "0.0 GetStdHandle() returned " << get_std_handle(STD_OUTPUT_HANDLE) << std::endl; - // You may put the `get_std_handle` into boost::function<>. But boost::function can not compile with + // You may put the `get_std_handle` into std::function<>. But std::function may not compile with // Signature template parameter that contains calling conventions, so you'll have to remove the calling convention. - boost::function get_std_handle2 = get_std_handle; + std::function get_std_handle2 = get_std_handle; std::cout << "0.1 GetStdHandle() returned " << get_std_handle2(STD_OUTPUT_HANDLE) << std::endl; /*<-*/ #endif /*->*/ - // OPTION #1, does not require C++11. But without C++11 dll::import<> can not handle calling conventions, - // so you'll need to hand write the import. + // OPTION #1, hand write the import. dll::shared_library lib("Kernel32.dll", dll::load_mode::search_system_folders); GetStdHandle_t& func = lib.get("GetStdHandle"); diff --git a/include/boost/dll/alias.hpp b/include/boost/dll/alias.hpp index 0eac7ce..711fbe1 100644 --- a/include/boost/dll/alias.hpp +++ b/include/boost/dll/alias.hpp @@ -44,7 +44,7 @@ namespace boost { namespace dll { #define BOOST_DLL_SELECTANY __declspec(selectany) #define BOOST_DLL_SECTION(SectionName, Permissions) \ - static_assert( \ + static_assert( \ sizeof(#SectionName) < 10, \ "Some platforms require section names to be at most 8 bytes" \ ); \ @@ -83,7 +83,7 @@ namespace boost { namespace dll { * \param Permissions Can be "read" or "write" (without quotes!). */ #define BOOST_DLL_SECTION(SectionName, Permissions) \ - static_assert( \ + static_assert( \ sizeof(#SectionName) < 10, \ "Some platforms require section names to be at most 8 bytes" \ ); \ @@ -92,7 +92,7 @@ namespace boost { namespace dll { #else // #if !BOOST_OS_MACOS && !BOOST_OS_IOS #define BOOST_DLL_SECTION(SectionName, Permissions) \ - static_assert( \ + static_assert( \ sizeof(#SectionName) < 10, \ "Some platforms require section names to be at most 8 bytes" \ ); \ @@ -184,7 +184,7 @@ namespace boost { namespace dll { #else // Note: we can not use `aggressive_ptr_cast` here, because in that case GCC applies // different permissions to the section and it causes Segmentation fault. -// Note: we can not use `boost::addressof()` here, because in that case GCC +// Note: we can not use `std::addressof()` here, because in that case GCC // may optimize away the FunctionOrVar instance and we'll get a pointer to unexisting symbol. /*! * \brief Same as \forcedmacrolink{BOOST_DLL_ALIAS} but puts alias name into the user specified section. diff --git a/include/boost/dll/config.hpp b/include/boost/dll/config.hpp index 65599b8..a2c2248 100644 --- a/include/boost/dll/config.hpp +++ b/include/boost/dll/config.hpp @@ -16,7 +16,7 @@ #endif #ifdef BOOST_DLL_DOXYGEN -/// Define this macro to make Boost.DLL use C++17's std::filesystem::path, std::system_error and std::error_code. +/// Define this macro to make Boost.DLL use C++17's std::filesystem::path and std::system_error. #define BOOST_DLL_USE_STD_FS BOOST_DLL_USE_STD_FS /// This namespace contains aliases to the Boost or C++17 classes. Aliases are configured using BOOST_DLL_USE_STD_FS macro. @@ -38,19 +38,17 @@ using system_error = std::conditional_t + #include namespace boost { namespace dll { namespace fs { using namespace std::filesystem; - using std::error_code; using std::system_error; -using std::make_error_code; -using std::errc; -using std::system_category; }}} @@ -58,18 +56,14 @@ using std::system_category; #include #include -#include #include +#include namespace boost { namespace dll { namespace fs { using namespace boost::filesystem; - using boost::system::error_code; using boost::system::system_error; -using boost::system::errc::make_error_code; -namespace errc = boost::system::errc; -using boost::system::system_category; }}} diff --git a/include/boost/dll/detail/aggressive_ptr_cast.hpp b/include/boost/dll/detail/aggressive_ptr_cast.hpp index b9efc29..5734130 100644 --- a/include/boost/dll/detail/aggressive_ptr_cast.hpp +++ b/include/boost/dll/detail/aggressive_ptr_cast.hpp @@ -13,15 +13,9 @@ # pragma once #endif -#include -#include -#include -#include -#include -#include -#include -#include #include // std::memcpy +#include +#include #if defined(__GNUC__) && defined(__GNUC_MINOR__) && (__GNUC__ * 100 + __GNUC_MINOR__ > 301) # pragma GCC system_header @@ -32,17 +26,17 @@ namespace boost { namespace dll { namespace detail { // GCC warns when reinterpret_cast between function pointer and object pointer occur. // This method suppress the warnings and ensures that such casts are safe. template -BOOST_FORCEINLINE typename boost::disable_if_c::value || boost::is_reference::value || boost::is_member_pointer::value, To>::type - aggressive_ptr_cast(From v) BOOST_NOEXCEPT +BOOST_FORCEINLINE typename std::enable_if::value && !std::is_reference::value && !std::is_member_pointer::value, To>::type + aggressive_ptr_cast(From v) noexcept { static_assert( - boost::is_pointer::value && boost::is_pointer::value, + std::is_pointer::value && std::is_pointer::value, "`agressive_ptr_cast` function must be used only for pointer casting." ); static_assert( - boost::is_void< typename boost::remove_pointer::type >::value - || boost::is_void< typename boost::remove_pointer::type >::value, + std::is_void< typename std::remove_pointer::type >::value + || std::is_void< typename std::remove_pointer::type >::value, "`agressive_ptr_cast` function must be used only for casting to or from void pointers." ); @@ -60,25 +54,25 @@ BOOST_FORCEINLINE typename boost::disable_if_c::val #endif template -BOOST_FORCEINLINE typename boost::disable_if_c::value || boost::is_member_pointer::value, To>::type - aggressive_ptr_cast(From v) BOOST_NOEXCEPT +BOOST_FORCEINLINE typename std::enable_if::value && !std::is_member_pointer::value, To>::type + aggressive_ptr_cast(From v) noexcept { static_assert( - boost::is_pointer::value, + std::is_pointer::value, "`agressive_ptr_cast` function must be used only for pointer casting." ); static_assert( - boost::is_void< typename boost::remove_pointer::type >::value, + std::is_void< typename std::remove_pointer::type >::value, "`agressive_ptr_cast` function must be used only for casting to or from void pointers." ); static_assert( - sizeof(v) == sizeof(typename boost::remove_reference::type*), + sizeof(v) == sizeof(typename std::remove_reference::type*), "Pointer to function and pointer to object differ in size on your platform." ); return static_cast( - **reinterpret_cast::type**>( + **reinterpret_cast::type**>( v ) ); @@ -89,16 +83,16 @@ BOOST_FORCEINLINE typename boost::disable_if_c::value | #endif template -BOOST_FORCEINLINE typename boost::disable_if_c::value || boost::is_member_pointer::value, To>::type - aggressive_ptr_cast(From v) BOOST_NOEXCEPT +BOOST_FORCEINLINE typename std::enable_if::value && !std::is_member_pointer::value, To>::type + aggressive_ptr_cast(From v) noexcept { static_assert( - boost::is_pointer::value, + std::is_pointer::value, "`agressive_ptr_cast` function must be used only for pointer casting." ); static_assert( - boost::is_void< typename boost::remove_pointer::type >::value, + std::is_void< typename std::remove_pointer::type >::value, "`agressive_ptr_cast` function must be used only for casting to or from void pointers." ); @@ -108,16 +102,16 @@ BOOST_FORCEINLINE typename boost::disable_if_c::va } template -BOOST_FORCEINLINE typename boost::disable_if_c::value || !boost::is_member_pointer::value, To>::type - aggressive_ptr_cast(From /* v */) BOOST_NOEXCEPT +BOOST_FORCEINLINE typename std::enable_if::value && std::is_member_pointer::value, To>::type + aggressive_ptr_cast(From /* v */) noexcept { static_assert( - boost::is_pointer::value, + std::is_pointer::value, "`agressive_ptr_cast` function must be used only for pointer casting." ); static_assert( - boost::is_void< typename boost::remove_pointer::type >::value, + std::is_void< typename std::remove_pointer::type >::value, "`agressive_ptr_cast` function must be used only for casting to or from void pointers." ); diff --git a/include/boost/dll/detail/ctor_dtor.hpp b/include/boost/dll/detail/ctor_dtor.hpp index 2722055..8b077af 100644 --- a/include/boost/dll/detail/ctor_dtor.hpp +++ b/include/boost/dll/detail/ctor_dtor.hpp @@ -130,7 +130,7 @@ template destructor load_dtor(Lib & lib, const mangled_storage_impl::dtor_sym & dt) { typedef typename destructor::standard_t standard_t; //@apolukhin That does NOT work this way with MSVC-14 x32 via memcpy. The x64 is different. - //standard_t dtor = &lib.template get< typename boost::remove_pointer::type >(dt); + //standard_t dtor = &lib.template get< typename std::remove_pointer::type >(dt); void * buf = &lib.template get(dt); standard_t dtor; std::memcpy(&dtor, &buf, sizeof(dtor)); @@ -175,11 +175,11 @@ destructor load_dtor(Lib & lib, const mangled_storage_impl::dtor_sym & dt //see here for the abi http://mentorembedded.github.io/cxx-abi/abi.html#mangling-special-ctor-dtor if (!dt.D1.empty()) { - s = &lib.template get< typename boost::remove_pointer::type >(dt.D1); + s = &lib.template get< typename std::remove_pointer::type >(dt.D1); } if (!dt.D0.empty()) { - d = &lib.template get< typename boost::remove_pointer::type >(dt.D0); + d = &lib.template get< typename std::remove_pointer::type >(dt.D0); } return destructor(s,d); diff --git a/include/boost/dll/detail/demangling/itanium.hpp b/include/boost/dll/detail/demangling/itanium.hpp index 236477f..8fe148b 100644 --- a/include/boost/dll/detail/demangling/itanium.hpp +++ b/include/boost/dll/detail/demangling/itanium.hpp @@ -8,19 +8,15 @@ #define BOOST_DLL_DETAIL_DEMANGLING_ITANIUM_HPP_ #include -#include + #include -#include -#include -#include -#include -#include +#include +#include namespace boost { namespace dll { namespace detail { - class mangled_storage_impl : public mangled_storage_base { template @@ -185,22 +181,22 @@ namespace parser } }; - inline std::string const_rule_impl(true_type ) {return " const";} - inline std::string const_rule_impl(false_type) {return "";} + inline std::string const_rule_impl(std::true_type ) {return " const";} + inline std::string const_rule_impl(std::false_type) {return "";} template - std::string const_rule() {using t = is_const::type>; return const_rule_impl(t());} + std::string const_rule() {using t = std::is_const::type>; return const_rule_impl(t());} - inline std::string volatile_rule_impl(true_type ) {return " volatile";} - inline std::string volatile_rule_impl(false_type) {return "";} + inline std::string volatile_rule_impl(std::true_type ) {return " volatile";} + inline std::string volatile_rule_impl(std::false_type) {return "";} template - std::string volatile_rule() {using t = is_volatile::type>; return volatile_rule_impl(t());} + std::string volatile_rule() {using t = std::is_volatile::type>; return volatile_rule_impl(t());} - inline std::string reference_rule_impl(false_type, false_type) {return "";} - inline std::string reference_rule_impl(true_type, false_type) {return "&" ;} - inline std::string reference_rule_impl(false_type, true_type ) {return "&&";} + inline std::string reference_rule_impl(std::false_type, std::false_type) {return "";} + inline std::string reference_rule_impl(std::true_type, std::false_type) {return "&" ;} + inline std::string reference_rule_impl(std::false_type, std::true_type ) {return "&&";} template - std::string reference_rule() {using t_l = is_lvalue_reference; using t_r = is_rvalue_reference; return reference_rule_impl(t_l(), t_r());} + std::string reference_rule() {using t_l = std::is_lvalue_reference; using t_r = std::is_rvalue_reference; return reference_rule_impl(t_l(), t_r());} //it takes a string, because it may be overloaded. template diff --git a/include/boost/dll/detail/demangling/mangled_storage_base.hpp b/include/boost/dll/detail/demangling/mangled_storage_base.hpp index d1241a0..32d0a7c 100644 --- a/include/boost/dll/detail/demangling/mangled_storage_base.hpp +++ b/include/boost/dll/detail/demangling/mangled_storage_base.hpp @@ -10,10 +10,12 @@ #include #include #include +#include + #include #include #include -#include + namespace boost { namespace dll { namespace detail { diff --git a/include/boost/dll/detail/demangling/msvc.hpp b/include/boost/dll/detail/demangling/msvc.hpp index 6f98e78..e5b5aa0 100644 --- a/include/boost/dll/detail/demangling/msvc.hpp +++ b/include/boost/dll/detail/demangling/msvc.hpp @@ -8,16 +8,12 @@ #define BOOST_DLL_DETAIL_DEMANGLING_MSVC_HPP_ #include + +#include + #include #include -#include -#include -#include -#include -#include -#include - -#include +#include namespace boost { namespace dll { namespace detail { @@ -26,11 +22,6 @@ class mangled_storage_impl : public mangled_storage_base template struct dummy {}; - template - std::vector get_func_params(dummy) const - { - return {get_name()...}; - } template std::string get_return_type(dummy) const { @@ -93,134 +84,247 @@ void mangled_storage_impl::trim_typename(std::string & val) } } +namespace parser { -namespace parser -{ - namespace x3 = spirit::x3; - - inline auto ptr_rule_impl(std::integral_constant) - { - return -((-x3::space) >> "__ptr32"); - } - inline auto ptr_rule_impl(std::integral_constant) - { - return -((-x3::space) >> "__ptr64"); + inline bool try_consume_prefix(boost::core::string_view& s, boost::core::string_view prefix) { + const bool result = s.starts_with(prefix); + if (result) { + s.remove_prefix(prefix.size()); + } + return result; } - inline auto ptr_rule() { - return ptr_rule_impl(std::integral_constant()); + inline bool ignore_prefix(boost::core::string_view& s, boost::core::string_view prefix) { + parser::try_consume_prefix(s, prefix); + return true; + } + + inline void consume_ptrs(boost::core::string_view& s) { + do { + while (parser::try_consume_prefix(s, " ")) {} + } while (parser::try_consume_prefix(s, "__ptr32") || parser::try_consume_prefix(s, "__ptr64")); } - auto const visibility = ("public:" | x3::lit("protected:") | "private:"); - auto const virtual_ = x3::space >> "virtual"; - auto const static_ = x3::space >> x3::lit("static") ; - - inline auto const_rule_impl(true_type ) {return x3::space >> "const";}; - inline auto const_rule_impl(false_type) {return x3::eps;}; - template - auto const_rule() {using t = is_const::type>; return const_rule_impl(t());} - - inline auto volatile_rule_impl(true_type ) {return x3::space >> "volatile";}; - inline auto volatile_rule_impl(false_type) {return x3::eps;}; - template - auto volatile_rule() {using t = is_volatile::type>; return volatile_rule_impl(t());} - - - inline auto inv_const_rule_impl(true_type ) {return "const" >> x3::space ;}; - inline auto inv_const_rule_impl(false_type) {return x3::eps;}; - template - auto inv_const_rule() {using t = is_const::type>; return inv_const_rule_impl(t());} - - inline auto inv_volatile_rule_impl(true_type ) {return "volatile" >> x3::space;}; - inline auto inv_volatile_rule_impl(false_type) {return x3::eps;}; - template - auto inv_volatile_rule() {using t = is_volatile::type>; return inv_volatile_rule_impl(t());} - - - inline auto reference_rule_impl(false_type, false_type) {return x3::eps;} - inline auto reference_rule_impl(true_type, false_type) {return x3::space >>"&" ;} - inline auto reference_rule_impl(false_type, true_type ) {return x3::space >>"&&" ;} - - - template - auto reference_rule() {using t_l = is_lvalue_reference; using t_r = is_rvalue_reference; return reference_rule_impl(t_l(), t_r());} - - auto const class_ = ("class" | x3::lit("struct")); - - //it takes a string, because it may be overloaded. - template - auto type_rule(const std::string & type_name) - { - using namespace std; - - return -(class_ >> x3::space)>> x3::string(type_name) >> - const_rule() >> - volatile_rule() >> - reference_rule() >> - ptr_rule(); + inline bool ignore_ptrs(boost::core::string_view& s) { + parser::consume_ptrs(s); + return true; } - template<> - inline auto type_rule(const std::string &) { return x3::string("void"); }; - auto const cdecl_ = "__cdecl" >> x3::space; - auto const stdcall = "__stdcall" >> x3::space; -#if defined(_WIN64)//seems to be necessary by msvc 14-x64 - auto const thiscall = "__cdecl" >> x3::space; -#else - auto const thiscall = "__thiscall" >> x3::space; -#endif + inline bool try_consume_visibility(boost::core::string_view& s) { + return parser::try_consume_prefix(s, "public:") + || parser::try_consume_prefix(s, "protected:") + || parser::try_consume_prefix(s, "private:"); + } + + template + bool try_consume_type(boost::core::string_view& s, const mangled_storage_impl& ms) { + if (std::is_void::value) { + return parser::try_consume_prefix(s, "void"); + } + + parser::ignore_prefix(s, "class "); + parser::ignore_prefix(s, "struct "); + + const auto& mangled_name = ms.get_name(); + if (!parser::try_consume_prefix(s, mangled_name)) { + return false; + } + + if (std::is_const::type>::value) { + if (!parser::try_consume_prefix(s, " const")) { + return false; + } + } + + if (std::is_volatile::type>::value) { + if (!parser::try_consume_prefix(s, " volatile")) { + return false; + } + } + + if (std::is_rvalue_reference::value) { + if (!parser::try_consume_prefix(s, " &&")) { + return false; + } + } + + if (std::is_lvalue_reference::value) { + if (!parser::try_consume_prefix(s, " &")) { + return false; + } + } + + return parser::ignore_ptrs(s); + } + + inline bool try_consume_thiscall(boost::core::string_view& s) { + parser::try_consume_prefix(s, " "); + return parser::try_consume_prefix(s, "__cdecl ") // Win 64bit + || parser::try_consume_prefix(s, "__thiscall "); // Win 32bit + } template - auto arg_list(const mangled_storage_impl & ms, Return (*)(Arg)) - { - using namespace std; - - return type_rule(ms.get_name()); + bool try_consume_arg_list(boost::core::string_view& s, const mangled_storage_impl& ms, Return (*)(Arg)) { + return parser::try_consume_type(s, ms); } template - auto arg_list(const mangled_storage_impl & ms, Return (*)(First, Second, Args...)) - { - + bool try_consume_arg_list(boost::core::string_view& s, const mangled_storage_impl& ms, Return (*)(First, Second, Args...)) { using next_type = Return (*)(Second, Args...); - return type_rule(ms.get_name()) >> x3::char_(',') >> arg_list(ms, next_type()); + return parser::try_consume_type(s, ms) + && parser::try_consume_prefix(s, ",") + && parser::try_consume_arg_list(s, ms, next_type()); } template - auto arg_list(const mangled_storage_impl& /*ms*/, Return (*)()) - { - return x3::string("void"); + bool try_consume_arg_list(boost::core::string_view& s, const mangled_storage_impl& ms, Return (*)()) { + return parser::try_consume_type(s, ms); } -} + class is_destructor_with_name { + const std::string& dtor_name_; -template std::string mangled_storage_impl::get_variable(const std::string &name) const -{ - using namespace std; - using namespace boost; + public: + explicit is_destructor_with_name(const std::string& dtor_name) + : dtor_name_(dtor_name) {} - namespace x3 = spirit::x3; - using namespace parser; + inline bool operator()(boost::core::string_view s) const { + return parser::try_consume_visibility(s) + && parser::ignore_prefix(s, " virtual") + && parser::try_consume_thiscall(s) + && parser::try_consume_prefix(s, dtor_name_) + && parser::ignore_ptrs(s) + && s.empty(); + } - auto type_name = get_name(); + inline bool operator()(const mangled_storage_base::entry& e) const { + return (*this)(boost::core::string_view(e.demangled.data(), e.demangled.size())); + } + }; - auto matcher = - -(visibility >> static_ >> x3::space) >> //it may be a static class-member - parser::type_rule(type_name) >> x3::space >> - name; + template + class is_variable_with_name { + const std::string& variable_name_; + const mangled_storage_impl& ms_; - auto predicate = [&](const mangled_storage_base::entry & e) - { - if (e.demangled == name)//maybe not mangled, - return true; + public: + is_variable_with_name(const std::string& variable_name, const mangled_storage_impl& ms) + : variable_name_(variable_name), ms_(ms) {} - auto itr = e.demangled.begin(); - auto end = e.demangled.end(); - auto res = x3::parse(itr, end, matcher); - return res && (itr == end); - }; + inline bool operator()(boost::core::string_view s) const { + if (parser::try_consume_visibility(s) && !parser::try_consume_prefix(s, " static ")) { + return false; + } - auto found = std::find_if(storage_.begin(), storage_.end(), predicate); + return parser::try_consume_type(s, ms_) + && parser::try_consume_prefix(s, variable_name_) + && s.empty(); + } + + inline bool operator()(const mangled_storage_base::entry& e) const { + return (*this)(boost::core::string_view(e.demangled.data(), e.demangled.size())); + } + }; + + template + class is_constructor_with_name { + const std::string& ctor_name_; + const mangled_storage_impl& ms_; + + public: + is_constructor_with_name(const std::string& ctor_name, const mangled_storage_impl& ms) + : ctor_name_(ctor_name), ms_(ms) {} + + inline bool operator()(boost::core::string_view s) const { + return parser::try_consume_visibility(s) + && parser::try_consume_thiscall(s) + && parser::try_consume_prefix(s, ctor_name_) + && parser::try_consume_prefix(s, "(") + && parser::try_consume_arg_list(s, ms_, Signature()) + && parser::try_consume_prefix(s, ")") + && parser::ignore_ptrs(s) + && s.empty(); + } + + inline bool operator()(const mangled_storage_base::entry& e) const { + return (*this)(boost::core::string_view(e.demangled.data(), e.demangled.size())); + } + }; + + template + class is_function_with_name; + + template + class is_function_with_name { + const std::string& function_name_; + const mangled_storage_impl& ms_; + + public: + is_function_with_name(const std::string& function_name, const mangled_storage_impl& ms) + : function_name_(function_name), ms_(ms) {} + + inline bool operator()(boost::core::string_view s) const { + if (parser::try_consume_visibility(s) && !parser::try_consume_prefix(s, " static ")) { + return false; + } + + using Signature = Result(*)(Args...); + return parser::try_consume_type(s, ms_) + && parser::ignore_prefix(s, " ") + && parser::try_consume_prefix(s, "__cdecl ") + && parser::try_consume_prefix(s, function_name_) + && parser::try_consume_prefix(s, "(") + && parser::try_consume_arg_list(s, ms_, Signature()) + && parser::try_consume_prefix(s, ")") + && parser::ignore_ptrs(s) + && s.empty(); + } + + inline bool operator()(const mangled_storage_base::entry& e) const { + return (*this)(boost::core::string_view(e.demangled.data(), e.demangled.size())); + } + }; + + template + class is_mem_fn_with_name; + + template + class is_mem_fn_with_name { + const std::string& function_name_; + const mangled_storage_impl& ms_; + + public: + is_mem_fn_with_name(const std::string& function_name, const mangled_storage_impl& ms) + : function_name_(function_name), ms_(ms) {} + + inline bool operator()(boost::core::string_view s) const { + using Signature = Result(*)(Args...); + return parser::try_consume_visibility(s) + && parser::ignore_prefix(s, " virtual") + && parser::try_consume_prefix(s, " ") + && parser::try_consume_type(s, ms_) + && parser::try_consume_thiscall(s) + && parser::try_consume_type::type>(s, ms_) + && parser::try_consume_prefix(s, "::") + && parser::try_consume_prefix(s, function_name_) + && parser::try_consume_prefix(s, "(") + && parser::try_consume_arg_list(s, ms_, Signature()) + && parser::try_consume_prefix(s, ")") + && (!std::is_const::value || parser::try_consume_prefix(s, "const ")) + && (!std::is_volatile::value || parser::try_consume_prefix(s, "volatile ")) + && parser::ignore_ptrs(s) + && s.empty(); + } + + inline bool operator()(const mangled_storage_base::entry& e) const { + return (*this)(boost::core::string_view(e.demangled.data(), e.demangled.size())); + } + }; +} // namespace parser + +template +std::string mangled_storage_impl::get_variable(const std::string &name) const { + const auto found = std::find_if(storage_.begin(), storage_.end(), parser::is_variable_with_name(name, *this)); if (found != storage_.end()) return found->mangled; @@ -228,73 +332,19 @@ template std::string mangled_storage_impl::get_variable(const std::s return ""; } -template std::string mangled_storage_impl::get_function(const std::string &name) const -{ - namespace x3 = spirit::x3; - using namespace parser; - using func_type = Func*; - using return_type = typename function_traits::result_type; - std::string return_type_name = get_name(); - - - auto matcher = - -(visibility >> static_ >> x3::space) >> //it may be a static class-member, which does however not have the static attribute. - parser::type_rule(return_type_name) >> x3::space >> - cdecl_ >> //cdecl declaration for methods. stdcall cannot be - name >> x3::lit('(') >> parser::arg_list(*this, func_type()) >> x3::lit(')') >> parser::ptr_rule(); - - - auto predicate = [&](const mangled_storage_base::entry & e) - { - if (e.demangled == name)//maybe not mangled, - return true; - - auto itr = e.demangled.begin(); - auto end = e.demangled.end(); - auto res = x3::parse(itr, end, matcher); - - return res && (itr == end); - }; - - auto found = std::find_if(storage_.begin(), storage_.end(), predicate); +template +std::string mangled_storage_impl::get_function(const std::string &name) const { + const auto found = std::find_if(storage_.begin(), storage_.end(), parser::is_function_with_name(name, *this)); if (found != storage_.end()) return found->mangled; else return ""; - } template -std::string mangled_storage_impl::get_mem_fn(const std::string &name) const -{ - namespace x3 = spirit::x3; - using namespace parser; - using func_type = Func*; - using return_type = typename function_traits::result_type; - auto return_type_name = get_name(); - - - auto cname = get_name(); - - auto matcher = - visibility >> -virtual_ >> x3::space >> - parser::type_rule(return_type_name) >> x3::space >> - thiscall >> //cdecl declaration for methods. stdcall cannot be - cname >> "::" >> name >> - x3::lit('(') >> parser::arg_list(*this, func_type()) >> x3::lit(')') >> - inv_const_rule() >> inv_volatile_rule() >> parser::ptr_rule(); - - auto predicate = [&](const mangled_storage_base::entry & e) - { - auto itr = e.demangled.begin(); - auto end = e.demangled.end(); - auto res = x3::parse(itr, end, matcher); - - return res && (itr == end); - }; - - auto found = std::find_if(storage_.begin(), storage_.end(), predicate); +std::string mangled_storage_impl::get_mem_fn(const std::string &name) const { + const auto found = std::find_if(storage_.begin(), storage_.end(), parser::is_mem_fn_with_name(name, *this)); if (found != storage_.end()) return found->mangled; @@ -304,14 +354,7 @@ std::string mangled_storage_impl::get_mem_fn(const std::string &name) const template -auto mangled_storage_impl::get_constructor() const -> ctor_sym -{ - namespace x3 = spirit::x3; - using namespace parser; - - using func_type = Signature*; - - +auto mangled_storage_impl::get_constructor() const -> ctor_sym { std::string ctor_name; // = class_name + "::" + name; std::string unscoped_cname; //the unscoped class-name { @@ -329,23 +372,7 @@ auto mangled_storage_impl::get_constructor() const -> ctor_sym } } - auto matcher = - visibility >> x3::space >> - thiscall >> //cdecl declaration for methods. stdcall cannot be - ctor_name >> - x3::lit('(') >> parser::arg_list(*this, func_type()) >> x3::lit(')') >> parser::ptr_rule(); - - - auto predicate = [&](const mangled_storage_base::entry & e) - { - auto itr = e.demangled.begin(); - auto end = e.demangled.end(); - auto res = x3::parse(itr, end, matcher); - - return res && (itr == end); - }; - - auto f = std::find_if(storage_.begin(), storage_.end(), predicate); + const auto f = std::find_if(storage_.begin(), storage_.end(), parser::is_constructor_with_name(ctor_name, *this)); if (f != storage_.end()) return f->mangled; @@ -354,10 +381,7 @@ auto mangled_storage_impl::get_constructor() const -> ctor_sym } template -auto mangled_storage_impl::get_destructor() const -> dtor_sym -{ - namespace x3 = spirit::x3; - using namespace parser; +auto mangled_storage_impl::get_destructor() const -> dtor_sym { std::string dtor_name; // = class_name + "::" + name; std::string unscoped_cname; //the unscoped class-name { @@ -375,23 +399,7 @@ auto mangled_storage_impl::get_destructor() const -> dtor_sym } } - auto matcher = - visibility >> -virtual_ >> x3::space >> - thiscall >> //cdecl declaration for methods. stdcall cannot be - dtor_name >> parser::ptr_rule(); - - - auto predicate = [&](const mangled_storage_base::entry & e) - { - auto itr = e.demangled.begin(); - auto end = e.demangled.end(); - auto res = x3::parse(itr, end, matcher); - - return res && (itr == end); - }; - - auto found = std::find_if(storage_.begin(), storage_.end(), predicate); - + const auto found = std::find_if(storage_.begin(), storage_.end(), parser::is_destructor_with_name(dtor_name)); if (found != storage_.end()) return found->mangled; @@ -400,8 +408,7 @@ auto mangled_storage_impl::get_destructor() const -> dtor_sym } template -std::string mangled_storage_impl::get_vtable() const -{ +std::string mangled_storage_impl::get_vtable() const { std::string id = "const " + get_name() + "::`vftable'"; auto predicate = [&](const mangled_storage_base::entry & e) @@ -419,8 +426,7 @@ std::string mangled_storage_impl::get_vtable() const } template -std::vector mangled_storage_impl::get_related() const -{ +std::vector mangled_storage_impl::get_related() const { std::vector ret; auto name = get_name(); @@ -433,9 +439,6 @@ std::vector mangled_storage_impl::get_related() const return ret; } - }}} - - #endif /* BOOST_DLL_DETAIL_DEMANGLING_MSVC_HPP_ */ diff --git a/include/boost/dll/detail/elf_info.hpp b/include/boost/dll/detail/elf_info.hpp index 6e3849e..cf30871 100644 --- a/include/boost/dll/detail/elf_info.hpp +++ b/include/boost/dll/detail/elf_info.hpp @@ -259,7 +259,7 @@ private: read_raw(fs, symbols[0], static_cast(symtab_size - (symtab_size % sizeof(symbol_t))) ); } - static bool is_visible(const symbol_t& sym) BOOST_NOEXCEPT { + static bool is_visible(const symbol_t& sym) noexcept { const unsigned char visibility = (sym.st_other & 0x03); // `(sym.st_info >> 4) != STB_LOCAL_ && !!sym.st_size` check also workarounds the // GCC's issue https://sourceware.org/bugzilla/show_bug.cgi?id=13621 diff --git a/include/boost/dll/detail/import_mangled_helpers.hpp b/include/boost/dll/detail/import_mangled_helpers.hpp index 9838f81..c1c7781 100644 --- a/include/boost/dll/detail/import_mangled_helpers.hpp +++ b/include/boost/dll/detail/import_mangled_helpers.hpp @@ -8,11 +8,7 @@ #define BOOST_DLL_DETAIL_IMPORT_MANGLED_HELPERS_HPP_ -#include -#include -#include -#include -#include +#include #ifdef BOOST_HAS_PRAGMA_ONCE @@ -34,9 +30,9 @@ struct push_front> template struct unqalified_is_same : - boost::is_same< - typename boost::remove_cv::type, - typename boost::remove_cv::type + std::is_same< + typename std::remove_cv::type, + typename std::remove_cv::type > { }; @@ -48,19 +44,19 @@ template struct is_function_seq; //type-trait for function overloads template struct is_function_seq> - : boost::conditional< - boost::is_function::value, + : std::conditional< + std::is_function::value, is_function_seq>, - boost::false_type>::type + std::false_type>::type {}; template -struct is_function_seq> : boost::is_function +struct is_function_seq> : std::is_function { }; template<> -struct is_function_seq> : boost::false_type +struct is_function_seq> : std::false_type { }; @@ -151,11 +147,11 @@ struct make_mem_fn_seq * Class, const Class, void(int)//--> ovl class. * */ - static_assert(boost::is_object::value, ""); + static_assert(std::is_object::value, ""); typedef typename make_mem_fn_seq_getter< unqalified_is_same::value, T0, T1, T2>::type mem_fn_type; - typedef typename boost::conditional< + typedef typename std::conditional< unqalified_is_same::value, make_mem_fn_seq, make_mem_fn_seq> ::type next; @@ -203,46 +199,46 @@ struct make_mem_fn_seq template struct is_mem_fn_seq_impl { - typedef typename boost::conditional< - boost::is_function::value || boost::dll::experimental::detail::unqalified_is_same::value, + typedef typename std::conditional< + std::is_function::value || boost::dll::experimental::detail::unqalified_is_same::value, typename is_mem_fn_seq_impl::type, - boost::false_type>::type type; + std::false_type>::type type; }; template struct is_mem_fn_seq_impl { - typedef typename boost::conditional< - boost::is_function::value && boost::is_object::value, - boost::true_type, boost::false_type>::type type; + typedef typename std::conditional< + std::is_function::value && std::is_object::value, + std::true_type, std::false_type>::type type; }; template struct is_mem_fn_seq_impl { - typedef typename boost::conditional< - (boost::is_function::value || boost::dll::experimental::detail::unqalified_is_same::value) - && boost::is_function::value, - boost::true_type, boost::false_type>::type type; + typedef typename std::conditional< + (std::is_function::value || boost::dll::experimental::detail::unqalified_is_same::value) + && std::is_function::value, + std::true_type, std::false_type>::type type; }; -template struct is_mem_fn_seq : boost::false_type {}; +template struct is_mem_fn_seq : std::false_type {}; //If only two arguments are provided at all. template -struct is_mem_fn_seq> : boost::conditional< - boost::is_object::value && boost::is_function::value, - boost::true_type, boost::false_type>::type +struct is_mem_fn_seq> : std::conditional< + std::is_object::value && std::is_function::value, + std::true_type, std::false_type>::type { }; template struct is_mem_fn_seq> : - boost::conditional< - boost::is_class::value && boost::is_function::value, + std::conditional< + std::is_class::value && std::is_function::value, typename is_mem_fn_seq_impl::type, - boost::false_type>::type {}; + std::false_type>::type {}; /* ********************************** mem fn sequence tuple ******************************/ diff --git a/include/boost/dll/detail/pe_info.hpp b/include/boost/dll/detail/pe_info.hpp index a6e7aad..cb024f0 100644 --- a/include/boost/dll/detail/pe_info.hpp +++ b/include/boost/dll/detail/pe_info.hpp @@ -350,6 +350,9 @@ public: // getting ordinal fs.seekg(fixed_ordinals_addr + i * sizeof(ordinal)); read_raw(fs, ordinal); + if (ordinal >= exported_symbols) { // required for clang-win created PE + continue; + } // getting function addr fs.seekg(fixed_functions_addr + ordinal * sizeof(ptr)); @@ -380,7 +383,7 @@ public: MSVCR110D.dll */ /* - static std::vector depend_of(boost::dll::fs::error_code &ec) BOOST_NOEXCEPT { + static std::vector depend_of(boost::dll::fs::error_code &ec) noexcept { std::vector ret; IMAGE_DOS_HEADER* image_dos_header = (IMAGE_DOS_HEADER*)native(); diff --git a/include/boost/dll/detail/posix/path_from_handle.hpp b/include/boost/dll/detail/posix/path_from_handle.hpp index f4be75f..dd118e6 100644 --- a/include/boost/dll/detail/posix/path_from_handle.hpp +++ b/include/boost/dll/detail/posix/path_from_handle.hpp @@ -24,13 +24,13 @@ # include // for std::ptrdiff_t namespace boost { namespace dll { namespace detail { - inline void* strip_handle(void* handle) BOOST_NOEXCEPT { + inline void* strip_handle(void* handle) noexcept { return reinterpret_cast( (reinterpret_cast(handle) >> 2) << 2 ); } - inline boost::dll::fs::path path_from_handle(void* handle, boost::dll::fs::error_code &ec) { + inline boost::dll::fs::path path_from_handle(void* handle, std::error_code &ec) { handle = strip_handle(handle); // Iterate through all images currently in memory @@ -53,8 +53,8 @@ namespace boost { namespace dll { namespace detail { } boost::dll::detail::reset_dlerror(); - ec = boost::dll::fs::make_error_code( - boost::dll::fs::errc::bad_file_descriptor + ec = std::make_error_code( + std::errc::bad_file_descriptor ); return boost::dll::fs::path(); @@ -78,7 +78,7 @@ namespace boost { namespace dll { namespace detail { // ... // Ignoring remaning parts of the structure }; - inline boost::dll::fs::path path_from_handle(const void* handle, boost::dll::fs::error_code &ec) { + inline boost::dll::fs::path path_from_handle(const void* handle, std::error_code &ec) { static const std::size_t work_around_b_24465209__offset = 128; const struct soinfo* si = reinterpret_cast( static_cast(handle) + work_around_b_24465209__offset @@ -119,7 +119,7 @@ namespace boost { namespace dll { namespace detail { }; #endif // #if BOOST_OS_QNX - inline boost::dll::fs::path path_from_handle(void* handle, boost::dll::fs::error_code &ec) { + inline boost::dll::fs::path path_from_handle(void* handle, std::error_code &ec) { // RTLD_DI_LINKMAP (RTLD_DI_ORIGIN returns only folder and is not suitable for this case) // Obtain the Link_map for the handle that is specified. // The p argument points to a Link_map pointer (Link_map @@ -144,8 +144,8 @@ namespace boost { namespace dll { namespace detail { #endif if (!link_map) { boost::dll::detail::reset_dlerror(); - ec = boost::dll::fs::make_error_code( - boost::dll::fs::errc::bad_file_descriptor + ec = std::make_error_code( + std::errc::bad_file_descriptor ); return boost::dll::fs::path(); diff --git a/include/boost/dll/detail/posix/program_location_impl.hpp b/include/boost/dll/detail/posix/program_location_impl.hpp index e4c7f7d..58544fa 100644 --- a/include/boost/dll/detail/posix/program_location_impl.hpp +++ b/include/boost/dll/detail/posix/program_location_impl.hpp @@ -21,7 +21,7 @@ #include namespace boost { namespace dll { namespace detail { - inline boost::dll::fs::path program_location_impl(boost::dll::fs::error_code &ec) { + inline boost::dll::fs::path program_location_impl(std::error_code &ec) { ec.clear(); char path[1024]; @@ -31,8 +31,8 @@ namespace boost { namespace dll { namespace detail { char *p = new char[size]; if (_NSGetExecutablePath(p, &size) != 0) { - ec = boost::dll::fs::make_error_code( - boost::dll::fs::errc::bad_file_descriptor + ec = std::make_error_code( + std::errc::bad_file_descriptor ); } @@ -46,7 +46,7 @@ namespace boost { namespace dll { namespace detail { #include namespace boost { namespace dll { namespace detail { - inline boost::dll::fs::path program_location_impl(boost::dll::fs::error_code& ec) { + inline boost::dll::fs::path program_location_impl(std::error_code& ec) { ec.clear(); return boost::dll::fs::path(getexecname()); @@ -60,7 +60,7 @@ namespace boost { namespace dll { namespace detail { #include namespace boost { namespace dll { namespace detail { - inline boost::dll::fs::path program_location_impl(boost::dll::fs::error_code& ec) { + inline boost::dll::fs::path program_location_impl(std::error_code& ec) { ec.clear(); int mib[4]; @@ -81,7 +81,7 @@ namespace boost { namespace dll { namespace detail { #elif BOOST_OS_BSD_NET namespace boost { namespace dll { namespace detail { - inline boost::dll::fs::path program_location_impl(boost::dll::fs::error_code &ec) { + inline boost::dll::fs::path program_location_impl(std::error_code &ec) { return boost::dll::fs::read_symlink("/proc/curproc/exe", ec); } }}} // namespace boost::dll::detail @@ -90,7 +90,7 @@ namespace boost { namespace dll { namespace detail { namespace boost { namespace dll { namespace detail { - inline boost::dll::fs::path program_location_impl(boost::dll::fs::error_code &ec) { + inline boost::dll::fs::path program_location_impl(std::error_code &ec) { return boost::dll::fs::read_symlink("/proc/curproc/file", ec); } }}} // namespace boost::dll::detail @@ -100,7 +100,7 @@ namespace boost { namespace dll { namespace detail { #include #include // for std::getline namespace boost { namespace dll { namespace detail { - inline boost::dll::fs::path program_location_impl(boost::dll::fs::error_code &ec) { + inline boost::dll::fs::path program_location_impl(std::error_code &ec) { ec.clear(); std::string s; @@ -108,8 +108,8 @@ namespace boost { namespace dll { namespace detail { std::getline(ifs, s); if (ifs.fail() || s.empty()) { - ec = boost::dll::fs::make_error_code( - boost::dll::fs::errc::bad_file_descriptor + ec = std::make_error_code( + std::errc::bad_file_descriptor ); } @@ -120,12 +120,15 @@ namespace boost { namespace dll { namespace detail { #else // BOOST_OS_LINUX || BOOST_OS_UNIX || BOOST_OS_HPUX || BOOST_OS_ANDROID namespace boost { namespace dll { namespace detail { - inline boost::dll::fs::path program_location_impl(boost::dll::fs::error_code &ec) { + inline boost::dll::fs::path program_location_impl(std::error_code &ec) { // We can not use // boost::dll::detail::path_from_handle(dlopen(NULL, RTLD_LAZY | RTLD_LOCAL), ignore); // because such code returns empty path. - return boost::dll::fs::read_symlink("/proc/self/exe", ec); // Linux specific + boost::dll::fs::error_code fs_errc; + auto result = boost::dll::fs::read_symlink("/proc/self/exe", fs_errc); // Linux specific + ec = fs_errc; + return result; } }}} // namespace boost::dll::detail diff --git a/include/boost/dll/detail/posix/shared_library_impl.hpp b/include/boost/dll/detail/posix/shared_library_impl.hpp index e3f12f7..594cddb 100644 --- a/include/boost/dll/detail/posix/shared_library_impl.hpp +++ b/include/boost/dll/detail/posix/shared_library_impl.hpp @@ -13,10 +13,11 @@ #include #include -#include #include #include +#include // std::move + #include #include // strncmp #if !BOOST_OS_MACOS && !BOOST_OS_IOS && !BOOST_OS_QNX @@ -33,31 +34,28 @@ 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 - : handle_(NULL) + shared_library_impl() noexcept + : handle_(nullptr) {} - ~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; + sl.handle_ = nullptr; } - shared_library_impl(native_handle_t handle) + explicit shared_library_impl(native_handle_t handle) noexcept : handle_(handle) {} - 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; } @@ -73,7 +71,7 @@ public: return actual_path; } - void load(boost::dll::fs::path sl, load_mode::type portable_mode, boost::dll::fs::error_code &ec) { + void load(boost::dll::fs::path sl, load_mode::type portable_mode, std::error_code &ec) { typedef int native_mode_t; native_mode_t native_mode = static_cast(portable_mode); unload(); @@ -81,8 +79,8 @@ public: // Do not allow opening NULL paths. User must use program_location() instead if (sl.empty()) { boost::dll::detail::reset_dlerror(); - ec = boost::dll::fs::make_error_code( - boost::dll::fs::errc::bad_file_descriptor + ec = std::make_error_code( + std::errc::bad_file_descriptor ); return; @@ -128,8 +126,8 @@ public: boost::dll::fs::path loc = boost::dll::detail::program_location_impl(prog_loc_err); if (boost::dll::fs::exists(actual_path) && !boost::dll::fs::equivalent(sl, loc, prog_loc_err)) { // decorated path exists : current error is not a bad file descriptor and we are not trying to load the executable itself - ec = boost::dll::fs::make_error_code( - boost::dll::fs::errc::executable_format_error + ec = std::make_error_code( + std::errc::executable_format_error ); return; } @@ -142,8 +140,8 @@ public: return; } - ec = boost::dll::fs::make_error_code( - boost::dll::fs::errc::bad_file_descriptor + ec = std::make_error_code( + std::errc::bad_file_descriptor ); // Maybe user wanted to load the executable itself? Checking... @@ -158,20 +156,20 @@ public: // 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 = boost::dll::fs::make_error_code( - boost::dll::fs::errc::bad_file_descriptor + ec = std::make_error_code( + std::errc::bad_file_descriptor ); } } } - 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; } @@ -180,11 +178,11 @@ public: handle_ = 0; } - void swap(shared_library_impl& rhs) BOOST_NOEXCEPT { + void swap(shared_library_impl& rhs) noexcept { boost::core::invoke_swap(handle_, rhs.handle_); } - boost::dll::fs::path full_module_path(boost::dll::fs::error_code &ec) const { + boost::dll::fs::path full_module_path(std::error_code &ec) const { return boost::dll::detail::path_from_handle(handle_, ec); } @@ -197,12 +195,12 @@ public: #endif } - void* symbol_addr(const char* sb, boost::dll::fs::error_code &ec) const BOOST_NOEXCEPT { + 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) { - ec = boost::dll::fs::make_error_code( - boost::dll::fs::errc::invalid_seek + if (symbol == nullptr) { + ec = std::make_error_code( + std::errc::invalid_seek ); } @@ -214,7 +212,7 @@ public: return symbol; } - native_handle_t native() const BOOST_NOEXCEPT { + native_handle_t native() const noexcept { return handle_; } diff --git a/include/boost/dll/detail/system_error.hpp b/include/boost/dll/detail/system_error.hpp index a0d42f5..ccedc44 100644 --- a/include/boost/dll/detail/system_error.hpp +++ b/include/boost/dll/detail/system_error.hpp @@ -22,14 +22,14 @@ namespace boost { namespace dll { namespace detail { - inline void reset_dlerror() BOOST_NOEXCEPT { + inline void reset_dlerror() noexcept { #if !BOOST_OS_WINDOWS const char* const error_txt = dlerror(); (void)error_txt; #endif } - inline void report_error(const boost::dll::fs::error_code& ec, const char* message) { + inline void report_error(const std::error_code& ec, const char* message) { #if !BOOST_OS_WINDOWS const char* const error_txt = dlerror(); if (error_txt) { diff --git a/include/boost/dll/detail/windows/path_from_handle.hpp b/include/boost/dll/detail/windows/path_from_handle.hpp index a7513dd..505cd32 100644 --- a/include/boost/dll/detail/windows/path_from_handle.hpp +++ b/include/boost/dll/detail/windows/path_from_handle.hpp @@ -19,15 +19,15 @@ namespace boost { namespace dll { namespace detail { - inline boost::dll::fs::error_code last_error_code() BOOST_NOEXCEPT { + inline std::error_code last_error_code() noexcept { boost::winapi::DWORD_ err = boost::winapi::GetLastError(); - return boost::dll::fs::error_code( + return std::error_code( static_cast(err), - boost::dll::fs::system_category() + std::system_category() ); } - inline boost::dll::fs::path path_from_handle(boost::winapi::HMODULE_ handle, boost::dll::fs::error_code &ec) { + inline boost::dll::fs::path path_from_handle(boost::winapi::HMODULE_ handle, std::error_code &ec) { BOOST_STATIC_CONSTANT(boost::winapi::DWORD_, ERROR_INSUFFICIENT_BUFFER_ = 0x7A); BOOST_STATIC_CONSTANT(boost::winapi::DWORD_, DEFAULT_PATH_SIZE_ = 260); diff --git a/include/boost/dll/detail/windows/shared_library_impl.hpp b/include/boost/dll/detail/windows/shared_library_impl.hpp index 17a8072..e573bc1 100644 --- a/include/boost/dll/detail/windows/shared_library_impl.hpp +++ b/include/boost/dll/detail/windows/shared_library_impl.hpp @@ -14,11 +14,12 @@ #include #include -#include #include #include +#include // std::move + #ifdef BOOST_HAS_PRAGMA_ONCE # pragma once #endif @@ -26,30 +27,28 @@ 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 - : handle_(NULL) + shared_library_impl() noexcept + : shared_library_impl(nullptr) {} - ~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; + sl.handle_ = nullptr; } - shared_library_impl(native_handle_t handle) + explicit shared_library_impl(native_handle_t handle) noexcept : handle_(handle) {} - 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; } @@ -60,7 +59,7 @@ public: return actual_path; } - void load(boost::dll::fs::path sl, load_mode::type portable_mode, boost::dll::fs::error_code &ec) { + void load(boost::dll::fs::path sl, load_mode::type portable_mode, std::error_code &ec) { typedef boost::winapi::DWORD_ native_mode_t; native_mode_t native_mode = static_cast(portable_mode); unload(); @@ -115,22 +114,22 @@ public: } } - 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_); } - boost::dll::fs::path full_module_path(boost::dll::fs::error_code &ec) const { + boost::dll::fs::path full_module_path(std::error_code &ec) const { return boost::dll::detail::path_from_handle(handle_, ec); } @@ -138,16 +137,16 @@ public: return L".dll"; } - void* symbol_addr(const char* sb, boost::dll::fs::error_code &ec) const BOOST_NOEXCEPT { + void* symbol_addr(const char* sb, std::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` // or `LOAD_LIBRARY_AS_IMAGE_RESOURCE`. - ec = boost::dll::fs::make_error_code( - boost::dll::fs::errc::operation_not_supported + ec = std::make_error_code( + std::errc::operation_not_supported ); - return NULL; + return nullptr; } // Judging by the documentation of GetProcAddress @@ -156,20 +155,20 @@ public: 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(); } return symbol; } - native_handle_t native() const BOOST_NOEXCEPT { + native_handle_t native() const noexcept { return handle_; } 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) { + bool load_impl(const boost::dll::fs::path &load_path, boost::winapi::DWORD_ mode, std::error_code &ec) { handle_ = boost::winapi::LoadLibraryExW(load_path.c_str(), 0, mode); if (handle_) { return true; @@ -185,7 +184,7 @@ private: 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 6a8fce8..0397f78 100644 --- a/include/boost/dll/import.hpp +++ b/include/boost/dll/import.hpp @@ -9,16 +9,11 @@ #define BOOST_DLL_IMPORT_HPP #include -#include -#include -#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 -#endif +#include // std::addressof +#include #ifdef BOOST_HAS_PRAGMA_ONCE # pragma once @@ -40,16 +35,10 @@ 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 { - return f_.get(); - } -#else - // Compilation error at this point means that imported function // was called with unmatching parameters. // @@ -64,33 +53,20 @@ namespace detail { { return (*f_)(static_cast(args)...); } -#endif }; - template - struct import_type; template - struct import_type >::type> { - typedef boost::dll::detail::library_function base_type; - -#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) - typedef boost::function type; -#else - typedef boost::dll::detail::library_function type; -#endif - }; - - template - struct import_type >::type> { - typedef boost::shared_ptr base_type; - typedef boost::shared_ptr type; - }; + using import_type = typename std::conditional< + std::is_object::value, + boost::shared_ptr, + boost::dll::detail::library_function + >::type; } // namespace detail #ifndef BOOST_DLL_DOXYGEN -# define BOOST_DLL_IMPORT_RESULT_TYPE inline typename boost::dll::detail::import_type::type +# define BOOST_DLL_IMPORT_RESULT_TYPE inline boost::dll::detail::import_type #endif @@ -108,7 +84,7 @@ namespace detail { * \b Examples: * * \code -* boost::function f = import_symbol("test_lib.so", "integer_func_name"); +* std::function f = import_symbol("test_lib.so", "integer_func_name"); * * auto f_cpp11 = import_symbol("test_lib.so", "integer_func_name"); * \endcode @@ -132,10 +108,10 @@ template BOOST_DLL_IMPORT_RESULT_TYPE import_symbol(const boost::dll::fs::path& lib, const char* name, load_mode::type mode = load_mode::default_mode) { - typedef typename boost::dll::detail::import_type::base_type type; + using type = boost::dll::detail::import_type; - boost::shared_ptr p = boost::make_shared(lib, mode); - return type(p, boost::addressof(p->get(name))); + auto p = boost::make_shared(lib, mode); + return type(p, std::addressof(p->get(name))); } //! \overload boost::dll::import_symbol(const boost::dll::fs::path& lib, const char* name, load_mode::type mode) @@ -149,10 +125,10 @@ BOOST_DLL_IMPORT_RESULT_TYPE import_symbol(const boost::dll::fs::path& lib, cons //! \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(const shared_library& lib, const char* name) { - typedef typename boost::dll::detail::import_type::base_type type; + using type = boost::dll::detail::import_type; - boost::shared_ptr p = boost::make_shared(lib); - return type(p, boost::addressof(p->get(name))); + auto p = boost::make_shared(lib); + return type(p, std::addressof(p->get(name))); } //! \overload boost::dll::import_symbol(const boost::dll::fs::path& lib, const char* name, load_mode::type mode) @@ -163,19 +139,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) { - typedef typename boost::dll::detail::import_type::base_type type; +BOOST_DLL_IMPORT_RESULT_TYPE import_symbol(shared_library&& lib, const char* name) { + using type = boost::dll::detail::import_type; - boost::shared_ptr p = boost::make_shared( - boost::move(lib) + auto p = boost::make_shared( + std::move(lib) ); - return type(p, boost::addressof(p->get(name))); + return type(p, std::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()); } @@ -195,7 +171,7 @@ BOOST_DLL_IMPORT_RESULT_TYPE import_symbol(BOOST_RV_REF(shared_library) lib, con * \b Examples: * * \code -* boost::function f = import_alias("test_lib.so", "integer_func_alias_name"); +* std::function f = import_alias("test_lib.so", "integer_func_alias_name"); * * auto f_cpp11 = import_alias("test_lib.so", "integer_func_alias_name"); * \endcode @@ -222,9 +198,9 @@ template BOOST_DLL_IMPORT_RESULT_TYPE import_alias(const boost::dll::fs::path& lib, const char* name, load_mode::type mode = load_mode::default_mode) { - typedef typename boost::dll::detail::import_type::base_type type; + using type = boost::dll::detail::import_type; - boost::shared_ptr p = boost::make_shared(lib, mode); + auto p = boost::make_shared(lib, mode); return type(p, p->get(name)); } @@ -239,9 +215,9 @@ BOOST_DLL_IMPORT_RESULT_TYPE import_alias(const boost::dll::fs::path& lib, const //! \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(const shared_library& lib, const char* name) { - typedef typename boost::dll::detail::import_type::base_type type; + using type = boost::dll::detail::import_type; - boost::shared_ptr p = boost::make_shared(lib); + auto p = boost::make_shared(lib); return type(p, p->get(name)); } @@ -253,19 +229,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) { - typedef typename boost::dll::detail::import_type::base_type type; +BOOST_DLL_IMPORT_RESULT_TYPE import_alias(shared_library&& lib, const char* name) { + using type = boost::dll::detail::import_type; - boost::shared_ptr p = boost::make_shared( - boost::move(lib) + auto p = boost::make_shared( + 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_class.hpp b/include/boost/dll/import_class.hpp index f4cd3f8..2b9b855 100644 --- a/include/boost/dll/import_class.hpp +++ b/include/boost/dll/import_class.hpp @@ -15,6 +15,7 @@ #include #include #include +#include // std::move #if (__cplusplus < 201103L) && (!defined(_MSVC_LANG) || _MSVC_LANG < 201103L) # error This file requires C++11 at least! @@ -68,7 +69,7 @@ struct mem_fn_call_proxy - auto operator()(Args&&...args) const + auto operator()(Args&&...args) const -> decltype(mem_fn(t, std::forward(args)...)) { return mem_fn(t, std::forward(args)...); } @@ -119,11 +120,11 @@ import_class(const smart_library& lib, std::size_t size, template class imported_class { - smart_library _lib; - std::unique_ptr> _data; - bool _is_allocating; - std::size_t _size; - const std::type_info& _ti; + smart_library lib_; + std::unique_ptr> data_; + bool is_allocating_; + std::size_t size_; + const std::type_info& ti_; template inline std::unique_ptr> make_data(const smart_library& lib, Args ... args); @@ -147,14 +148,14 @@ public: static imported_class make(smart_library&& lib, Args...args) { typedef detail::sequence *seq; - return imported_class(seq(), boost::move(lib), static_cast(args)...); + return imported_class(seq(), std::move(lib), static_cast(args)...); } template static imported_class make(smart_library&& lib, std::size_t size, Args...args) { typedef detail::sequence *seq; - return imported_class(seq(), boost::move(lib), size, static_cast(args)...); + return imported_class(seq(), std::move(lib), size, static_cast(args)...); } template static imported_class make(const smart_library& lib, Args...args) @@ -172,7 +173,7 @@ public: typedef imported_class base_t; ///Returns a pointer to the underlying class - T* get() {return _data.get();} + T* get() {return data_.get();} imported_class() = delete; imported_class(imported_class&) = delete; @@ -181,13 +182,13 @@ public: imported_class& operator=(imported_class&&) = default; /// ().empty();} + bool is_move_constructible() {return !lib_.symbol_storage().template get_constructor ().empty();} ///Check if the imported class is move-assignable - bool is_move_assignable() {return !_lib.symbol_storage().template get_mem_fn ("operator=").empty();} + bool is_move_assignable() {return !lib_.symbol_storage().template get_mem_fn ("operator=").empty();} ///Check if the imported class is copy-constructible - bool is_copy_constructible() {return !_lib.symbol_storage().template get_constructor().empty();} + bool is_copy_constructible() {return !lib_.symbol_storage().template get_constructor().empty();} ///Check if the imported class is copy-assignable - bool is_copy_assignable() {return !_lib.symbol_storage().template get_mem_fn("operator=").empty();} + bool is_copy_assignable() {return !lib_.symbol_storage().template get_mem_fn("operator=").empty();} imported_class copy() const; /// move(); /// & lhs); ///Check if the class is loaded. - explicit operator bool() const {return _data;} + explicit operator bool() const {return data_;} ///Get a const reference to the std::type_info. - const std::type_info& get_type_info() {return _ti;}; + const std::type_info& get_type_info() {return ti_;}; /*! Call a member function. This returns a proxy to the function. * The proxy mechanic mechanic is necessary, so the signaute can be passed. @@ -215,7 +216,7 @@ public: template const detail::mem_fn_call_proxy call(const std::string& name) { - return detail::mem_fn_call_proxy(_data.get(), name, _lib); + return detail::mem_fn_call_proxy(data_.get(), name, lib_); } /*! Call a qualified member function, i.e. const and or volatile. * @@ -228,14 +229,14 @@ public: template>> const detail::mem_fn_call_proxy call(const std::string& name) { - return detail::mem_fn_call_proxy(_data.get(), name, _lib); + return detail::mem_fn_call_proxy(data_.get(), name, lib_); } ///Overload of ->* for an imported method. template const detail::mem_fn_call_proxy> operator->*(detail::mangled_library_mem_fn& mn) { - return detail::mem_fn_call_proxy>(_data.get(), mn); + return detail::mem_fn_call_proxy>(data_.get(), mn); } ///Import a method of the class. @@ -243,7 +244,7 @@ public: typename boost::dll::experimental::detail::mangled_import_type>::type import(const std::string & name) { - return boost::dll::experimental::import_mangled(_lib, name); + return boost::dll::experimental::import_mangled(lib_, name); } }; @@ -259,10 +260,8 @@ inline std::unique_ptr> imported_class::make_data(const if (!ctor.has_allocating() || !dtor.has_deleting()) { - boost::dll::fs::error_code ec; - - ec = boost::dll::fs::make_error_code( - boost::dll::fs::errc::bad_file_descriptor + std::error_code ec = std::make_error_code( + std::errc::bad_file_descriptor ); // report_error() calls dlsym, do not use it here! @@ -288,10 +287,8 @@ inline std::unique_ptr> imported_class::make_data(const if (!ctor.has_standard() || !dtor.has_standard()) { - boost::dll::fs::error_code ec; - - ec = boost::dll::fs::make_error_code( - boost::dll::fs::errc::bad_file_descriptor + std::error_code ec = std::make_error_code( + std::errc::bad_file_descriptor ); // report_error() calls dlsym, do not use it here! @@ -316,11 +313,11 @@ inline std::unique_ptr> imported_class::make_data(const template template imported_class::imported_class(detail::sequence *, const smart_library & lib, Args...args) - : _lib(lib), - _data(make_data(lib, static_cast(args)...)), - _is_allocating(false), - _size(0), - _ti(lib.get_type_info()) + : lib_(lib), + data_(make_data(lib_, static_cast(args)...)), + is_allocating_(false), + size_(0), + ti_(lib.get_type_info()) { } @@ -328,11 +325,11 @@ imported_class::imported_class(detail::sequence *, const smart_libra template template imported_class::imported_class(detail::sequence *, const smart_library & lib, std::size_t size, Args...args) - : _lib(lib), - _data(make_data(lib, size, static_cast(args)...)), - _is_allocating(true), - _size(size), - _ti(lib.get_type_info()) + : lib_(lib), + data_(make_data(lib_, size, static_cast(args)...)), + is_allocating_(true), + size_(size), + ti_(lib.get_type_info()) { } @@ -340,11 +337,11 @@ imported_class::imported_class(detail::sequence *, const smart_libra template template imported_class::imported_class(detail::sequence *, smart_library && lib, Args...args) - : _lib(boost::move(lib)), - _data(make_data(lib, static_cast(args)...)), - _is_allocating(false), - _size(0), - _ti(lib.get_type_info()) + : lib_(std::move(lib)), + data_(make_data(lib_, static_cast(args)...)), + is_allocating_(false), + size_(0), + ti_(lib.get_type_info()) { } @@ -352,11 +349,11 @@ imported_class::imported_class(detail::sequence *, smart_library && template template imported_class::imported_class(detail::sequence *, smart_library && lib, std::size_t size, Args...args) - : _lib(boost::move(lib)), - _data(make_data(lib, size, static_cast(args)...)), - _is_allocating(true), - _size(size), - _ti(lib.get_type_info()) + : lib_(std::move(lib)), + data_(make_data(lib_, size, static_cast(args)...)), + is_allocating_(true), + size_(size), + ti_(lib.get_type_info()) { } @@ -364,31 +361,31 @@ imported_class::imported_class(detail::sequence *, smart_library && template inline imported_class boost::dll::experimental::imported_class::copy() const { - if (this->_is_allocating) - return imported_class::template make(_lib, *_data); + if (this->is_allocating_) + return imported_class::template make(lib_, *data_); else - return imported_class::template make(_lib, _size, *_data); + return imported_class::template make(lib_, size_, *data_); } template inline imported_class boost::dll::experimental::imported_class::move() { - if (this->_is_allocating) - return imported_class::template make(_lib, *_data); + if (this->is_allocating_) + return imported_class::template make(lib_, *data_); else - return imported_class::template make(_lib, _size, *_data); + return imported_class::template make(lib_, size_, *data_); } template inline void boost::dll::experimental::imported_class::copy_assign(const imported_class& lhs) const { - this->call("operator=")(*lhs._data); + this->call("operator=")(*lhs.data_); } template inline void boost::dll::experimental::imported_class::move_assign(imported_class& lhs) { - this->call("operator=")(static_cast(*lhs._data)); + this->call("operator=")(static_cast(*lhs.data_)); } @@ -423,90 +420,43 @@ inline void boost::dll::experimental::imported_class::move_assign(imported_cl * Overload that accepts path also throws std::bad_alloc in case of insufficient memory. */ template imported_class -import_class(const smart_library& lib_, std::size_t size, Args...args) +import_class(smart_library lib, std::size_t size, Args...args) { - smart_library lib(lib_); - - return imported_class::template make(boost::move(lib), size, static_cast(args)...); + return imported_class::template make(std::move(lib), size, static_cast(args)...); } //! \overload boost::dll::import_class(const smart_library& lib, std::size_t, Args...) template imported_class -import_class(const smart_library& lib_, Args...args) +import_class(smart_library lib, Args...args) { - smart_library lib(lib_); - return imported_class::template make(boost::move(lib), static_cast(args)...); + return imported_class::template make(std::move(lib), static_cast(args)...); } //! \overload boost::dll::import_class(const smart_library& lib, std::size_t, Args...) template imported_class -import_class(const smart_library& lib_, const std::string & alias_name, Args...args) -{ - smart_library lib(lib_); - lib.add_type_alias(alias_name); - return imported_class::template make(boost::move(lib), static_cast(args)...); -} - -//! \overload boost::dll::import_class(const smart_library& lib, std::size_t, Args...) -template imported_class -import_class(const smart_library& lib_, std::size_t size, const std::string & alias_name, Args...args) -{ - smart_library lib(lib_); - - lib.add_type_alias(alias_name); - return imported_class::template make(boost::move(lib), size, static_cast(args)...); -} - -//! \overload boost::dll::import_class(const smart_library& lib, std::size_t, Args...) -template imported_class -import_class(const smart_library& lib_, const std::string & alias_name, std::size_t size, Args...args) -{ - smart_library lib(lib_); - - lib.add_type_alias(alias_name); - return imported_class::template make(boost::move(lib), size, static_cast(args)...); -} - -//! \overload boost::dll::import_class(const smart_library& lib, std::size_t, Args...) -template imported_class -import_class(smart_library && lib, Args...args) -{ - return imported_class::template make(boost::move(lib), static_cast(args)...); -} - -//! \overload boost::dll::import_class(const smart_library& lib, std::size_t, Args...) -template imported_class -import_class(smart_library && lib, const std::string & alias_name, Args...args) +import_class(smart_library lib, const std::string & alias_name, Args...args) { lib.add_type_alias(alias_name); - return imported_class::template make(boost::move(lib), static_cast(args)...); + return imported_class::template make(std::move(lib), static_cast(args)...); } //! \overload boost::dll::import_class(const smart_library& lib, std::size_t, Args...) template imported_class -import_class(smart_library && lib, std::size_t size, Args...args) -{ - return imported_class::template make(boost::move(lib), size, static_cast(args)...); -} - -//! \overload boost::dll::import_class(const smart_library& lib, std::size_t, Args...) -template imported_class -import_class(smart_library && lib, std::size_t size, const std::string & alias_name, Args...args) +import_class(smart_library lib, std::size_t size, const std::string & alias_name, Args...args) { lib.add_type_alias(alias_name); - return imported_class::template make(boost::move(lib), size, static_cast(args)...); + return imported_class::template make(std::move(lib), size, static_cast(args)...); } //! \overload boost::dll::import_class(const smart_library& lib, std::size_t, Args...) template imported_class -import_class(smart_library && lib, const std::string & alias_name, std::size_t size, Args...args) +import_class(smart_library lib, const std::string & alias_name, std::size_t size, Args...args) { lib.add_type_alias(alias_name); - return imported_class::template make(boost::move(lib), size, static_cast(args)...); + return imported_class::template make(std::move(lib), size, static_cast(args)...); } - /*! \overload boost::dll::import_class(const smart_library& lib, std::size_t, Args...) * \note This function does add the type alias to the \ref boost::dll::experimental::smart_library. */ diff --git a/include/boost/dll/import_mangled.hpp b/include/boost/dll/import_mangled.hpp index 6dc8d3c..1a5e22c 100644 --- a/include/boost/dll/import_mangled.hpp +++ b/include/boost/dll/import_mangled.hpp @@ -19,13 +19,11 @@ #endif #include -#include #include #include -#include -#include -#include -#include + +#include // std::addressof +#include #ifdef BOOST_HAS_PRAGMA_ONCE @@ -43,7 +41,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 +75,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...) {} @@ -94,8 +92,8 @@ public: // simple enough to be here -template struct is_variable : boost::false_type {}; -template struct is_variable> : boost::is_object {}; +template struct is_variable : std::false_type {}; +template struct is_variable> : std::is_object {}; template ::value, @@ -113,7 +111,7 @@ struct mangled_import_type, true,false,false> //is function { return type( boost::make_shared(p.shared_lib()), - boost::addressof(p.get_function(name))...); + std::addressof(p.get_function(name))...); } }; @@ -154,7 +152,7 @@ struct mangled_import_type, false, false, true> //is variable { return type( boost::make_shared(p.shared_lib()), - boost::addressof(p.get_variable(name))); + std::addressof(p.get_variable(name))); } }; @@ -186,7 +184,7 @@ struct mangled_import_type, false, false, true> //is variable * \b Examples: * * \code -* boost::function f = import_mangled("test_lib.so", "integer_func_name"); +* std::function f = import_mangled("test_lib.so", "integer_func_name"); * * auto f_cpp11 = import_mangled("test_lib.so", "integer_func_name"); * \endcode @@ -264,7 +262,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 +270,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) @@ -282,7 +280,7 @@ BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(const shared_library& lib, c typedef typename boost::dll::experimental::detail::mangled_import_type> type; boost::shared_ptr p = boost::make_shared(lib); - return type::make(p, name); + return type::boostmake(p, name); } //! \overload boost::dll::import(const boost::dll::fs::path& lib, const char* name, load_mode::type mode) @@ -293,18 +291,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/library_info.hpp b/include/boost/dll/library_info.hpp index ca317c9..d68d7a9 100644 --- a/include/boost/dll/library_info.hpp +++ b/include/boost/dll/library_info.hpp @@ -14,9 +14,9 @@ #include #include #include -#include #include +#include #include #include @@ -50,15 +50,15 @@ private: } fmt_; /// @cond - inline static void throw_if_in_32bit_impl(boost::true_type /* is_32bit_platform */) { + inline static void throw_if_in_32bit_impl(std::true_type /* is_32bit_platform */) { boost::throw_exception(std::runtime_error("Not native format: 64bit binary")); } - inline static void throw_if_in_32bit_impl(boost::false_type /* is_32bit_platform */) BOOST_NOEXCEPT {} + inline static void throw_if_in_32bit_impl(std::false_type /* is_32bit_platform */) noexcept {} inline static void throw_if_in_32bit() { - throw_if_in_32bit_impl( boost::integral_constant() ); + throw_if_in_32bit_impl( std::integral_constant() ); } static void throw_if_in_windows() { diff --git a/include/boost/dll/runtime_symbol_info.hpp b/include/boost/dll/runtime_symbol_info.hpp index 8a9128b..bd400c2 100644 --- a/include/boost/dll/runtime_symbol_info.hpp +++ b/include/boost/dll/runtime_symbol_info.hpp @@ -12,6 +12,7 @@ #include #include #include + #if BOOST_OS_WINDOWS # include # include @@ -20,6 +21,8 @@ # include #endif +#include // std::addressof + #ifdef BOOST_HAS_PRAGMA_ONCE # pragma once #endif @@ -30,7 +33,7 @@ namespace boost { namespace dll { #if BOOST_OS_WINDOWS namespace detail { - inline boost::dll::fs::path program_location_impl(boost::dll::fs::error_code& ec) { + inline boost::dll::fs::path program_location_impl(std::error_code& ec) { return boost::dll::detail::path_from_handle(NULL, ec); } } // namespace detail @@ -53,12 +56,12 @@ namespace detail { * \endcode */ template - inline boost::dll::fs::path symbol_location_ptr(T ptr_to_symbol, boost::dll::fs::error_code& ec) { - static_assert(boost::is_pointer::value, "boost::dll::symbol_location_ptr works only with pointers! `ptr_to_symbol` must be a pointer"); + inline boost::dll::fs::path symbol_location_ptr(T ptr_to_symbol, std::error_code& ec) { + static_assert(std::is_pointer::value, "boost::dll::symbol_location_ptr works only with pointers! `ptr_to_symbol` must be a pointer"); boost::dll::fs::path ret; if (!ptr_to_symbol) { - ec = boost::dll::fs::make_error_code( - boost::dll::fs::errc::bad_address + ec = std::make_error_code( + std::errc::bad_address ); return ret; @@ -85,8 +88,8 @@ namespace detail { ret = info.dli_fname; } else { boost::dll::detail::reset_dlerror(); - ec = boost::dll::fs::make_error_code( - boost::dll::fs::errc::bad_address + ec = std::make_error_code( + std::errc::bad_address ); } @@ -94,11 +97,11 @@ namespace detail { #endif } - //! \overload symbol_location_ptr(const void* ptr_to_symbol, boost::dll::fs::error_code& ec) + //! \overload symbol_location_ptr(const void* ptr_to_symbol, std::error_code& ec) template inline boost::dll::fs::path symbol_location_ptr(T ptr_to_symbol) { boost::dll::fs::path ret; - boost::dll::fs::error_code ec; + std::error_code ec; ret = boost::dll::symbol_location_ptr(ptr_to_symbol, ec); if (ec) { @@ -132,10 +135,10 @@ namespace detail { * \endcode */ template - inline boost::dll::fs::path symbol_location(const T& symbol, boost::dll::fs::error_code& ec) { + inline boost::dll::fs::path symbol_location(const T& symbol, std::error_code& ec) { ec.clear(); return boost::dll::symbol_location_ptr( - boost::dll::detail::aggressive_ptr_cast(boost::addressof(symbol)), + boost::dll::detail::aggressive_ptr_cast(std::addressof(symbol)), ec ); } @@ -146,15 +149,15 @@ namespace detail { template inline boost::dll::fs::path symbol_location(const T& symbol, const char* /*workaround*/ = 0) #else - //! \overload symbol_location(const T& symbol, boost::dll::fs::error_code& ec) + //! \overload symbol_location(const T& symbol, std::error_code& ec) template inline boost::dll::fs::path symbol_location(const T& symbol) #endif { boost::dll::fs::path ret; - boost::dll::fs::error_code ec; + std::error_code ec; ret = boost::dll::symbol_location_ptr( - boost::dll::detail::aggressive_ptr_cast(boost::addressof(symbol)), + boost::dll::detail::aggressive_ptr_cast(std::addressof(symbol)), ec ); @@ -180,16 +183,16 @@ namespace detail { * \param ec Variable that will be set to the result of the operation. * \throws std::bad_alloc in case of insufficient memory. Overload that does not accept \forcedlinkfs{error_code} also throws \forcedlinkfs{system_error}. */ - static inline boost::dll::fs::path this_line_location(boost::dll::fs::error_code& ec) { - typedef boost::dll::fs::path(func_t)(boost::dll::fs::error_code& ); + static inline boost::dll::fs::path this_line_location(std::error_code& ec) { + typedef boost::dll::fs::path(func_t)(std::error_code& ); func_t& f = this_line_location; return boost::dll::symbol_location(f, ec); } - //! \overload this_line_location(boost::dll::fs::error_code& ec) + //! \overload this_line_location(std::error_code& ec) static inline boost::dll::fs::path this_line_location() { boost::dll::fs::path ret; - boost::dll::fs::error_code ec; + std::error_code ec; ret = this_line_location(ec); if (ec) { @@ -213,15 +216,15 @@ namespace detail { * \param ec Variable that will be set to the result of the operation. * \throws std::bad_alloc in case of insufficient memory. Overload that does not accept \forcedlinkfs{error_code} also throws \forcedlinkfs{system_error}. */ - inline boost::dll::fs::path program_location(boost::dll::fs::error_code& ec) { + inline boost::dll::fs::path program_location(std::error_code& ec) { ec.clear(); return boost::dll::detail::program_location_impl(ec); } - //! \overload program_location(boost::dll::fs::error_code& ec) { + //! \overload program_location(std::error_code& ec) { inline boost::dll::fs::path program_location() { boost::dll::fs::path ret; - boost::dll::fs::error_code ec; + std::error_code ec; ret = boost::dll::detail::program_location_impl(ec); if (ec) { diff --git a/include/boost/dll/shared_library.hpp b/include/boost/dll/shared_library.hpp index 3666ca3..f7d8853 100644 --- a/include/boost/dll/shared_library.hpp +++ b/include/boost/dll/shared_library.hpp @@ -16,7 +16,6 @@ #include #include #include -#include #include #include @@ -26,6 +25,9 @@ # include #endif +#include +#include // std::move + #ifdef BOOST_HAS_PRAGMA_ONCE # pragma once #endif @@ -50,7 +52,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 +66,7 @@ public: * \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. @@ -90,7 +91,7 @@ public: * \post lib == *this * \throw std::bad_alloc in case of insufficient memory. */ - shared_library(const shared_library& lib, boost::dll::fs::error_code& ec) + shared_library(const shared_library& lib, std::error_code& ec) : base_t() { assign(lib, ec); @@ -103,8 +104,8 @@ public: * \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)) {} /*! @@ -128,12 +129,12 @@ public: * \param ec Variable that will be set to the result of the operation. * \throw std::bad_alloc in case of insufficient memory. */ - shared_library(const boost::dll::fs::path& lib_path, boost::dll::fs::error_code& ec, load_mode::type mode = load_mode::default_mode) { + shared_library(const boost::dll::fs::path& lib_path, std::error_code& ec, load_mode::type mode = load_mode::default_mode) { shared_library::load(lib_path, mode, ec); } - //! \overload shared_library(const boost::dll::fs::path& lib_path, boost::dll::fs::error_code& ec, load_mode::type mode = load_mode::default_mode) - shared_library(const boost::dll::fs::path& lib_path, load_mode::type mode, boost::dll::fs::error_code& ec) { + //! \overload shared_library(const boost::dll::fs::path& lib_path, std::error_code& ec, load_mode::type mode = load_mode::default_mode) + shared_library(const boost::dll::fs::path& lib_path, load_mode::type mode, std::error_code& ec) { shared_library::load(lib_path, mode, ec); } @@ -142,7 +143,7 @@ public: * * \param handle The native handle. */ - explicit shared_library(native_handle_t handle) + explicit shared_library(native_handle_t handle) noexcept : base_t(handle) {} @@ -153,8 +154,8 @@ public: * \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) { - boost::dll::fs::error_code ec; + shared_library& operator=(const shared_library& lib) { + std::error_code ec; assign(lib, ec); if (ec) { boost::dll::detail::report_error(ec, "boost::dll::shared_library::operator= failed"); @@ -170,7 +171,7 @@ public: * \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); } @@ -185,7 +186,7 @@ public: * * \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. @@ -195,7 +196,7 @@ public: * \param ec Variable that will be set to the result of the operation. * \throw std::bad_alloc in case of insufficient memory. */ - shared_library& assign(const shared_library& lib, boost::dll::fs::error_code& ec) { + shared_library& assign(const shared_library& lib, std::error_code& ec) { ec.clear(); if (native() == lib.native()) { @@ -229,7 +230,7 @@ public: * \throw \forcedlinkfs{system_error}, std::bad_alloc in case of insufficient memory. */ shared_library& assign(const shared_library& lib) { - boost::dll::fs::error_code ec; + std::error_code ec; assign(lib, ec); if (ec) { boost::dll::detail::report_error(ec, "boost::dll::shared_library::assign() failed"); @@ -251,7 +252,7 @@ public: * */ void load(const boost::dll::fs::path& lib_path, load_mode::type mode = load_mode::default_mode) { - boost::dll::fs::error_code ec; + std::error_code ec; base_t::load(lib_path, mode, ec); @@ -272,13 +273,13 @@ public: * \param mode A mode that will be used on library load. * \throw std::bad_alloc in case of insufficient memory. */ - void load(const boost::dll::fs::path& lib_path, boost::dll::fs::error_code& ec, load_mode::type mode = load_mode::default_mode) { + void load(const boost::dll::fs::path& lib_path, std::error_code& ec, load_mode::type mode = load_mode::default_mode) { ec.clear(); base_t::load(lib_path, mode, ec); } - //! \overload void load(const boost::dll::fs::path& lib_path, boost::dll::fs::error_code& ec, load_mode::type mode = load_mode::default_mode) - void load(const boost::dll::fs::path& lib_path, load_mode::type mode, boost::dll::fs::error_code& ec) { + //! \overload void load(const boost::dll::fs::path& lib_path, std::error_code& ec, load_mode::type mode = load_mode::default_mode) + void load(const boost::dll::fs::path& lib_path, load_mode::type mode, std::error_code& ec) { ec.clear(); base_t::load(lib_path, mode, ec); } @@ -291,7 +292,7 @@ public: * \post this->is_loaded() returns false. * \throw Nothing. */ - void unload() BOOST_NOEXCEPT { + void unload() noexcept { base_t::unload(); } @@ -301,27 +302,19 @@ public: * \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. @@ -330,13 +323,13 @@ public: * \return `true` if the loaded library contains a symbol with a given name. * \throw Nothing. */ - bool has(const char* symbol_name) const BOOST_NOEXCEPT { - boost::dll::fs::error_code ec; + bool has(const char* symbol_name) const noexcept { + std::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()); } @@ -357,19 +350,19 @@ public: * \throw \forcedlinkfs{system_error} if symbol does not exist or if the DLL/DSO was not loaded. */ template - inline typename boost::enable_if_c::value || boost::is_reference::value, T>::type get(const std::string& symbol_name) const { + inline typename std::enable_if::value || std::is_reference::value, T>::type get(const std::string& symbol_name) const { return get(symbol_name.c_str()); } //! \overload T& get(const std::string& symbol_name) const template - inline typename boost::disable_if_c::value || boost::is_reference::value, T&>::type get(const std::string& symbol_name) const { + inline typename std::enable_if::value || std::is_reference::value), T&>::type get(const std::string& symbol_name) const { return get(symbol_name.c_str()); } //! \overload T& get(const std::string& symbol_name) const template - inline typename boost::enable_if_c::value || boost::is_reference::value, T>::type get(const char* symbol_name) const { + inline typename std::enable_if::value || std::is_reference::value, T>::type get(const char* symbol_name) const { return boost::dll::detail::aggressive_ptr_cast( get_void(symbol_name) ); @@ -377,7 +370,7 @@ public: //! \overload T& get(const std::string& symbol_name) const template - inline typename boost::disable_if_c::value || boost::is_reference::value, T&>::type get(const char* symbol_name) const { + inline typename std::enable_if::value || std::is_reference::value), T&>::type get(const char* symbol_name) const { return *boost::dll::detail::aggressive_ptr_cast( get_void(symbol_name) ); @@ -411,11 +404,11 @@ private: // get_void is required to reduce binary size: it does not depend on a template // parameter and will be instantiated only once. void* get_void(const char* sb) const { - boost::dll::fs::error_code ec; + std::error_code ec; if (!is_loaded()) { - ec = boost::dll::fs::make_error_code( - boost::dll::fs::errc::bad_file_descriptor + ec = std::make_error_code( + std::errc::bad_file_descriptor ); // report_error() calls dlsym, do not use it here! @@ -442,7 +435,7 @@ public: * * \return Platform-specific handle. */ - native_handle_t native() const BOOST_NOEXCEPT { + native_handle_t native() const noexcept { return base_t::native(); } @@ -459,10 +452,10 @@ public: * \throw \forcedlinkfs{system_error}, std::bad_alloc. */ boost::dll::fs::path location() const { - boost::dll::fs::error_code ec; + std::error_code ec; if (!is_loaded()) { - ec = boost::dll::fs::make_error_code( - boost::dll::fs::errc::bad_file_descriptor + ec = std::make_error_code( + std::errc::bad_file_descriptor ); boost::throw_exception( @@ -494,10 +487,10 @@ public: * \return Full path to the shared library. * \throw std::bad_alloc. */ - boost::dll::fs::path location(boost::dll::fs::error_code& ec) const { + boost::dll::fs::path location(std::error_code& ec) const { if (!is_loaded()) { - ec = boost::dll::fs::make_error_code( - boost::dll::fs::errc::bad_file_descriptor + ec = std::make_error_code( + std::errc::bad_file_descriptor ); return boost::dll::fs::path(); @@ -546,7 +539,7 @@ public: * \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); } }; @@ -554,22 +547,22 @@ public: /// 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/shared_library_load_mode.hpp b/include/boost/dll/shared_library_load_mode.hpp index c47ab54..b92084e 100644 --- a/include/boost/dll/shared_library_load_mode.hpp +++ b/include/boost/dll/shared_library_load_mode.hpp @@ -207,37 +207,37 @@ enum type { /// Free operators for load_mode::type flag manipulation. -BOOST_CONSTEXPR inline type operator|(type left, type right) BOOST_NOEXCEPT { +BOOST_CONSTEXPR inline type operator|(type left, type right) noexcept { return static_cast( static_cast(left) | static_cast(right) ); } -BOOST_CXX14_CONSTEXPR inline type& operator|=(type& left, type right) BOOST_NOEXCEPT { +BOOST_CXX14_CONSTEXPR inline type& operator|=(type& left, type right) noexcept { left = left | right; return left; } -BOOST_CONSTEXPR inline type operator&(type left, type right) BOOST_NOEXCEPT { +BOOST_CONSTEXPR inline type operator&(type left, type right) noexcept { return static_cast( static_cast(left) & static_cast(right) ); } -BOOST_CXX14_CONSTEXPR inline type& operator&=(type& left, type right) BOOST_NOEXCEPT { +BOOST_CXX14_CONSTEXPR inline type& operator&=(type& left, type right) noexcept { left = left & right; return left; } -BOOST_CONSTEXPR inline type operator^(type left, type right) BOOST_NOEXCEPT { +BOOST_CONSTEXPR inline type operator^(type left, type right) noexcept { return static_cast( static_cast(left) ^ static_cast(right) ); } -BOOST_CXX14_CONSTEXPR inline type& operator^=(type& left, type right) BOOST_NOEXCEPT { +BOOST_CXX14_CONSTEXPR inline type& operator^=(type& left, type right) noexcept { left = left ^ right; return left; } -BOOST_CONSTEXPR inline type operator~(type left) BOOST_NOEXCEPT { +BOOST_CONSTEXPR inline type operator~(type left) noexcept { return static_cast( ~static_cast(left) ); diff --git a/include/boost/dll/smart_library.hpp b/include/boost/dll/smart_library.hpp index 1f02843..0e2bce0 100644 --- a/include/boost/dll/smart_library.hpp +++ b/include/boost/dll/smart_library.hpp @@ -9,7 +9,7 @@ #define BOOST_DLL_SMART_LIBRARY_HPP_ /// \file boost/dll/smart_library.hpp -/// \warning Extremely experimental! Requires C++11! Will change in next version of Boost! boost/dll/smart_library.hpp is not included in boost/dll.hpp +/// \warning Extremely experimental! May change in next version of Boost! boost/dll/smart_library.hpp is not included in boost/dll.hpp /// \brief Contains the boost::dll::experimental::smart_library class for loading mangled symbols. #include @@ -27,11 +27,9 @@ #include #include #include -#include -#include -#include - +#include +#include // std::move namespace boost { namespace dll { @@ -53,10 +51,10 @@ using boost::dll::detail::destructor; * Member functions must be defined outside of the class to be exported. That is: * \code * //not exported: -* struct BOOST_SYMBOL_EXPORT my_class { void func() {}}; +* struct BOOST_SYMBOL_EXPORT my_class { void func() {} }; * //exported -* struct BOOST_SYMBOL_EXPORT my_class { void func();}; -* void my_class::func() {}; +* struct BOOST_SYMBOL_EXPORT my_class { void func(); }; +* void my_class::func() {} * \endcode * * With the current analysis, the first version does get exported in MSVC. @@ -72,14 +70,14 @@ using boost::dll::detail::destructor; * This does however not happen when the value is set inside the constructor function. */ class smart_library { - shared_library _lib; - detail::mangled_storage_impl _storage; + shared_library lib_; + detail::mangled_storage_impl storage_; public: /*! * Get the underlying shared_library */ - const shared_library &shared_lib() const {return _lib;} + const shared_library &shared_lib() const noexcept { return lib_;} using mangled_storage = detail::mangled_storage_impl; /*! @@ -87,18 +85,18 @@ public: * * \throw Nothing. */ - const mangled_storage &symbol_storage() const {return _storage;} + const mangled_storage &symbol_storage() const noexcept { return storage_; } ///Overload, for current development. - mangled_storage &symbol_storage() {return _storage;} + mangled_storage &symbol_storage() noexcept { return storage_; } //! \copydoc shared_library::shared_library() - smart_library() BOOST_NOEXCEPT {}; + smart_library() = default; //! \copydoc shared_library::shared_library(const boost::dll::fs::path& lib_path, load_mode::type mode = load_mode::default_mode) smart_library(const boost::dll::fs::path& lib_path, load_mode::type mode = load_mode::default_mode) { - _lib.load(lib_path, mode); - _storage.load(lib_path); + lib_.load(lib_path, mode); + storage_.load(lib_path); } //! \copydoc shared_library::shared_library(const boost::dll::fs::path& lib_path, boost::dll::fs::error_code& ec, load_mode::type mode = load_mode::default_mode) @@ -117,9 +115,7 @@ public: * * \throw Nothing. */ - smart_library(const smart_library & lib) BOOST_NOEXCEPT - : _lib(lib._lib), _storage(lib._storage) - {} + smart_library(const smart_library & lib) = default; /*! * Move a smart_library object. * @@ -127,9 +123,7 @@ public: * * \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) = default; /*! * Construct from a shared_library object. @@ -138,10 +132,10 @@ public: * * \throw Nothing. */ - explicit smart_library(const shared_library & lib) BOOST_NOEXCEPT - : _lib(lib) + explicit smart_library(const shared_library & lib) noexcept + : lib_(lib) { - _storage.load(lib.location()); + storage_.load(lib.location()); } /*! * Construct from a shared_library object. @@ -150,10 +144,10 @@ public: * * \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) noexcept + : lib_(std::move(lib)) { - _storage.load(lib.location()); + storage_.load(lib.location()); } /*! @@ -164,13 +158,13 @@ public: * * \throw Nothing. */ - ~smart_library() BOOST_NOEXCEPT {}; + ~smart_library() = default; //! \copydoc shared_library::load(const boost::dll::fs::path& lib_path, load_mode::type mode = load_mode::default_mode) void load(const boost::dll::fs::path& lib_path, load_mode::type mode = load_mode::default_mode) { boost::dll::fs::error_code ec; - _storage.load(lib_path); - _lib.load(lib_path, mode, ec); + storage_.load(lib_path); + lib_.load(lib_path, mode, ec); if (ec) { boost::dll::detail::report_error(ec, "load() failed"); @@ -180,15 +174,15 @@ public: //! \copydoc shared_library::load(const boost::dll::fs::path& lib_path, boost::dll::fs::error_code& ec, load_mode::type mode = load_mode::default_mode) void load(const boost::dll::fs::path& lib_path, boost::dll::fs::error_code& ec, load_mode::type mode = load_mode::default_mode) { ec.clear(); - _storage.load(lib_path); - _lib.load(lib_path, mode, ec); + storage_.load(lib_path); + lib_.load(lib_path, mode, ec); } //! \copydoc shared_library::load(const boost::dll::fs::path& lib_path, load_mode::type mode, boost::dll::fs::error_code& ec) void load(const boost::dll::fs::path& lib_path, load_mode::type mode, boost::dll::fs::error_code& ec) { ec.clear(); - _storage.load(lib_path); - _lib.load(lib_path, mode, ec); + storage_.load(lib_path); + lib_.load(lib_path, mode, ec); } /*! @@ -206,7 +200,7 @@ public: */ template T& get_variable(const std::string &name) const { - return _lib.get(_storage.get_variable(name)); + return lib_.get(storage_.get_variable(name)); } /*! @@ -232,7 +226,7 @@ public: */ template Func& get_function(const std::string &name) const { - return _lib.get(_storage.get_function(name)); + return lib_.get(storage_.get_function(name)); } /*! @@ -261,8 +255,8 @@ public: */ template typename boost::dll::detail::get_mem_fn_type::mem_fn get_mem_fn(const std::string& name) const { - return _lib.get::mem_fn>( - _storage.get_mem_fn(name) + return lib_.get::mem_fn>( + storage_.get_mem_fn(name) ); } @@ -284,7 +278,7 @@ public: */ template constructor get_constructor() const { - return boost::dll::detail::load_ctor(_lib, _storage.get_constructor()); + return boost::dll::detail::load_ctor(lib_, storage_.get_constructor()); } /*! @@ -306,7 +300,7 @@ public: */ template destructor get_destructor() const { - return boost::dll::detail::load_dtor(_lib, _storage.get_destructor()); + return boost::dll::detail::load_dtor(lib_, storage_.get_destructor()); } /*! * Load the typeinfo of the given type. @@ -328,7 +322,7 @@ public: template const std::type_info& get_type_info() const { - return boost::dll::detail::load_type_info(_lib, _storage); + return boost::dll::detail::load_type_info(lib_, storage_); } /** * This function can be used to add a type alias. @@ -352,69 +346,66 @@ public: * \warning The alias will only be applied for the type signature, it will not replace the token in the scoped name. */ template void add_type_alias(const std::string& name) { - this->_storage.add_alias(name); + this->storage_.add_alias(name); } //! \copydoc shared_library::unload() - void unload() BOOST_NOEXCEPT { - _storage.clear(); - _lib.unload(); + void unload() noexcept { + storage_.clear(); + lib_.unload(); } //! \copydoc shared_library::is_loaded() const - bool is_loaded() const BOOST_NOEXCEPT { - return _lib.is_loaded(); - } - - //! \copydoc shared_library::operator!() const - bool operator!() const BOOST_NOEXCEPT { - return !is_loaded(); + bool is_loaded() const noexcept { + return lib_.is_loaded(); } //! \copydoc shared_library::operator bool() const - BOOST_EXPLICIT_OPERATOR_BOOL() + explicit operator bool() const noexcept { + return is_loaded(); + } //! \copydoc shared_library::has(const char* symbol_name) const - bool has(const char* symbol_name) const BOOST_NOEXCEPT { - return _lib.has(symbol_name); + bool has(const char* symbol_name) const noexcept { + return lib_.has(symbol_name); } //! \copydoc shared_library::has(const std::string& symbol_name) const - bool has(const std::string& symbol_name) const BOOST_NOEXCEPT { - return _lib.has(symbol_name); + bool has(const std::string& symbol_name) const noexcept { + return lib_.has(symbol_name); } //! \copydoc shared_library::assign(const shared_library& lib) smart_library& assign(const smart_library& lib) { - _lib.assign(lib._lib); - _storage.assign(lib._storage); + lib_.assign(lib.lib_); + storage_.assign(lib.storage_); return *this; } //! \copydoc shared_library::swap(shared_library& rhs) - void swap(smart_library& rhs) BOOST_NOEXCEPT { - _lib.swap(rhs._lib); - _storage.swap(rhs._storage); + void swap(smart_library& rhs) noexcept { + lib_.swap(rhs.lib_); + storage_.swap(rhs.storage_); } }; /// Very fast equality check that compares the actual DLL/DSO objects. Throws nothing. -inline bool operator==(const smart_library& lhs, const smart_library& rhs) BOOST_NOEXCEPT { +inline bool operator==(const smart_library& lhs, const smart_library& rhs) noexcept { return lhs.shared_lib().native() == rhs.shared_lib().native(); } /// Very fast inequality check that compares the actual DLL/DSO objects. Throws nothing. -inline bool operator!=(const smart_library& lhs, const smart_library& rhs) BOOST_NOEXCEPT { +inline bool operator!=(const smart_library& lhs, const smart_library& rhs) noexcept { return lhs.shared_lib().native() != rhs.shared_lib().native(); } /// Compare the actual DLL/DSO objects without any guarantee to be stable between runs. Throws nothing. -inline bool operator<(const smart_library& lhs, const smart_library& rhs) BOOST_NOEXCEPT { +inline bool operator<(const smart_library& lhs, const smart_library& rhs) noexcept { return lhs.shared_lib().native() < rhs.shared_lib().native(); } /// Swaps two shared libraries. Does not invalidate symbols and functions loaded from libraries. Throws nothing. -inline void swap(smart_library& lhs, smart_library& rhs) BOOST_NOEXCEPT { +inline void swap(smart_library& lhs, smart_library& rhs) noexcept { lhs.swap(rhs); } @@ -439,14 +430,14 @@ void get(const smart_library& sm, const std::string &name); #endif template -typename boost::enable_if, T&>::type get(const smart_library& sm, const std::string &name) +typename std::enable_if::value, T&>::type get(const smart_library& sm, const std::string &name) { return sm.get_variable(name); } template -typename boost::enable_if, T&>::type get(const smart_library& sm, const std::string &name) +typename std::enable_if::value, T&>::type get(const smart_library& sm, const std::string &name) { return sm.get_function(name); } diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 692422e..5779e7b 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -99,6 +99,7 @@ project [ compile-fail section_name_too_big.cpp ] [ run shared_library_concurrent_load_test.cpp /boost/thread//boost_thread : : library1 library2 my_plugin_aggregator refcounting_plugin : shared ] [ run cpp_mangle_test.cpp : : cpp_plugin ] + [ run cpp_mangling.cpp ] [ run cpp_load_test.cpp : : cpp_plugin ] [ run cpp_import_test.cpp : : cpp_plugin ] [ run template_method_linux_test.cpp : : cpp_plugin ] diff --git a/test/appveyor.yml b/test/appveyor.yml index d8bc70f..ef54c27 100644 --- a/test/appveyor.yml +++ b/test/appveyor.yml @@ -21,7 +21,7 @@ init: # From this point and below code is same for all the Boost libs ############################################################################################################### -version: 1.64.{build}-{branch} +version: 1.87.{build}-{branch} # branches to build branches: @@ -63,10 +63,11 @@ environment: # ADDPATH: C:\cygwin64\bin; # TOOLSET: gcc # CXXSTD: 11,14,1z - - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 - ADDPATH: C:\mingw\bin; - TOOLSET: gcc - CXXSTD: 11,14,1z + # MinGW 32 bit is not supported by boost system any more + #- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 + # ADDPATH: C:\mingw\bin; + # TOOLSET: gcc + # CXXSTD: 11,14,1z - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 ADDPATH: C:\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev1\mingw64\bin; TOOLSET: gcc diff --git a/test/cpp_ctti_type_name_parser_lib.cpp b/test/cpp_ctti_type_name_parser_lib.cpp index 392f078..eac7f4b 100644 --- a/test/cpp_ctti_type_name_parser_lib.cpp +++ b/test/cpp_ctti_type_name_parser_lib.cpp @@ -8,8 +8,6 @@ #include -#if (__cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L) - #include #include @@ -138,4 +136,3 @@ cpp_plugin_type_pasrser::type_test( {} } // namespace space -#endif diff --git a/test/cpp_import_class_test.cpp b/test/cpp_import_class_test.cpp index 97a79a5..f4af84d 100644 --- a/test/cpp_import_class_test.cpp +++ b/test/cpp_import_class_test.cpp @@ -9,8 +9,6 @@ #include -#if (__cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L) - #include "../example/b2_workarounds.hpp" #include @@ -24,7 +22,7 @@ using namespace std; #include #include #include -#include +#include #define L cout << __LINE__ << endl; @@ -92,7 +90,7 @@ int main(int argc, char* argv[]) BOOST_TEST((cl->*fun2)(5 ,2 ) == 7 ); //test if it binds. - boost::function mem_fn_obj = func; + std::function mem_fn_obj = func; const std::type_info & ti = cl.get_type_info(); @@ -109,7 +107,3 @@ int main(int argc, char* argv[]) return boost::report_errors(); } - -#else -int main() {return 0;} -#endif diff --git a/test/cpp_import_test.cpp b/test/cpp_import_test.cpp index a32df87..a6f4002 100644 --- a/test/cpp_import_test.cpp +++ b/test/cpp_import_test.cpp @@ -8,8 +8,6 @@ #include -#if (__cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L) - #include "../example/b2_workarounds.hpp" #include @@ -18,8 +16,8 @@ #include #include #include -#include +#include #include struct override_class @@ -51,7 +49,7 @@ int main(int argc, char* argv[]) ovl(5.0); BOOST_TEST(*sp_variable == 5.0); - boost::function f_test = ovl;//test if it binds + std::function f_test = ovl;//test if it binds f_test(-2); BOOST_TEST(*unscoped_var == -2); @@ -76,6 +74,3 @@ int main(int argc, char* argv[]) return boost::report_errors(); } -#else -int main() {return 0;} -#endif diff --git a/test/cpp_load_test.cpp b/test/cpp_load_test.cpp index b073107..ad11548 100644 --- a/test/cpp_load_test.cpp +++ b/test/cpp_load_test.cpp @@ -10,12 +10,7 @@ #include #include -#if (__cplusplus >= 201103L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201103L) -// Make sure that it at least compiles # include -#endif - -#if (__cplusplus >= 201402L) || (BOOST_COMP_MSVC >= BOOST_VERSION_NUMBER(14,0,0)) #include "../example/b2_workarounds.hpp" @@ -231,7 +226,3 @@ int main(int argc, char* argv[]) std::cerr << 28 << ' '; return boost::report_errors(); } - -#else -int main() {return 0;} -#endif diff --git a/test/cpp_mangle_test.cpp b/test/cpp_mangle_test.cpp index 9c4b54b..c7eb614 100644 --- a/test/cpp_mangle_test.cpp +++ b/test/cpp_mangle_test.cpp @@ -8,8 +8,6 @@ #include -#if (__cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L) - #include "../example/b2_workarounds.hpp" #include @@ -128,6 +126,3 @@ int main(int argc, char* argv[]) return boost::report_errors(); } -#else -int main() {return 0;} -#endif diff --git a/test/cpp_mangling.cpp b/test/cpp_mangling.cpp new file mode 100644 index 0000000..949679b --- /dev/null +++ b/test/cpp_mangling.cpp @@ -0,0 +1,155 @@ +// Copyright 2024 Antony Polukhin +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + +// For more information, see http://www.boost.org + +#include + +#include + +int main() { + namespace parser = boost::dll::detail::parser; + + BOOST_TEST(parser::is_destructor_with_name("foo::~foo(void)")("public: __cdecl foo::~foo(void)")); + BOOST_TEST(parser::is_destructor_with_name("foo::~foo(void)")("private: __cdecl foo::~foo(void)")); + BOOST_TEST(parser::is_destructor_with_name("foo::~foo(void)")("protected: __cdecl foo::~foo(void)")); + + BOOST_TEST(parser::is_destructor_with_name("foo::~foo(void)")("public: virtual __cdecl foo::~foo(void)")); + BOOST_TEST(parser::is_destructor_with_name("foo::~foo(void)")("private: virtual __cdecl foo::~foo(void)")); + BOOST_TEST(parser::is_destructor_with_name("foo::~foo(void)")("protected: virtual __cdecl foo::~foo(void)")); + + BOOST_TEST(parser::is_destructor_with_name("foo::~foo(void)")("public: __cdecl foo::~foo(void) __ptr64")); + BOOST_TEST(parser::is_destructor_with_name("foo::~foo(void)")("private: __cdecl foo::~foo(void) __ptr64")); + BOOST_TEST(parser::is_destructor_with_name("foo::~foo(void)")("protected: __cdecl foo::~foo(void) __ptr64")); + + BOOST_TEST(parser::is_destructor_with_name("some_space::some_father::~some_father(void)")("public: __cdecl some_space::some_father::~some_father(void) __ptr64")); + + BOOST_TEST(parser::is_destructor_with_name("foo::~foo(void)")("public: __thiscall foo::~foo(void)")); + BOOST_TEST(parser::is_destructor_with_name("foo::~foo(void)")("private: __thiscall foo::~foo(void)")); + BOOST_TEST(parser::is_destructor_with_name("foo::~foo(void)")("protected: __thiscall foo::~foo(void)")); + + BOOST_TEST(parser::is_destructor_with_name("foo::~foo(void)")("public: virtual __thiscall foo::~foo(void)")); + BOOST_TEST(parser::is_destructor_with_name("foo::~foo(void)")("private: virtual __thiscall foo::~foo(void)")); + BOOST_TEST(parser::is_destructor_with_name("foo::~foo(void)")("protected: virtual __thiscall foo::~foo(void)")); + + BOOST_TEST(parser::is_destructor_with_name("foo::~foo(void)")("public: __thiscall foo::~foo(void) __ptr32")); + BOOST_TEST(parser::is_destructor_with_name("foo::~foo(void)")("private: __thiscall foo::~foo(void) __ptr32")); + BOOST_TEST(parser::is_destructor_with_name("foo::~foo(void)")("protected: __thiscall foo::~foo(void) __ptr32")); + + BOOST_TEST(parser::is_destructor_with_name("some_space::some_father::~some_father(void)")("public: __thiscall some_space::some_father::~some_father(void) __ptr64")); + + + boost::dll::detail::mangled_storage_impl ms; + { + void(*ptr0)(int) = nullptr; + boost::core::string_view s = "integer"; + BOOST_TEST(parser::try_consume_arg_list(s, ms, ptr0)); + BOOST_TEST_EQ(s, "eger"); + } + { + void(*ptr1)(int) = nullptr; + boost::core::string_view s = "int"; + BOOST_TEST(parser::try_consume_arg_list(s, ms, ptr1)); + BOOST_TEST(s.empty()); + } + { + void(*ptr2)() = nullptr; + boost::core::string_view s = "void"; + BOOST_TEST(parser::try_consume_arg_list(s, ms, ptr2)); + BOOST_TEST(s.empty()); + } + { + void(*ptr3)(int,int) = nullptr; + boost::core::string_view s = "int,int"; + BOOST_TEST(parser::try_consume_arg_list(s, ms, ptr3)); + BOOST_TEST(s.empty()); + } + { + void(*ptr4)(int,int,int) = nullptr; + boost::core::string_view s = "int,int,int"; + BOOST_TEST(parser::try_consume_arg_list(s, ms, ptr4)); + BOOST_TEST(s.empty()); + } + + + BOOST_TEST(( + parser::is_constructor_with_name("some_space::some_class::some_class", ms) + ("public: __cdecl some_space::some_class::some_class(void) __ptr64") + )); + BOOST_TEST(( + parser::is_constructor_with_name("some_space::some_class::some_class", ms) + ("private: __cdecl some_space::some_class::some_class(int)") + )); + BOOST_TEST(( + parser::is_constructor_with_name("some_space::some_class::some_class", ms) + ("private: __cdecl some_space::some_class::some_class(int,int)") + )); + + + BOOST_TEST(( + parser::is_variable_with_name("some_space::some_class::value", ms) + ("public: static int some_space::some_class::value") + )); + + BOOST_TEST(( + parser::is_variable_with_name("some_space::some_class::value", ms) + ("int some_space::some_class::value") + )); + + BOOST_TEST(( + parser::is_variable_with_name("some_space::variable", ms) + ("public: static double some_space::variable") + )); + + BOOST_TEST(( + !parser::is_variable_with_name("some_space::variable", ms) + ("public: static int some_space::variable_that_is_not_exist") + )); + + BOOST_TEST(( + parser::is_variable_with_name("unscoped_c_var", ms) + ("double const unscoped_c_var") + )); + + + BOOST_TEST(( + parser::is_function_with_name("overloaded", ms) + ("void __cdecl overloaded(int)") + )); + + BOOST_TEST(( + parser::is_function_with_name("overloaded", ms) + ("void __cdecl overloaded(double)") + )); + + BOOST_TEST(( + parser::is_function_with_name("some_space::scoped_fun", ms) + ("int const & __ptr64 __cdecl some_space::scoped_fun(void)") + )); + + + BOOST_TEST(( + parser::is_mem_fn_with_name("func", ms) + ("public: int __thiscall int::func(int,int)volatile ") + )); + BOOST_TEST(( + parser::is_mem_fn_with_name("func", ms) + ("private: double __thiscall int::func(double)const volatile ") + )); + + BOOST_TEST(( + parser::is_mem_fn_with_name("func", ms) + ("public: int __cdecl int::func(int,int)volatile __ptr64") + )); + + BOOST_TEST(( + parser::is_mem_fn_with_name("func", ms) + ("public: virtual int __cdecl int::func(int,int)volatile __ptr64") + )); + + return boost::report_errors(); +} + diff --git a/test/cpp_test_library.cpp b/test/cpp_test_library.cpp index f0bebeb..d8b37f3 100644 --- a/test/cpp_test_library.cpp +++ b/test/cpp_test_library.cpp @@ -9,8 +9,6 @@ #include -#if (__cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L) - #include #include @@ -198,6 +196,3 @@ namespace space { template BOOST_SYMBOL_EXPORT int my_plugin::Func2<::space::my_plugin>(); template BOOST_SYMBOL_EXPORT int my_plugin::AFunc<::space::my_plugin>(); } - - -#endif diff --git a/test/ctti_type_name_parser_test.cpp b/test/ctti_type_name_parser_test.cpp index d374608..ea5a89f 100644 --- a/test/ctti_type_name_parser_test.cpp +++ b/test/ctti_type_name_parser_test.cpp @@ -8,7 +8,6 @@ #include -#if (__cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L) #include "../example/b2_workarounds.hpp" #include @@ -165,10 +164,3 @@ main(int argc, char* argv[]) return boost::report_errors(); } -#else -int -main() -{ - return 0; -} -#endif diff --git a/test/library_info_test.cpp b/test/library_info_test.cpp index eeec29e..57f4b17 100644 --- a/test/library_info_test.cpp +++ b/test/library_info_test.cpp @@ -39,7 +39,8 @@ int main(int argc, char* argv[]) #if defined(__GNUC__) && __GNUC__ >= 4 && defined(__ELF__) BOOST_TEST(std::find(symb.begin(), symb.end(), "protected_function") != symb.end()); #endif - + + std::cout << "\n\n'boostdll' symbols:\n"; symb = lib_info.symbols("boostdll"); std::copy(symb.begin(), symb.end(), std::ostream_iterator(std::cout, "\n")); BOOST_TEST(std::find(symb.begin(), symb.end(), "const_integer_g_alias") != symb.end()); @@ -48,6 +49,7 @@ int main(int argc, char* argv[]) BOOST_TEST(std::find(symb.begin(), symb.end(), "say_hello") == symb.end()); BOOST_TEST(lib_info.symbols(std::string("boostdll")) == symb); + std::cout << "\n\n'empty' symbols:\n"; std::vector empty = lib_info.symbols("empty"); BOOST_TEST(empty.empty() == true); diff --git a/test/link.hpp b/test/link.hpp index de03d24..6d05e4f 100644 --- a/test/link.hpp +++ b/test/link.hpp @@ -9,13 +9,8 @@ #include -#if (__cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L) - #include #include #include -#endif - - #include diff --git a/test/shared_library_errors.cpp b/test/shared_library_errors.cpp index b5f532c..5fce7f4 100644 --- a/test/shared_library_errors.cpp +++ b/test/shared_library_errors.cpp @@ -12,7 +12,6 @@ #include #include #include -#include // Unit Tests diff --git a/test/shared_library_get_symbol_test.cpp b/test/shared_library_get_symbol_test.cpp index 091e989..a45c897 100644 --- a/test/shared_library_get_symbol_test.cpp +++ b/test/shared_library_get_symbol_test.cpp @@ -11,7 +11,7 @@ #include "../example/b2_workarounds.hpp" #include #include -#include +#include #include // lib functions @@ -35,7 +35,7 @@ void refcountable_test(boost::dll::fs::path shared_library_path) { std::vector v(1000); { - boost::function sz2 + std::function sz2 = import_symbol(shared_library_path, "say_hello"); sz2(); @@ -52,17 +52,17 @@ void refcountable_test(boost::dll::fs::path shared_library_path) { #endif { - boost::function&)> sz + std::function&)> sz = import_alias&)>(shared_library_path, "foo_bar"); BOOST_TEST(sz(v) == 1000); } { - boost::function f; + std::function f; { - boost::function f2 = import_alias(shared_library_path, "do_share"); + std::function f2 = import_alias(shared_library_path, "do_share"); f = f2; } @@ -91,13 +91,13 @@ void refcountable_test(boost::dll::fs::path shared_library_path) { } { - boost::function f = import_alias(shared_library_path, "ref_returning_function"); + std::function f = import_alias(shared_library_path, "ref_returning_function"); BOOST_TEST(f() == 0); f() = 10; BOOST_TEST(f() == 10); - boost::function f1 = import_alias(shared_library_path, "ref_returning_function"); + std::function f1 = import_alias(shared_library_path, "ref_returning_function"); BOOST_TEST(f1() == 10); f1() += 10; @@ -157,7 +157,7 @@ int main(int argc, char* argv[]) { BOOST_TEST(sl.get("const_integer_g") == 777); - boost::function inc = sl.get("increment"); + std::function inc = sl.get("increment"); BOOST_TEST(inc(1) == 2); BOOST_TEST(inc(2) == 3); BOOST_TEST(inc(3) == 4); @@ -170,7 +170,7 @@ int main(int argc, char* argv[]) { // Checking aliases - boost::function&)> sz + std::function&)> sz = sl.get_alias&)>("foo_bar"); std::vector v(10); diff --git a/test/shared_library_load_test.cpp b/test/shared_library_load_test.cpp index 7309d29..ca22c7d 100644 --- a/test/shared_library_load_test.cpp +++ b/test/shared_library_load_test.cpp @@ -9,6 +9,11 @@ #include "../example/b2_workarounds.hpp" #include + +#include +#include +#include + #include // Unit Tests @@ -403,7 +408,8 @@ int main(int argc, char* argv[]) std::cout << "\nLibrary location: " << sl.location(); BOOST_TEST( boost::dll::fs::equivalent(sl.location(), program_location()) ); - boost::dll::fs::error_code ec; + // Make sure that works with boost::system::error_code + boost::system::error_code ec; shared_library sl2(program_location()); BOOST_TEST(sl2.is_loaded()); BOOST_TEST( boost::dll::fs::equivalent(sl2.location(), program_location()) ); @@ -478,7 +484,7 @@ int main(int argc, char* argv[]) { // error_code load calls test - boost::dll::fs::error_code ec; + std::error_code ec; shared_library sl(shared_library_path / "dir_that_does_not_exist", ec); BOOST_TEST(ec); BOOST_TEST(!sl.is_loaded()); @@ -512,6 +518,75 @@ int main(int argc, char* argv[]) BOOST_TEST(!sl); } + { // error_code load calls test + std::error_code ec; // make sure that works with std::error_code + shared_library sl(shared_library_path / "dir_that_does_not_exist", ec); + BOOST_TEST(ec); + BOOST_TEST(!sl.is_loaded()); + BOOST_TEST(!sl); + + boost::dll::fs::path bad_path(shared_library_path); + bad_path += ".1.1.1.1.1.1"; + sl.load(bad_path, ec); + BOOST_TEST(ec); + BOOST_TEST(!sl.is_loaded()); + BOOST_TEST(!sl); + + sl.load(shared_library_path, ec); + BOOST_TEST(!ec); + BOOST_TEST(sl.is_loaded()); + BOOST_TEST(sl); + + shared_library sl2(bad_path, ec); + BOOST_TEST(ec); + BOOST_TEST(!sl2.is_loaded()); + BOOST_TEST(!sl2); + + shared_library sl3(shared_library_path, ec); + BOOST_TEST(!ec); + BOOST_TEST(sl3.is_loaded()); + BOOST_TEST(sl3); + + sl.load("", ec); + BOOST_TEST(ec); + BOOST_TEST(!sl.is_loaded()); + BOOST_TEST(!sl); + } + + { // error_code load calls test + boost::system::error_code ec; // make sure that works with boost::system::error_code + shared_library sl(shared_library_path / "dir_that_does_not_exist", ec); + BOOST_TEST(ec); + BOOST_TEST(!sl.is_loaded()); + BOOST_TEST(!sl); + + boost::dll::fs::path bad_path(shared_library_path); + bad_path += ".1.1.1.1.1.1"; + sl.load(bad_path, ec); + BOOST_TEST(ec); + BOOST_TEST(!sl.is_loaded()); + BOOST_TEST(!sl); + + sl.load(shared_library_path, ec); + BOOST_TEST(!ec); + BOOST_TEST(sl.is_loaded()); + BOOST_TEST(sl); + + shared_library sl2(bad_path, ec); + BOOST_TEST(ec); + BOOST_TEST(!sl2.is_loaded()); + BOOST_TEST(!sl2); + + shared_library sl3(shared_library_path, ec); + BOOST_TEST(!ec); + BOOST_TEST(sl3.is_loaded()); + BOOST_TEST(sl3); + + sl.load("", ec); + BOOST_TEST(ec); + BOOST_TEST(!sl.is_loaded()); + BOOST_TEST(!sl); + } shared_library_path = do_find_correct_libs_path(argc, argv, "library1"); fs_copy_guard guard(shared_library_path); diff --git a/test/template_method_linux_test.cpp b/test/template_method_linux_test.cpp index 8dde1f6..2481cd5 100644 --- a/test/template_method_linux_test.cpp +++ b/test/template_method_linux_test.cpp @@ -6,7 +6,6 @@ // or copy at http://www.boost.org/LICENSE_1_0.txt) #include -#if (__cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L) #include #include @@ -60,8 +59,3 @@ int main(int argc, char** argv) { return boost::report_errors(); } - - -#else -int main() {} -#endif