From 296a35773a259f67d1fdd8a27eb0a199d4785b82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Neun=C3=BCller?= Date: Wed, 14 Aug 2013 22:21:45 +0200 Subject: [PATCH] Try to be compatible with older Boost versions (#7). --- CMakeLists.txt | 2 +- doc/build-options.rst | 6 ++++++ luabind/config.hpp | 29 ++++++++++++++++++++++++++++ luabind/detail/call_function.hpp | 4 ++-- luabind/detail/decorate_type.hpp | 2 +- luabind/detail/policy.hpp | 10 +++------- luabind/function_converter.hpp | 4 ++-- luabind/object.hpp | 2 +- luabind/std_shared_ptr_converter.hpp | 1 + 9 files changed, 46 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a43e9482..a5e828c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,7 @@ set(CMAKE_MODULE_PATH set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME OFF) -find_package(Boost 1.51.0 REQUIRED) +find_package(Boost 1.40.0 REQUIRED) # Better use at least 1.51. find_package(Lua52 REQUIRED) if (BUILD_SHARED_LIBS) diff --git a/doc/build-options.rst b/doc/build-options.rst index cf24d8e6..b5e2ac5c 100644 --- a/doc/build-options.rst +++ b/doc/build-options.rst @@ -73,6 +73,12 @@ to Lua and boost in there as well. This define will disable all asserts and should be defined in a release build. +``LUABIND_USE_NOEXCEPT`` + If you use Boost <= 1.46 but your compiler is C++11 compliant and marks + destructors as noexcept by default, you need to define LUABIND_USE_NOEXCEPT. + Failing to do so will cause std::terminate() being called if a destructor + throws (e.g. the destructor of the proxy returned by ``call_function`` or + ``object::operator()``). CMake options ~~~~~~~~~~~~~ diff --git a/luabind/config.hpp b/luabind/config.hpp index d16212cc..6d8f10b2 100644 --- a/luabind/config.hpp +++ b/luabind/config.hpp @@ -118,6 +118,35 @@ namespace std # define LUABIND_API #endif +// C++11 features // + +#if ( defined(BOOST_NO_CXX11_SCOPED_ENUMS) \ + || defined(BOOST_NO_SCOPED_ENUMS) \ + || defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS) \ + || defined(BOOST_NO_0X_HDR_TYPE_TRAITS)) +# define LUABIND_NO_SCOPED_ENUM +#endif + +#if ( defined(BOOST_NO_CXX11_RVALUE_REFERENCES) \ + || defined(BOOST_NO_RVALUE_REFERENCES)) +# define LUABIND_NO_RVALUE_REFERENCES +#endif + +// If you use Boost <= 1.46 but your compiler is C++11 compliant and marks +// destructors as noexcept by default, you need to define LUABIND_USE_NOEXCEPT. +#if !defined(BOOST_NO_NOEXCEPT) && !defined(BOOST_NO_CXX11_NOEXCEPT) +# define LUABIND_USE_NOEXCEPT +#endif +#ifndef LUABIND_MAY_THROW +# ifdef BOOST_NOEXCEPT_IF +# define LUABIND_MAY_THROW BOOST_NOEXCEPT_IF(false) +# elif defined(LUABIND_USE_NOEXCEPT) +# define LUABIND_MAY_THROW noexcept(false) +# else +# define LUABIND_MAY_THROW +# endif +#endif + namespace luabind { LUABIND_API void disable_super_deprecation(); diff --git a/luabind/detail/call_function.hpp b/luabind/detail/call_function.hpp index 26f63e44..b766dd58 100644 --- a/luabind/detail/call_function.hpp +++ b/luabind/detail/call_function.hpp @@ -79,7 +79,7 @@ namespace luabind rhs.m_called = true; } - ~proxy_function_caller() BOOST_NOEXCEPT_IF(false) + ~proxy_function_caller() LUABIND_MAY_THROW { if (m_called) return; @@ -242,7 +242,7 @@ namespace luabind rhs.m_called = true; } - ~proxy_function_void_caller() BOOST_NOEXCEPT_IF(false) + ~proxy_function_void_caller() LUABIND_MAY_THROW { if (m_called) return; diff --git a/luabind/detail/decorate_type.hpp b/luabind/detail/decorate_type.hpp index 3ee03e47..62acfbcf 100644 --- a/luabind/detail/decorate_type.hpp +++ b/luabind/detail/decorate_type.hpp @@ -92,7 +92,7 @@ namespace luabind { namespace detail template by_const_reference decorated_type::t; -#ifdef BOOST_HAS_RVALUE_REFS +#ifndef LUABIND_NO_RVALUE_REFERENCES template struct decorated_type { diff --git a/luabind/detail/policy.hpp b/luabind/detail/policy.hpp index 8fb8bbed..f888976c 100644 --- a/luabind/detail/policy.hpp +++ b/luabind/detail/policy.hpp @@ -62,10 +62,6 @@ #include #include -#if ( defined(BOOST_NO_CXX11_SCOPED_ENUMS) \ - || defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)) -# define LUABIND_NO_SCOPED_ENUM -#endif #ifndef LUABIND_NO_SCOPED_ENUM # include #endif @@ -677,7 +673,7 @@ lua_Number as_lua_number(T v) return static_cast(v); } -#ifdef BOOST_HAS_RVALUE_REFS +#ifndef LUABIND_NO_RVALUE_REFERENCES # define LUABIND_NUMBER_CONVERTER(type, kind) \ template <> \ @@ -806,7 +802,7 @@ struct default_converter : default_converter {}; -#ifdef BOOST_HAS_RVALUE_REFS +#ifndef LUABIND_NO_RVALUE_REFERENCES template <> struct default_converter : default_converter @@ -843,7 +839,7 @@ struct default_converter : default_converter {}; -#ifdef BOOST_HAS_RVALUE_REFS +#ifndef LUABIND_NO_RVALUE_REFERENCES template <> struct default_converter : default_converter diff --git a/luabind/function_converter.hpp b/luabind/function_converter.hpp index c885caca..ff4937a8 100644 --- a/luabind/function_converter.hpp +++ b/luabind/function_converter.hpp @@ -116,12 +116,12 @@ namespace luabind { # define N BOOST_PP_ITERATION() # define TMPL_PARAMS BOOST_PP_ENUM_PARAMS(N, typename A) -# ifndef BOOST_NO_CXX11_RVALUE_REFERENCES +# ifndef LUABIND_NO_RVALUE_REFERENCES # define TYPED_ARGS BOOST_PP_ENUM_BINARY_PARAMS(N, A, && a) # else # define TYPED_ARGS BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& a) # endif -# ifndef BOOST_NO_CXX11_RVALUE_REFERENCES +# ifndef LUABIND_NO_RVALUE_REFERENCES # define PRINT_FORWARD_ARG(z, n, _) std::forward(BOOST_PP_CAT(a, n)) # define TRAILING_ARGS BOOST_PP_ENUM_TRAILING(N, PRINT_FORWARD_ARG, ~) # else diff --git a/luabind/object.hpp b/luabind/object.hpp index 4bbded96..44875e2e 100644 --- a/luabind/object.hpp +++ b/luabind/object.hpp @@ -973,7 +973,7 @@ namespace adl other.value_wrapper = 0; } - ~call_proxy() BOOST_NOEXCEPT_IF(false) + ~call_proxy() LUABIND_MAY_THROW { if (value_wrapper) call(static_cast(0)); diff --git a/luabind/std_shared_ptr_converter.hpp b/luabind/std_shared_ptr_converter.hpp index ae08f57e..b4f54241 100644 --- a/luabind/std_shared_ptr_converter.hpp +++ b/luabind/std_shared_ptr_converter.hpp @@ -7,6 +7,7 @@ #include #if (defined(BOOST_NO_CXX11_SMART_PTR) \ + && !defined(BOOST_HAS_TR1_SHARED_PTR) \ && (!defined(BOOST_MSVC) || BOOST_MSVC < 1600)) # define LUABIND_NO_STD_SHARED_PTR #else