]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/libs/dll/test/symbol_runtime_info_test.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / dll / test / symbol_runtime_info_test.cpp
index fe4d6664663169a5280987a9091062d892410643..bfeb69bf6bd5006c6ef896420edb16ee95291ffd 100644 (file)
@@ -1,5 +1,5 @@
 // Copyright 2014 Renato Tegon Forti, Antony Polukhin.
-// Copyright 2015 Antony Polukhin.
+// Copyright 2015-2019 Antony Polukhin.
 //
 // Distributed under the Boost Software License, Version 1.0.
 // (See accompanying file LICENSE_1_0.txt
 
 #include <boost/core/lightweight_test.hpp>
 
+#include <boost/predef/os.h>
+
+
+#include <cmath>
+#include <exception> // std::set_terminate
+#include <signal.h> // ::signal
+
+// Makes global error variables dirty. Useful for preventing issues like https://github.com/boostorg/dll/issues/16
+void make_error_code_dirty() {
+    using namespace std;
+    (void)log(-1.0);
+
+#if BOOST_OS_WINDOWS
+    boost::winapi::WCHAR_ path_hldr[10];
+    int some_invalid_value_for_handle = 0xFF004242;
+    boost::winapi::HMODULE_ some_invalid_handle;
+    memcpy(&some_invalid_handle, &some_invalid_value_for_handle, sizeof(some_invalid_value_for_handle));
+    boost::winapi::GetModuleFileNameW(some_invalid_handle, path_hldr, 10);
+#endif
+}
+
+
+
 // lib functions
 
 typedef float (lib_version_func)();
@@ -25,6 +48,15 @@ extern "C" int BOOST_SYMBOL_EXPORT exef() {
     return 15;
 }
 
+
+extern "C" void BOOST_SYMBOL_EXPORT my_terminate_handler() {
+    std::abort();
+}
+
+extern "C" void BOOST_SYMBOL_EXPORT my_signal_handler(int) {
+    std::abort();
+}
+
 void internal_function() {}
 int internal_variable = 1;
 
