Skip to content

Commit

Permalink
fixes and more info in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
apolukhin committed Dec 19, 2024
1 parent 51b5321 commit 7a538e0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 47 deletions.
88 changes: 42 additions & 46 deletions include/boost/dll/smart_library.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <boost/dll/config.hpp>
Expand Down Expand Up @@ -51,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.
Expand All @@ -70,33 +70,33 @@ 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;
/*!
* Access to the mangled storage, which is created on construction.
*
* \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() 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)
Expand All @@ -115,19 +115,15 @@ class smart_library {
*
* \throw Nothing.
*/
smart_library(const smart_library & lib) noexcept
: _lib(lib._lib), _storage(lib._storage)
{}
smart_library(const smart_library & lib) = default;
/*!
* Move a smart_library object.
*
* \param lib A smart_library to move from.
*
* \throw Nothing.
*/
smart_library(smart_library&& lib) noexcept
: _lib(std::move(lib._lib)), _storage(std::move(lib._storage))
{}
smart_library(smart_library&& lib) = default;

/*!
* Construct from a shared_library object.
Expand All @@ -137,9 +133,9 @@ class smart_library {
* \throw Nothing.
*/
explicit smart_library(const shared_library & lib) noexcept
: _lib(lib)
: lib_(lib)
{
_storage.load(lib.location());
storage_.load(lib.location());
}
/*!
* Construct from a shared_library object.
Expand All @@ -149,9 +145,9 @@ class smart_library {
* \throw Nothing.
*/
explicit smart_library(shared_library&& lib) noexcept
: _lib(std::move(lib))
: lib_(std::move(lib))
{
_storage.load(lib.location());
storage_.load(lib.location());
}

/*!
Expand All @@ -162,13 +158,13 @@ class smart_library {
*
* \throw Nothing.
*/
~smart_library() 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");
Expand All @@ -178,15 +174,15 @@ class smart_library {
//! \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);
}

/*!
Expand All @@ -204,7 +200,7 @@ class smart_library {
*/
template<typename T>
T& get_variable(const std::string &name) const {
return _lib.get<T>(_storage.get_variable<T>(name));
return lib_.get<T>(storage_.get_variable<T>(name));
}

/*!
Expand All @@ -230,7 +226,7 @@ class smart_library {
*/
template<typename Func>
Func& get_function(const std::string &name) const {
return _lib.get<Func>(_storage.get_function<Func>(name));
return lib_.get<Func>(storage_.get_function<Func>(name));
}

/*!
Expand Down Expand Up @@ -259,8 +255,8 @@ class smart_library {
*/
template<typename Class, typename Func>
typename boost::dll::detail::get_mem_fn_type<Class, Func>::mem_fn get_mem_fn(const std::string& name) const {
return _lib.get<typename boost::dll::detail::get_mem_fn_type<Class, Func>::mem_fn>(
_storage.get_mem_fn<Class, Func>(name)
return lib_.get<typename boost::dll::detail::get_mem_fn_type<Class, Func>::mem_fn>(
storage_.get_mem_fn<Class, Func>(name)
);
}

Expand All @@ -282,7 +278,7 @@ class smart_library {
*/
template<typename Signature>
constructor<Signature> get_constructor() const {
return boost::dll::detail::load_ctor<Signature>(_lib, _storage.get_constructor<Signature>());
return boost::dll::detail::load_ctor<Signature>(lib_, storage_.get_constructor<Signature>());
}

/*!
Expand All @@ -304,7 +300,7 @@ class smart_library {
*/
template<typename Class>
destructor<Class> get_destructor() const {
return boost::dll::detail::load_dtor<Class>(_lib, _storage.get_destructor<Class>());
return boost::dll::detail::load_dtor<Class>(lib_, storage_.get_destructor<Class>());
}
/*!
* Load the typeinfo of the given type.
Expand All @@ -326,7 +322,7 @@ class smart_library {
template<typename Class>
const std::type_info& get_type_info() const
{
return boost::dll::detail::load_type_info<Class>(_lib, _storage);
return boost::dll::detail::load_type_info<Class>(lib_, storage_);
}
/**
* This function can be used to add a type alias.
Expand All @@ -350,18 +346,18 @@ class smart_library {
* \warning The alias will only be applied for the type signature, it will not replace the token in the scoped name.
*/
template<typename Alias> void add_type_alias(const std::string& name) {
this->_storage.add_alias<Alias>(name);
this->storage_.add_alias<Alias>(name);
}

//! \copydoc shared_library::unload()
void unload() noexcept {
_storage.clear();
_lib.unload();
storage_.clear();
lib_.unload();
}

//! \copydoc shared_library::is_loaded() const
bool is_loaded() const noexcept {
return _lib.is_loaded();
return lib_.is_loaded();
}

//! \copydoc shared_library::operator bool() const
Expand All @@ -371,25 +367,25 @@ class smart_library {

//! \copydoc shared_library::has(const char* symbol_name) const
bool has(const char* symbol_name) const noexcept {
return _lib.has(symbol_name);
return lib_.has(symbol_name);
}

//! \copydoc shared_library::has(const std::string& symbol_name) const
bool has(const std::string& symbol_name) const noexcept {
return _lib.has(symbol_name);
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) noexcept {
_lib.swap(rhs._lib);
_storage.swap(rhs._storage);
lib_.swap(rhs.lib_);
storage_.swap(rhs.storage_);
}
};

Expand Down
2 changes: 1 addition & 1 deletion test/appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions test/library_info_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,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<std::string> empty = lib_info.symbols("empty");
BOOST_TEST(empty.empty() == true);

Expand Down

0 comments on commit 7a538e0

Please sign in to comment.