mirror of
https://github.com/boostorg/dll.git
synced 2026-07-21 13:13:30 +00:00
smart_library correct constructors from shared_library (#114)
This commit is contained in:
@@ -151,23 +151,26 @@ public:
|
||||
*
|
||||
* \throw Nothing.
|
||||
*/
|
||||
explicit smart_library(const shared_library & lib) noexcept
|
||||
: lib_(lib)
|
||||
{
|
||||
storage_.load(lib.location());
|
||||
}
|
||||
/*!
|
||||
* Construct from a shared_library object.
|
||||
*
|
||||
* \param lib A shared_library to move from.
|
||||
*
|
||||
* \throw Nothing.
|
||||
*/
|
||||
explicit smart_library(shared_library&& lib) noexcept
|
||||
: lib_(std::move(lib))
|
||||
{
|
||||
storage_.load(lib.location());
|
||||
}
|
||||
explicit smart_library(const shared_library & lib) noexcept
|
||||
: lib_(lib) {
|
||||
if (lib_.is_loaded()) {
|
||||
storage_.load(lib_.location());
|
||||
}
|
||||
}
|
||||
/*!
|
||||
* Construct from a shared_library object.
|
||||
*
|
||||
* \param lib A shared_library to move from.
|
||||
*
|
||||
* \throw Nothing.
|
||||
*/
|
||||
explicit smart_library(shared_library&& lib) noexcept
|
||||
: lib_(std::move(lib))
|
||||
{
|
||||
if (lib_.is_loaded()) {
|
||||
storage_.load(lib_.location());
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* Destroys the smart_library.
|
||||
|
||||
@@ -116,6 +116,7 @@ boost_dll_add_test(dll_test_cpp_mangle cpp_mangle_test.cpp #[[export_symbols=]]
|
||||
target_link_libraries(dll_test_cpp_mangle PRIVATE Boost::variant)
|
||||
boost_dll_add_test(dll_test_cpp_load cpp_load_test.cpp #[[export_symbols=]] FALSE dll_cpp_plugin)
|
||||
target_link_libraries(dll_test_cpp_load PRIVATE Boost::variant)
|
||||
boost_dll_add_test(dll_test_smart_library smart_library_test.cpp #[[export_symbols=]] FALSE dll_cpp_plugin)
|
||||
boost_dll_add_test(dll_test_cpp_import cpp_import_test.cpp #[[export_symbols=]] FALSE dll_cpp_plugin)
|
||||
target_link_libraries(dll_test_cpp_import PRIVATE Boost::variant)
|
||||
if(LINUX)
|
||||
|
||||
@@ -105,6 +105,7 @@ project
|
||||
[ run cpp_mangling.cpp ]
|
||||
[ compile-fail cpp_mangling1_cf.cpp ]
|
||||
[ run cpp_load_test.cpp : : cpp_plugin ]
|
||||
[ run smart_library_test.cpp : : cpp_plugin ]
|
||||
[ run cpp_import_test.cpp : : cpp_plugin ]
|
||||
[ run template_method_linux_test.cpp : : cpp_plugin ]
|
||||
# TODO: uncomment (fails on some MSVCs and Clang-5)
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
// Copyright 2026 Roman Savchenko
|
||||
//
|
||||
// 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 <boost/config.hpp>
|
||||
#include <boost/predef.h>
|
||||
|
||||
#include "../example/b2_workarounds.hpp"
|
||||
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/dll/smart_library.hpp>
|
||||
|
||||
// Test for smart_library construction from empty/unloaded shared_library objects.
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
using namespace boost::dll;
|
||||
using namespace boost::dll::experimental;
|
||||
boost::dll::fs::path pt = b2_workarounds::first_lib_from_argv(argc, argv);
|
||||
|
||||
BOOST_TEST(!pt.empty());
|
||||
std::cout << "Library: " << pt << std::endl;
|
||||
|
||||
{
|
||||
shared_library empty_lib;
|
||||
BOOST_TEST(!empty_lib.is_loaded());
|
||||
|
||||
// Should not access location() for an unloaded library.
|
||||
smart_library sm(empty_lib);
|
||||
BOOST_TEST(!sm.is_loaded());
|
||||
}
|
||||
|
||||
{
|
||||
shared_library lib(pt);
|
||||
BOOST_TEST(lib.is_loaded());
|
||||
|
||||
shared_library moved_to = std::move(lib);
|
||||
BOOST_TEST(!lib.is_loaded());
|
||||
BOOST_TEST(moved_to.is_loaded());
|
||||
|
||||
// Should not access location() for a moved-from library.
|
||||
smart_library sm(std::move(lib));
|
||||
BOOST_TEST(!sm.is_loaded());
|
||||
}
|
||||
|
||||
{
|
||||
shared_library lib(pt);
|
||||
BOOST_TEST(lib.is_loaded());
|
||||
|
||||
smart_library sm(lib);
|
||||
BOOST_TEST(sm.is_loaded());
|
||||
}
|
||||
|
||||
{
|
||||
shared_library lib(pt);
|
||||
BOOST_TEST(lib.is_loaded());
|
||||
|
||||
smart_library sm(std::move(lib));
|
||||
BOOST_TEST(sm.is_loaded());
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
Reference in New Issue
Block a user