@@ -32,9 +64,11 @@ int internal_variable = 1;
 int main(int argc, char* argv[]) {
     using namespace boost::dll;
 
-    boost::filesystem::path shared_library_path = b2_workarounds::first_lib_from_argv(argc, argv);
+    boost::dll::fs::path shared_library_path = b2_workarounds::first_lib_from_argv(argc, argv);
     BOOST_TEST(shared_library_path.string().find("test_library") != std::string::npos);
 
+    make_error_code_dirty();
+
     shared_library lib(shared_library_path);
 
     std::cout << std::endl;
@@ -45,6 +79,8 @@ int main(int argc, char* argv[]) {
         symbol_location(lib.get<int>("integer_g")) == lib.location()
     );
 
+    make_error_code_dirty();
+
     BOOST_TEST(
         symbol_location(lib.get<say_hello_func>("say_hello")) == lib.location()
     );
@@ -53,6 +89,8 @@ int main(int argc, char* argv[]) {
         symbol_location(lib.get<lib_version_func>("lib_version")) == lib.location()
     );
 
+    make_error_code_dirty();
+
     BOOST_TEST(
         symbol_location(lib.get<const int>("const_integer_g")) == lib.location()
     );
@@ -64,6 +102,9 @@ int main(int argc, char* argv[]) {
         symbol_location(lib.get<int>("integer_g")) == lib.location()
     );
 
+
+    make_error_code_dirty();
+
     // Checking aliases
     BOOST_TEST(
         symbol_location(lib.get<std::size_t(*)(const std::vector<int>&)>("foo_bar")) == lib.location()
@@ -81,19 +122,25 @@ int main(int argc, char* argv[]) {
     );
     
     { // self
+
+        make_error_code_dirty();
+
         shared_library sl(program_location());
+
+        make_error_code_dirty();
+
         BOOST_TEST(
-            (boost::filesystem::equivalent(symbol_location(sl.get<int(void)>("exef")), argv[0]))
+            (boost::dll::fs::equivalent(symbol_location(sl.get<int(void)>("exef")), argv[0]))
         );
     }
 
     { // self with error_code
-        boost::system::error_code ec;
+        boost::dll::fs::error_code ec;
         shared_library sl(program_location(ec));
         BOOST_TEST(!ec);
 
         BOOST_TEST(
-            (boost::filesystem::equivalent(symbol_location(sl.get<int(void)>("exef"), ec), argv[0]))
+            (boost::dll::fs::equivalent(symbol_location(sl.get<int(void)>("exef"), ec), argv[0]))
         );
         BOOST_TEST(!ec);
 
@@ -104,33 +151,81 @@ int main(int argc, char* argv[]) {
     std::cout << "\ninternal_function: " << symbol_location(internal_function);
     std::cout << "\nargv[0]          : " << boost::filesystem::absolute(argv[0]);
     BOOST_TEST(
-        (boost::filesystem::equivalent(symbol_location(internal_function), argv[0]))
+        (boost::dll::fs::equivalent(symbol_location(internal_function), argv[0]))
     );
 
     BOOST_TEST(
-        (boost::filesystem::equivalent(symbol_location(internal_variable), argv[0]))
+        (boost::dll::fs::equivalent(symbol_location(internal_variable), argv[0]))
     );
 
+    make_error_code_dirty();
 
     BOOST_TEST(
-        (boost::filesystem::equivalent(this_line_location(), argv[0]))
+        (boost::dll::fs::equivalent(this_line_location(), argv[0]))
     );
 
     { // this_line_location with error_code
-        boost::system::error_code ec;
+        boost::dll::fs::error_code ec;
+        make_error_code_dirty();
         BOOST_TEST(
-            (boost::filesystem::equivalent(this_line_location(ec), argv[0]))
+            (boost::dll::fs::equivalent(this_line_location(ec), argv[0]))
         );
         BOOST_TEST(!ec);
     }
 
     BOOST_TEST(
-        lib.get_alias<boost::filesystem::path()>("module_location_from_itself")() == lib.location()
+        lib.get_alias<boost::dll::fs::path()>("module_location_from_itself")() == lib.location()
     );
 
     // Checking docs content
     std::cout << "\nsymbol_location(std::cerr); // " << symbol_location(std::cerr);
     std::cout << "\nsymbol_location(std::puts); // " << symbol_location(std::puts);
+
+    std::set_terminate(&my_terminate_handler);
+    BOOST_TEST((boost::dll::fs::equivalent(
+        symbol_location_ptr(std::set_terminate(0)),
+        argv[0]
+    )));
+
+    {
+        boost::dll::fs::error_code ec;
+        boost::dll::fs::path p = symbol_location_ptr(std::set_terminate(0), ec);
+        BOOST_TEST(ec || !p.empty());
+    }
+
+    {
+        boost::dll::fs::error_code ec;
+        symbol_location(std::set_terminate(0), ec),
+        BOOST_TEST(ec);
+    }
+
+    {
+        std::set_terminate(&my_terminate_handler);
+        boost::dll::fs::error_code ec;
+        make_error_code_dirty();
+        symbol_location(std::set_terminate(0), ec),
+        BOOST_TEST(ec);
+    }
+
+    {
+        boost::dll::fs::error_code ec;
+        ::signal(SIGSEGV, &my_signal_handler);
+        boost::dll::fs::path p = symbol_location_ptr(::signal(SIGSEGV, SIG_DFL), ec);
+        BOOST_TEST((boost::dll::fs::equivalent(
+            p,
+            argv[0]
+        )) || ec);
+    }
+
+    {
+        ::signal(SIGSEGV, &my_signal_handler);
+        boost::dll::fs::error_code ec;
+        make_error_code_dirty();
+        symbol_location(::signal(SIGSEGV, SIG_DFL), ec);
+        BOOST_TEST(ec);
+    }
+
+
     return boost::report_errors();
 }