Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:boostorg/dll into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
apolukhin committed Dec 20, 2024
2 parents dab63b8 + 15d8fb4 commit 7cbc0d4
Show file tree
Hide file tree
Showing 53 changed files with 924 additions and 864 deletions.
4 changes: 0 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
4 changes: 0 additions & 4 deletions build.jam
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions doc/Jamfile.v2
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,8 @@ local doxygen_params =
\"forcedlinkfs{1}=\\xmlonly<link linkend='boost.dll.fs.\\1'>boost::dll::fs::\\1</link>\\endxmlonly\" \\
\"forcedmacrolink{1}=\\xmlonly<link linkend='\\1'>\\1</link>\\endxmlonly\" "
<doxygen:param>"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\" "
;

Expand Down
3 changes: 1 addition & 2 deletions doc/dependencies.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion doc/getting_started.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -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<const int>("integer_variable");
boost::function<int()> f = lib.get<int()>("function_returning_int");
auto function_ptr = lib.get<int()>("function_returning_int");
int& i = lib.get_alias<int>("alias_to_int_variable");
```
In case of `boost::dll::shared_library` it is safe to use imported symbols only until `boost::dll::shared_library`
Expand Down
5 changes: 2 additions & 3 deletions example/tutorial2/tutorial2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<my_plugin_api> (pluginapi_create_t)();
boost::function<pluginapi_create_t> creator;

creator = boost::dll::import_alias<pluginapi_create_t>( // type of imported symbol must be explicitly specified
using pluginapi_create_t = boost::shared_ptr<my_plugin_api>();
auto creator = boost::dll::import_alias<pluginapi_create_t>( // 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
Expand Down
7 changes: 4 additions & 3 deletions example/tutorial3/tutorial3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ std::size_t search_for_symbols(const std::vector<boost::dll::fs::path>& plugins)
}

// library has symbol, importing...
typedef boost::shared_ptr<my_plugin_api> (pluginapi_create_t)();
boost::function<pluginapi_create_t> creator
= dll::import_alias<pluginapi_create_t>(boost::move(lib), "create_plugin");
using pluginapi_create_t = boost::shared_ptr<my_plugin_api>();
auto creator = dll::import_alias<pluginapi_create_t>(
std::move(lib), "create_plugin"
);

std::cout << "Matching plugin name: " << creator()->name() << std::endl;
++ plugins_found;
Expand Down
3 changes: 1 addition & 2 deletions example/tutorial4/load_self.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ int main() {
dll::shared_library self(dll::program_location());

std::cout << "Call function" << std::endl;
boost::function<boost::shared_ptr<my_plugin_api>()> creator
= self.get_alias<boost::shared_ptr<my_plugin_api>()>("create_plugin");
auto creator = self.get_alias<boost::shared_ptr<my_plugin_api>()>("create_plugin");

std::cout << "Computed Value: " << creator()->calculate(2, 2) << std::endl;
//<-
Expand Down
17 changes: 8 additions & 9 deletions example/tutorial5/load_all.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace dll = boost::dll;

class plugins_collector {
// Name => plugin
typedef boost::container::map<std::string, dll::shared_library> plugins_t;
using plugins_t = boost::container::map<std::string, dll::shared_library>;

boost::dll::fs::path plugins_directory_;
plugins_t plugins_;
Expand All @@ -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)
Expand All @@ -52,8 +52,7 @@ class plugins_collector {
//[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;
Expand All @@ -67,25 +66,25 @@ 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;
}
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<boost::shared_ptr<my_plugin_api>()>("create_plugin")()->name();
Expand All @@ -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);
}
}
//]
Expand Down
6 changes: 3 additions & 3 deletions example/tutorial6/on_unload_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

//[plugcpp_on_unload
#include <boost/dll/alias.hpp> // for BOOST_DLL_ALIAS
#include <boost/function.hpp>
#include <functional>
#include <vector>

namespace my_namespace {

struct on_unload {
typedef boost::function<void()> callback_t;
typedef on_unload this_type;
using callback_t = std::function<void()> ;
using this_type = on_unload;

~on_unload() {
for (std::size_t i = 0; i < callbacks_.size(); ++i) {
Expand Down
13 changes: 6 additions & 7 deletions example/tutorial6/tutorial6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

//[callplugcpp_tutorial6
#include <boost/dll/import.hpp>
#include <boost/function.hpp>
#include <functional>
#include <iostream>

typedef boost::function<void()> callback_t;
using callback_t = std::function<void()> ;

void print_unloaded() {
std::cout << "unloaded" << std::endl;
Expand All @@ -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<void(const callback_t&)> on_unload
= boost::dll::import_alias<void(const callback_t&)>(
shared_library_path, "on_unload"
);
std::function<void(const callback_t&)> on_unload = boost::dll::import_alias<void(const callback_t&)>(
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;
}
//]
Expand Down
4 changes: 2 additions & 2 deletions example/tutorial8/refcounting_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ inline boost::shared_ptr<my_refcounting_api> bind(my_refcounting_api* plugin) {
inline boost::shared_ptr<my_refcounting_api> get_plugin(
boost::dll::fs::path path, const char* func_name)
{
typedef my_refcounting_api*(func_t)();
boost::function<func_t> creator = boost::dll::import_alias<func_t>(
using func_t = my_refcounting_api*();
auto creator = boost::dll::import_alias<func_t>(
path,
func_name,
boost::dll::load_mode::append_decorations // will be ignored for executable
Expand Down
9 changes: 4 additions & 5 deletions example/tutorial9/tutorial9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//[callplugcpp_tutorial9
#include <boost/dll/import.hpp> // for dll::import
#include <boost/dll/shared_library.hpp> // for dll::shared_library
#include <boost/function.hpp>
#include <functional>
#include <iostream>
#include <windows.h>

Expand All @@ -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<Signature> can not compile with
// You may put the `get_std_handle` into std::function<>. But std::function<Signature> may not compile with
// Signature template parameter that contains calling conventions, so you'll have to remove the calling convention.
boost::function<HANDLE(DWORD)> get_std_handle2 = get_std_handle;
std::function<HANDLE(DWORD)> 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_t>("GetStdHandle");

Expand Down
8 changes: 4 additions & 4 deletions include/boost/dll/alias.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
); \
Expand Down Expand Up @@ -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" \
); \
Expand All @@ -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" \
); \
Expand Down Expand Up @@ -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.
Expand Down
14 changes: 4 additions & 10 deletions include/boost/dll/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -38,38 +38,32 @@ using system_error = std::conditional_t<BOOST_DLL_USE_STD_FS, std::system_error,

#endif


#ifdef BOOST_DLL_USE_STD_FS
#include <filesystem>

#include <system_error>

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;

}}}

#else // BOOST_DLL_USE_STD_FS

#include <boost/filesystem/path.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/system/error_code.hpp>
#include <boost/system/system_error.hpp>
#include <boost/system/error_code.hpp>

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;

}}}

Expand Down
Loading

0 comments on commit 7cbc0d4

Please sign in to comment.