From 2bb0075e3fd7d57aec92b6b88538fe17892a52a9 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Sat, 22 May 2010 12:12:00 +0000 Subject: [PATCH] =?UTF-8?q?Major=20upgrade=20to=20Boost.Config=20symbol=20?= =?UTF-8?q?visibility=20macros=20for=20shared=20libraries,=20based=20on=20?= =?UTF-8?q?patches=20from=20J=C3=BCrgen=20Hunold=20with=20mods=20by=20Bema?= =?UTF-8?q?n=20Dawes.=20=20Upgrade=20Boost.System=20to=20use=20the=20new?= =?UTF-8?q?=20visibility=20macros.=20Fixes=20#3697=20and=20provides=20foun?= =?UTF-8?q?dation=20for=20fixing=202114,=202309,=20etc.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [SVN r62140] --- include/boost/system/config.hpp | 37 +++++-------- include/boost/system/system_error.hpp | 6 +- test/Jamfile.v2 | 16 +++++- test/dynamic_link_test.cpp | 55 +++++++++++++++++++ test/error_code_test.cpp | 6 ++ test/error_code_user_test.cpp | 48 ++++++++-------- test/header_only_test.cpp | 5 +- test/initialization_test.cpp | 4 +- test/system_error_test.cpp | 10 ++-- test/system_msvc/common.vsprops | 6 +- .../error_code_test/error_code_test.vcproj | 8 +-- test/system_msvc/system_msvc.sln | 31 +++++++++++ test/throw_test.cpp | 31 +++++++++++ 13 files changed, 193 insertions(+), 70 deletions(-) create mode 100644 test/dynamic_link_test.cpp create mode 100644 test/throw_test.cpp diff --git a/include/boost/system/config.hpp b/include/boost/system/config.hpp index fa09099..6bc217a 100644 --- a/include/boost/system/config.hpp +++ b/include/boost/system/config.hpp @@ -1,4 +1,4 @@ -// boost/system/config.hpp -------------------------------------------------// +// boost/system/config.hpp -----------------------------------------------------------// // Copyright Beman Dawes 2003, 2006 @@ -18,40 +18,29 @@ # if defined( BOOST_WINDOWS_API ) && defined( BOOST_POSIX_API ) # error both BOOST_WINDOWS_API and BOOST_POSIX_API are defined # elif !defined( BOOST_WINDOWS_API ) && !defined( BOOST_POSIX_API ) -# if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(__CYGWIN__) +# if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) + // All Win32 development environments, including 64-bit Windows and MinGW, define + // _WIN32 or one of its variant spellings. Note that Cygwin is a POSIX environment, + // so does not define _WIN32 or its variants. # define BOOST_WINDOWS_API # else # define BOOST_POSIX_API # endif # endif -// enable dynamic linking on Windows ---------------------------------------// +// enable dynamic or static linking as requested --------------------------------------// -//# if (defined(BOOST_ALL_DYN_LINK) || defined(BOOST_SYSTEM_DYN_LINK)) && defined(__BORLANDC__) && defined(__WIN32__) -//# error Dynamic linking Boost.System does not work for Borland; use static linking instead -//# endif - -#ifdef BOOST_HAS_DECLSPEC // defined in config system -// we need to import/export our code only if the user has specifically -// asked for it by defining either BOOST_ALL_DYN_LINK if they want all boost -// libraries to be dynamically linked, or BOOST_SYSTEM_DYN_LINK -// if they want just this one to be dynamically liked: #if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_SYSTEM_DYN_LINK) -// export if this is our own source, otherwise import: -#ifdef BOOST_SYSTEM_SOURCE -# define BOOST_SYSTEM_DECL __declspec(dllexport) +# if defined(BOOST_SYSTEM_SOURCE) +# define BOOST_SYSTEM_DECL BOOST_SYMBOL_EXPORT +# else +# define BOOST_SYSTEM_DECL BOOST_SYMBOL_IMPORT +# endif #else -# define BOOST_SYSTEM_DECL __declspec(dllimport) -#endif // BOOST_SYSTEM_SOURCE -#endif // DYN_LINK -#endif // BOOST_HAS_DECLSPEC -// -// if BOOST_SYSTEM_DECL isn't defined yet define it now: -#ifndef BOOST_SYSTEM_DECL -#define BOOST_SYSTEM_DECL +# define BOOST_SYSTEM_DECL #endif -// enable automatic library variant selection ------------------------------// +// enable automatic library variant selection ----------------------------------------// #if !defined(BOOST_SYSTEM_SOURCE) && !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_SYSTEM_NO_LIB) // diff --git a/include/boost/system/system_error.hpp b/include/boost/system/system_error.hpp index 3e83500..065d365 100644 --- a/include/boost/system/system_error.hpp +++ b/include/boost/system/system_error.hpp @@ -17,9 +17,11 @@ namespace boost { namespace system { - // class system_error --------------------------------------------------// + // class system_error ------------------------------------------------------------// - class system_error : public std::runtime_error + class BOOST_SYMBOL_VISIBLE system_error : public std::runtime_error + // BOOST_SYMBOL_VISIBLE is needed by GCC to ensure system_error thrown from a shared + // library can be caught. See svn.boost.org/trac/boost/ticket/3697 { public: system_error( error_code ec ) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 7b14c76..043a36f 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -12,6 +12,12 @@ project /boost/system//boost_system msvc:on ; + + lib throw_test + : throw_test.cpp + : shared:BOOST_SYSTEM_DYN_LINK=1 + ; + test-suite "system" : [ run error_code_test.cpp @@ -21,21 +27,25 @@ project static ] [ run error_code_test.cpp - : : : : error_code_test_dll + : : : shared : error_code_test_shared ] [ run error_code_user_test.cpp : : : static ] [ run error_code_user_test.cpp - : : : : error_code_user_test_dll + : : : shared : error_code_user_test_shared ] [ run system_error_test.cpp : : : static ] [ run system_error_test.cpp - : : : : system_error_test_dll + : : : shared : system_error_test_shared + ] + [ run dynamic_link_test.cpp throw_test + : : : shared : throw_test_shared ] [ run initialization_test.cpp + : : : shared : initialization_test_shared ] [ run header_only_test.cpp : : : static diff --git a/test/dynamic_link_test.cpp b/test/dynamic_link_test.cpp new file mode 100644 index 0000000..87f37c2 --- /dev/null +++ b/test/dynamic_link_test.cpp @@ -0,0 +1,55 @@ +// dynamic_link_test.cpp -------------------------------------------------------------// + +// Copyright Beman Dawes 2010 + +// Distributed under the Boost Software License, Version 1.0. +// See www.boost.org/LICENSE_1_0.txt + +// Library home page is www.boost.org/libs/system + +//--------------------------------------------------------------------------------------// + +// Dynamic link libraries (DLL's), also know as dynamic shared objects (DSO's), +// can cause symbol visability problems unless carefully configured. One of the +// manifestations, particularly with GCC, is that a system_error exception thrown from +// a DLL or DSO is not caught. +// +// The purpose of this program is to test for that error. + +//--------------------------------------------------------------------------------------// + +#include + +#include + +namespace boost +{ + namespace system + { + BOOST_SYSTEM_DECL void throw_test(); + } +} + +int main() +{ + try + { + boost::system::throw_test(); + } + catch (const boost::system::system_error& ex) + { + std::cout << " caught boost::system::system_error as expected\n"; + std::cout << " what() reports " << ex.what() << '\n'; + return 0; + } + + catch (const std::runtime_error& ex) + { + std::cout << " error: caught std::runtime_error instead of boost::system::system_error\n"; + std::cout << " what() reports " << ex.what() << '\n'; + return 1; + } + + std::cout << " error: failed to catch boost::system::system_error\n"; + return 1; +} \ No newline at end of file diff --git a/test/error_code_test.cpp b/test/error_code_test.cpp index 4870b2d..8c0e7c7 100644 --- a/test/error_code_test.cpp +++ b/test/error_code_test.cpp @@ -59,6 +59,12 @@ namespace int main( int, char ** ) { + std::cout << "Conversion use cases...\n"; + error_condition x1( errc::file_exists ); + //error_code x2( errc::file_exists ); // should fail to compile + make_error_code(errc::file_exists); + make_error_condition(errc::file_exists); + std::cout << "General tests...\n"; // unit tests: diff --git a/test/error_code_user_test.cpp b/test/error_code_user_test.cpp index be9adaa..be1a43e 100644 --- a/test/error_code_user_test.cpp +++ b/test/error_code_user_test.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #ifdef BOOST_POSIX_API # include @@ -264,7 +264,7 @@ namespace lib4 // // void check_success(const boost::system::error_code& ec, bool expect) // { -// BOOST_CHECK( (ec == boost::system::posix::success) == expect ); +// BOOST_TEST( (ec == boost::system::posix::success) == expect ); // if (ec == boost::system::posix::success) // std::cout << "yes... " << (expect ? "ok" : "fail") << '\n'; // else @@ -273,7 +273,7 @@ namespace lib4 // // void check_permission_denied(const boost::system::error_code& ec, bool expect) // { -// BOOST_CHECK( (ec == boost::system::posix::permission_denied) == expect ); +// BOOST_TEST( (ec == boost::system::posix::permission_denied) == expect ); // if (ec == boost::system::posix::permission_denied) // std::cout << "yes... " << (expect ? "ok" : "fail") << '\n'; // else @@ -282,7 +282,7 @@ namespace lib4 // // void check_out_of_memory(const boost::system::error_code& ec, bool expect) // { -// BOOST_CHECK( (ec == boost::system::posix::not_enough_memory) == expect ); +// BOOST_TEST( (ec == boost::system::posix::not_enough_memory) == expect ); // if (ec == boost::system::posix::not_enough_memory) // std::cout << "yes... " << (expect ? "ok" : "fail") << '\n'; // else @@ -337,7 +337,7 @@ namespace lib4 // ------------------------------------------------------------------------ // -int test_main( int, char *[] ) +int main( int, char *[] ) { boost::system::error_code ec; @@ -346,35 +346,35 @@ int test_main( int, char *[] ) ec = my_mkdir( "/no-such-file-or-directory/will-not-succeed" ); std::cout << "ec.value() is " << ec.value() << '\n'; - BOOST_CHECK( ec ); - BOOST_CHECK( ec == boost::system::posix::no_such_file_or_directory ); - BOOST_CHECK( ec.category() == boost::system::system_category ); + BOOST_TEST( ec ); + BOOST_TEST( ec == boost::system::posix::no_such_file_or_directory ); + BOOST_TEST( ec.category() == boost::system::system_category ); // Library 2 tests: ec = my_remove( "/no-such-file-or-directory" ); std::cout << "ec.value() is " << ec.value() << '\n'; - BOOST_CHECK( ec ); - BOOST_CHECK( ec == boost::system::posix::no_such_file_or_directory ); - BOOST_CHECK( ec.category() == boost::system::posix_category ); + BOOST_TEST( ec ); + BOOST_TEST( ec == boost::system::posix::no_such_file_or_directory ); + BOOST_TEST( ec.category() == boost::system::posix_category ); // Library 3 tests: ec = boost::lib3::boo_boo; std::cout << "ec.value() is " << ec.value() << '\n'; - BOOST_CHECK( ec ); - BOOST_CHECK( ec == boost::lib3::boo_boo ); - BOOST_CHECK( ec.value() == boost::lib3::boo_boo ); - BOOST_CHECK( ec.category() == boost::lib3::lib3_error_category ); + BOOST_TEST( ec ); + BOOST_TEST( ec == boost::lib3::boo_boo ); + BOOST_TEST( ec.value() == boost::lib3::boo_boo ); + BOOST_TEST( ec.category() == boost::lib3::lib3_error_category ); - BOOST_CHECK( ec == boost::system::posix::io_error ); + BOOST_TEST( ec == boost::system::posix::io_error ); boost::system::error_code ec3( boost::lib3::boo_boo+100, boost::lib3::lib3_error_category ); - BOOST_CHECK( ec3.category() == boost::lib3::lib3_error_category ); - BOOST_CHECK( ec3.default_error_condition().category() + BOOST_TEST( ec3.category() == boost::lib3::lib3_error_category ); + BOOST_TEST( ec3.default_error_condition().category() == boost::lib3::lib3_error_category ); // Library 4 tests: @@ -382,16 +382,16 @@ int test_main( int, char *[] ) ec = lib4::boo_boo; std::cout << "ec.value() is " << ec.value() << '\n'; - BOOST_CHECK( ec ); - BOOST_CHECK( ec == lib4::boo_boo ); - BOOST_CHECK( ec.value() == lib4::boo_boo.value() ); - BOOST_CHECK( ec.category() == lib4::lib4_error_category ); + BOOST_TEST( ec ); + BOOST_TEST( ec == lib4::boo_boo ); + BOOST_TEST( ec.value() == lib4::boo_boo.value() ); + BOOST_TEST( ec.category() == lib4::lib4_error_category ); - BOOST_CHECK( ec == boost::system::posix::io_error ); + BOOST_TEST( ec == boost::system::posix::io_error ); boost::system::error_code ec4( lib4::boo_boo.value()+100, lib4::lib4_error_category ); - BOOST_CHECK( ec4.default_error_condition().category() + BOOST_TEST( ec4.default_error_condition().category() == lib4::lib4_error_category ); // Test 3 diff --git a/test/header_only_test.cpp b/test/header_only_test.cpp index 20d6179..7c74793 100644 --- a/test/header_only_test.cpp +++ b/test/header_only_test.cpp @@ -13,11 +13,10 @@ #define BOOST_ERROR_CODE_HEADER_ONLY -#include - +#include #include -int test_main( int, char*[] ) +int main( int, char*[] ) { boost::system::error_code ec( 0, boost::system::system_category ); return 0; diff --git a/test/initialization_test.cpp b/test/initialization_test.cpp index 7ccd594..c481e5a 100644 --- a/test/initialization_test.cpp +++ b/test/initialization_test.cpp @@ -10,7 +10,7 @@ // This test verifiies that the error_category vtable does not suffer from // order-of-initialization problems. -#include +#include #include struct foo @@ -22,7 +22,7 @@ struct foo } } f; -int test_main( int, char ** ) +int main( int, char ** ) { return 0; } diff --git a/test/system_error_test.cpp b/test/system_error_test.cpp index 0f3dbe4..67c27a1 100644 --- a/test/system_error_test.cpp +++ b/test/system_error_test.cpp @@ -14,7 +14,7 @@ #include -#include +#include #include #include #include @@ -36,8 +36,8 @@ namespace int v, const char * str ) { std::cout << "test " << desc << "\n what() returns \"" << ex.what() << "\"\n"; - BOOST_CHECK( ex.code().value() == v ); - BOOST_CHECK( ex.code().category() == system_category ); + BOOST_TEST( ex.code().value() == v ); + BOOST_TEST( ex.code().category() == system_category ); # ifdef BOOST_WINDOWS_API LANGID language_id; # if !defined(__MINGW32__) && !defined(__CYGWIN__) @@ -48,7 +48,7 @@ namespace // std::cout << "GetUserDefaultUILanguage() returns " << language_id << '\n'; if ( language_id == 0x0409 ) // English (United States) { - BOOST_CHECK( std::string( ex.what() ) == str ); + BOOST_TEST( std::string( ex.what() ) == str ); if ( std::string( ex.what() ) != str ) std::cout << "expected \"" << str << "\", but what() returned \"" << ex.what() << "\"\n"; @@ -59,7 +59,7 @@ namespace const boost::uint_least32_t uvalue = 2u; } -int test_main( int, char *[] ) +int main( int, char *[] ) { // all constructors, in the same order as they appear in the header: diff --git a/test/system_msvc/common.vsprops b/test/system_msvc/common.vsprops index 4dce1d5..e4cc705 100644 --- a/test/system_msvc/common.vsprops +++ b/test/system_msvc/common.vsprops @@ -7,13 +7,13 @@ diff --git a/test/system_msvc/error_code_test/error_code_test.vcproj b/test/system_msvc/error_code_test/error_code_test.vcproj index d59cd21..f69ff01 100644 --- a/test/system_msvc/error_code_test/error_code_test.vcproj +++ b/test/system_msvc/error_code_test/error_code_test.vcproj @@ -86,6 +86,8 @@ /> @@ -172,10 +176,6 @@ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" > - - diff --git a/test/system_msvc/system_msvc.sln b/test/system_msvc/system_msvc.sln index f26e95f..d3d2746 100644 --- a/test/system_msvc/system_msvc.sln +++ b/test/system_msvc/system_msvc.sln @@ -2,8 +2,27 @@ Microsoft Visual Studio Solution File, Format Version 10.00 # Visual C++ Express 2008 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "error_code_test", "error_code_test\error_code_test.vcproj", "{81960557-E9A9-4E81-AC96-9E11C33CB058}" + ProjectSection(ProjectDependencies) = postProject + {22892211-A1F3-435B-8B97-A12E8772599E} = {22892211-A1F3-435B-8B97-A12E8772599E} + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "system_error_test", "system_error_test\system_error_test.vcproj", "{CBD12E59-99E5-4F35-9B66-0554D0FBDB76}" + ProjectSection(ProjectDependencies) = postProject + {22892211-A1F3-435B-8B97-A12E8772599E} = {22892211-A1F3-435B-8B97-A12E8772599E} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dynamic_link_test", "dynamic_link_test\dynamic_link_test.vcproj", "{AD186B11-9132-48A9-9F24-3522C2310B0D}" + ProjectSection(ProjectDependencies) = postProject + {F6D9B408-84A3-405A-93ED-DE5AA8CF84D7} = {F6D9B408-84A3-405A-93ED-DE5AA8CF84D7} + {22892211-A1F3-435B-8B97-A12E8772599E} = {22892211-A1F3-435B-8B97-A12E8772599E} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "system_dll", "system_dll\system_dll.vcproj", "{22892211-A1F3-435B-8B97-A12E8772599E}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "throw_test_dll", "throw_test_dll\throw_test_dll.vcproj", "{F6D9B408-84A3-405A-93ED-DE5AA8CF84D7}" + ProjectSection(ProjectDependencies) = postProject + {22892211-A1F3-435B-8B97-A12E8772599E} = {22892211-A1F3-435B-8B97-A12E8772599E} + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -19,6 +38,18 @@ Global {CBD12E59-99E5-4F35-9B66-0554D0FBDB76}.Debug|Win32.Build.0 = Debug|Win32 {CBD12E59-99E5-4F35-9B66-0554D0FBDB76}.Release|Win32.ActiveCfg = Release|Win32 {CBD12E59-99E5-4F35-9B66-0554D0FBDB76}.Release|Win32.Build.0 = Release|Win32 + {AD186B11-9132-48A9-9F24-3522C2310B0D}.Debug|Win32.ActiveCfg = Debug|Win32 + {AD186B11-9132-48A9-9F24-3522C2310B0D}.Debug|Win32.Build.0 = Debug|Win32 + {AD186B11-9132-48A9-9F24-3522C2310B0D}.Release|Win32.ActiveCfg = Release|Win32 + {AD186B11-9132-48A9-9F24-3522C2310B0D}.Release|Win32.Build.0 = Release|Win32 + {22892211-A1F3-435B-8B97-A12E8772599E}.Debug|Win32.ActiveCfg = Debug|Win32 + {22892211-A1F3-435B-8B97-A12E8772599E}.Debug|Win32.Build.0 = Debug|Win32 + {22892211-A1F3-435B-8B97-A12E8772599E}.Release|Win32.ActiveCfg = Release|Win32 + {22892211-A1F3-435B-8B97-A12E8772599E}.Release|Win32.Build.0 = Release|Win32 + {F6D9B408-84A3-405A-93ED-DE5AA8CF84D7}.Debug|Win32.ActiveCfg = Debug|Win32 + {F6D9B408-84A3-405A-93ED-DE5AA8CF84D7}.Debug|Win32.Build.0 = Debug|Win32 + {F6D9B408-84A3-405A-93ED-DE5AA8CF84D7}.Release|Win32.ActiveCfg = Release|Win32 + {F6D9B408-84A3-405A-93ED-DE5AA8CF84D7}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/test/throw_test.cpp b/test/throw_test.cpp new file mode 100644 index 0000000..998fc20 --- /dev/null +++ b/test/throw_test.cpp @@ -0,0 +1,31 @@ +// throw_test.cpp --------------------------------------------------------===========-// + +// Copyright Beman Dawes 2010 + +// Distributed under the Boost Software License, Version 1.0. +// See www.boost.org/LICENSE_1_0.txt + +// Library home page is www.boost.org/libs/system + +//--------------------------------------------------------------------------------------// + +// See dynamic_link_test.cpp comments for use case. + +//--------------------------------------------------------------------------------------// + +// define BOOST_SYSTEM_SOURCE so that knows +// the library is being built (possibly exporting rather than importing code) +#define BOOST_SYSTEM_SOURCE + +#include + +namespace boost +{ + namespace system + { + BOOST_SYSTEM_DECL void throw_test() + { + throw system_error(9999, get_system_category(), "boo boo"); + } + } +}