diff --git a/doc/Jamfile.v2 b/doc/Jamfile.v2 index d8dafc0..cd051a0 100644 --- a/doc/Jamfile.v2 +++ b/doc/Jamfile.v2 @@ -39,7 +39,7 @@ local doxygen_params = \"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=auto\" \\ + \"BOOST_DLL_IMPORT_RESULT_TYPE=result_type\" \\ \"BOOST_DLL_DOXYGEN\" " ; diff --git a/include/boost/dll/detail/elf_info.hpp b/include/boost/dll/detail/elf_info.hpp index 3241ff5..5e4fffd 100644 --- a/include/boost/dll/detail/elf_info.hpp +++ b/include/boost/dll/detail/elf_info.hpp @@ -184,7 +184,7 @@ private: const boost::filesystem::ifstream::pos_type pos = f_.tellg(); f_.seekg(section.sh_offset); - f_.read((char*)&symbols[0], section.sh_size); + f_.read((char*)&symbols[0], section.sh_size - (section.sh_size % sizeof(symbol_t)) ); f_.seekg(pos); } else if (section.sh_type == SHT_STRTAB_) { text.resize(static_cast<std::size_t>(section.sh_size)); diff --git a/include/boost/dll/import.hpp b/include/boost/dll/import.hpp index be29c28..1e024c8 100644 --- a/include/boost/dll/import.hpp +++ b/include/boost/dll/import.hpp @@ -20,7 +20,7 @@ #endif /// \file boost/dll/import_function.hpp -/// \brief Contains all the boost::dll::import_function* reference counting +/// \brief Contains all the boost::dll::import* reference counting /// functions that hold a shared pointer to the instance of /// boost::dll::shared_library. @@ -92,10 +92,10 @@ namespace detail { * boost::shared_ptr<int> i = import<int>("test_lib.so", "integer_name"); * \endcode * -* \tparam T Type of the symbol that we are going to import. Must be explicitly specified. +* \b Template \b parameter \b T: Type of the symbol that we are going to import. Must be explicitly specified. * * \param lib Path or shared pointer to library to load function from. -* \param func_name Null-terminated C or C++ mangled name of the function to import. Can handle std::string, char*, const char*. +* \param name Null-terminated C or C++ mangled name of the function to import. Can handle std::string, char*, const char*. * \param mode An mode that will be used on library load. * * \return boost::function<T> if T is a function type, or boost::shared_ptr<T> if T is an object type. @@ -104,6 +104,22 @@ namespace detail { * Overload that accepts path also throws std::bad_alloc in case of insufficient memory. */ template <class T> +BOOST_DLL_IMPORT_RESULT_TYPE import(const boost::filesystem::path& lib, const char* name, + load_mode::type mode = load_mode::default_mode); + +//! \overload boost::dll::import(const boost::filesystem::path& lib, const char* name, load_mode::type mode) +template <class T> +BOOST_DLL_IMPORT_RESULT_TYPE import(const boost::filesystem::path& lib, const std::string& name, + load_mode::type mode = load_mode::default_mode) +{ + return boost::dll::import<T>( + boost::make_shared<boost::dll::shared_library>(lib, mode), + name.c_str() + ); +} + +//! \overload boost::dll::import(const boost::filesystem::path& lib, const char* name, load_mode::type mode) +template <class T> BOOST_DLL_IMPORT_RESULT_TYPE import(const boost::shared_ptr<shared_library>& lib, const char* name) { typedef typename boost::dll::detail::import_type<T>::base_type type; return type(lib, &lib->get<T>(name)); @@ -115,8 +131,6 @@ BOOST_DLL_IMPORT_RESULT_TYPE import(const boost::shared_ptr<shared_library>& lib return boost::dll::import<T>(lib, name.c_str()); } - -//! \overload boost::dll::import(const boost::filesystem::path& lib, const char* name, load_mode::type mode) template <class T> BOOST_DLL_IMPORT_RESULT_TYPE import(const boost::filesystem::path& lib, const char* name, load_mode::type mode = load_mode::default_mode) @@ -127,17 +141,6 @@ BOOST_DLL_IMPORT_RESULT_TYPE import(const boost::filesystem::path& lib, const ch ); } -//! \overload boost::dll::import(const boost::filesystem::path& lib, const char* name, load_mode::type mode) -template <class T> -BOOST_DLL_IMPORT_RESULT_TYPE import(const boost::filesystem::path& lib, const std::string& name, - load_mode::type mode = load_mode::default_mode) -{ - return boost::dll::import<T>( - boost::make_shared<boost::dll::shared_library>(lib, mode), - name.c_str() - ); -} - @@ -168,13 +171,10 @@ BOOST_DLL_IMPORT_RESULT_TYPE import(const boost::filesystem::path& lib, const st * boost::shared_ptr<int> i = import_alias<int>("test_lib.so", "integer_alias_name"); * \endcode * -* \tparam T Type of the symbol that we are going to import. Must be explicitly specified. +* \b Template \b parameter \b T: Type of the symbol alias that we are going to import. Must be explicitly specified. * * \param lib Path or shared pointer to library to load function from. -* \param func_name Null-terminated C or C++ mangled name of the function to import. Can handle std::string, char*, const char*. -* \param variable_name Null-terminated C or C++ mangled name of the variable to import. -* Can handle std::string, char*, const char*. -* +* \param name Null-terminated C or C++ mangled name of the function or variable to import. Can handle std::string, char*, const char*. * \param mode An mode that will be used on library load. * * \return boost::function<T> if T is a function type, or boost::shared_ptr<T> if T is an object type. @@ -183,27 +183,8 @@ BOOST_DLL_IMPORT_RESULT_TYPE import(const boost::filesystem::path& lib, const st * Overload that accepts path also throws std::bad_alloc in case of insufficient memory. */ template <class T> -BOOST_DLL_IMPORT_RESULT_TYPE import_alias(const boost::shared_ptr<shared_library>& lib, const char* name) { - typedef typename boost::dll::detail::import_type<T>::base_type type; - return type(lib, lib->get<T*>(name)); -} - -//! \overload boost::dll::import_alias(const boost::filesystem::path& lib, const char* name, load_mode::type mode) -template <class T> -BOOST_DLL_IMPORT_RESULT_TYPE import_alias(const boost::shared_ptr<shared_library>& lib, const std::string& name) { - return boost::dll::import_alias<T>(lib, name.c_str()); -} - -//! \overload boost::dll::import_alias(const boost::filesystem::path& lib, const char* name, load_mode::type mode) -template <class T> BOOST_DLL_IMPORT_RESULT_TYPE import_alias(const boost::filesystem::path& lib, const char* name, - load_mode::type mode = load_mode::default_mode) -{ - return boost::dll::import_alias<T>( - boost::make_shared<boost::dll::shared_library>(lib, mode), - name - ); -} + load_mode::type mode = load_mode::default_mode); //! \overload boost::dll::import_alias(const boost::filesystem::path& lib, const char* name, load_mode::type mode) template <class T> @@ -216,9 +197,28 @@ BOOST_DLL_IMPORT_RESULT_TYPE import_alias(const boost::filesystem::path& lib, co ); } +//! \overload boost::dll::import_alias(const boost::filesystem::path& lib, const char* name, load_mode::type mode) +template <class T> +BOOST_DLL_IMPORT_RESULT_TYPE import_alias(const boost::shared_ptr<shared_library>& lib, const std::string& name) { + return boost::dll::import_alias<T>(lib, name.c_str()); +} +//! \overload boost::dll::import_alias(const boost::filesystem::path& lib, const char* name, load_mode::type mode) +template <class T> +BOOST_DLL_IMPORT_RESULT_TYPE import_alias(const boost::shared_ptr<shared_library>& lib, const char* name) { + typedef typename boost::dll::detail::import_type<T>::base_type type; + return type(lib, lib->get<T*>(name)); +} - +template <class T> +BOOST_DLL_IMPORT_RESULT_TYPE import_alias(const boost::filesystem::path& lib, const char* name, + load_mode::type mode = load_mode::default_mode) +{ + return boost::dll::import_alias<T>( + boost::make_shared<boost::dll::shared_library>(lib, mode), + name + ); +} #undef BOOST_DLL_IMPORT_RESULT_TYPE