diff --git a/include/boost/interprocess/detail/preprocessor.hpp b/include/boost/interprocess/detail/preprocessor.hpp index 4ba183b..431e96e 100644 --- a/include/boost/interprocess/detail/preprocessor.hpp +++ b/include/boost/interprocess/detail/preprocessor.hpp @@ -57,21 +57,10 @@ #ifndef BOOST_NO_RVALUE_REFERENCES - #if defined(BOOST_MOVE_MSVC_10_MEMBER_RVALUE_REF_BUG) - - #define BOOST_INTERPROCESS_PP_PARAM_INIT(z, n, data) \ - BOOST_PP_CAT(m_p, n) (BOOST_PP_CAT(p, n)) \ - //! - - - #else //#if defined(BOOST_MOVE_MSVC_10_MEMBER_RVALUE_REF_BUG) - #define BOOST_INTERPROCESS_PP_PARAM_INIT(z, n, data) \ BOOST_PP_CAT(m_p, n) (::boost::forward< BOOST_PP_CAT(P, n) >( BOOST_PP_CAT(p, n) )) \ //! - #endif //#if defined(BOOST_MOVE_MSVC_10_MEMBER_RVALUE_REF_BUG) - #else //#ifndef BOOST_NO_RVALUE_REFERENCES #define BOOST_INTERPROCESS_PP_PARAM_INIT(z, n, data) \ @@ -79,31 +68,104 @@ //! #endif -#define BOOST_INTERPROCESS_PP_PARAM_INC(z, n, data) \ - BOOST_PP_CAT(++m_p, n) \ -//! - #ifndef BOOST_NO_RVALUE_REFERENCES -#if defined(BOOST_MOVE_MSVC_10_MEMBER_RVALUE_REF_BUG) + #if defined(BOOST_MOVE_MSVC_10_MEMBER_RVALUE_REF_BUG) -#define BOOST_INTERPROCESS_PP_PARAM_DEFINE(z, n, data) \ - BOOST_PP_CAT(P, n) & BOOST_PP_CAT(m_p, n); \ -//! + namespace boost { + namespace interprocess { + namespace ipcdetail { + template + struct ref_holder; + + template + struct ref_holder + { + ref_holder(T &t) + : t_(t) + {} + T &t_; + T & get() { return t_; } + T & get_lvalue() { return t_; } + }; + + template + struct ref_holder + { + ref_holder(const T &t) + : t_(t) + {} + const T &t_; + const T & get() { return t_; } + const T & get_lvalue() { return t_; } + }; + + template + struct ref_holder + { + ref_holder(const T &t) + : t_(t) + {} + const T &t_; + const T & get() { return t_; } + const T & get_lvalue() { return t_; } + }; + + template + struct ref_holder + { + ref_holder(T &&t) + : t_(t) + {} + T &t_; + T && get() { return ::boost::move(t_); } + T & get_lvalue() { return t_; } + }; + + template + struct ref_holder + { + ref_holder(T &&t) + : t(t) + {} + T &t; + T && get() { return ::boost::move(t_); } + T & get_lvalue() { return t_; } + }; + + } //namespace ipcdetail { + } //namespace interprocess { + } //namespace boost { + + #define BOOST_INTERPROCESS_PP_PARAM_DEFINE(z, n, data) \ + ::boost::interprocess::ipcdetail::ref_holder BOOST_PP_CAT(m_p, n); \ + //! + + #define BOOST_INTERPROCESS_PP_PARAM_INC(z, n, data) \ + BOOST_PP_CAT(++m_p, n).get_lvalue() \ + //! + + #else //BOOST_MOVE_MSVC_10_MEMBER_RVALUE_REF_BUG + + #define BOOST_INTERPROCESS_PP_PARAM_DEFINE(z, n, data)\ + BOOST_PP_CAT(P, n) && BOOST_PP_CAT(m_p, n); \ + //! + + #define BOOST_INTERPROCESS_PP_PARAM_INC(z, n, data) \ + BOOST_PP_CAT(++m_p, n) \ + //! + + #endif //defined(BOOST_MOVE_MSVC_10_MEMBER_RVALUE_REF_BUG) #else + #define BOOST_INTERPROCESS_PP_PARAM_DEFINE(z, n, data) \ + BOOST_PP_CAT(P, n) & BOOST_PP_CAT(m_p, n); \ + //! -#define BOOST_INTERPROCESS_PP_PARAM_DEFINE(z, n, data) \ - BOOST_PP_CAT(P, n) && BOOST_PP_CAT(m_p, n); \ -//! + #define BOOST_INTERPROCESS_PP_PARAM_INC(z, n, data) \ + BOOST_PP_CAT(++m_p, n) \ + //! -#endif //defined(BOOST_MOVE_MSVC_10_MEMBER_RVALUE_REF_BUG) - - -#else -#define BOOST_INTERPROCESS_PP_PARAM_DEFINE(z, n, data) \ - BOOST_PP_CAT(P, n) & BOOST_PP_CAT(m_p, n); \ -//! #endif #define BOOST_INTERPROCESS_PP_PARAM_FORWARD(z, n, data) \ @@ -112,24 +174,26 @@ #if !defined(BOOST_NO_RVALUE_REFERENCES) && defined(BOOST_MOVE_MSVC_10_MEMBER_RVALUE_REF_BUG) -#include + #define BOOST_INTERPROCESS_PP_MEMBER_FORWARD(z, n, data) BOOST_PP_CAT(this->m_p, n).get() \ + //! -#define BOOST_INTERPROCESS_PP_MEMBER_FORWARD(z, n, data) \ -::boost::container::container_detail::stored_ref< BOOST_PP_CAT(P, n) >::forward( BOOST_PP_CAT(m_p, n) ) \ -//! + #define BOOST_INTERPROCESS_PP_MEMBER_IT_FORWARD(z, n, data) \ + BOOST_PP_CAT(*m_p, n).get_lvalue() \ + //! #else -#define BOOST_INTERPROCESS_PP_MEMBER_FORWARD(z, n, data) \ -::boost::forward< BOOST_PP_CAT(P, n) >( BOOST_PP_CAT(m_p, n) ) \ -//! + #define BOOST_INTERPROCESS_PP_MEMBER_FORWARD(z, n, data) \ + ::boost::forward< BOOST_PP_CAT(P, n) >( BOOST_PP_CAT(m_p, n) ) \ + //! + + #define BOOST_INTERPROCESS_PP_MEMBER_IT_FORWARD(z, n, data) \ + BOOST_PP_CAT(*m_p, n) \ + //! + #endif //!defined(BOOST_NO_RVALUE_REFERENCES) && defined(BOOST_MOVE_MSVC_10_MEMBER_RVALUE_REF_BUG) -#define BOOST_INTERPROCESS_PP_MEMBER_IT_FORWARD(z, n, data) \ -BOOST_PP_CAT(*m_p, n) \ -//! - #include #else diff --git a/proj/to-do.txt b/proj/to-do.txt index ec55fe2..658f4e0 100644 --- a/proj/to-do.txt +++ b/proj/to-do.txt @@ -249,3 +249,17 @@ MyRobustMutexLockFile() ipcdetail::intermodule_singleton::get(); +Add unsigned overflow checking with shortcut as explained here: + +https://github.com/ivmai/bdwgc/commit/83231d0ab5ed60015797c3d1ad9056295ac3b2bb + +# define GC_SIZE_MAX (~(size_t)0) + #endif ++#define GC_SQRT_SIZE_MAX ((1U << (WORDSZ / 2)) - 1) ++ +void * calloc(size_t n, size_t lb) +{ +- if (lb && n > GC_SIZE_MAX / lb) ++ if ((lb | n) > GC_SQRT_SIZE_MAX /* fast initial test */ ++ && lb && n > GC_SIZE_MAX / lb) + return NULL; diff --git a/test/allocator_v1.hpp b/test/allocator_v1.hpp index 7185076..6fb7dc2 100644 --- a/test/allocator_v1.hpp +++ b/test/allocator_v1.hpp @@ -29,6 +29,7 @@ #include #include #include +#include //!\file //!Describes an allocator_v1 that allocates portions of fixed size @@ -118,7 +119,12 @@ class allocator_v1 //!Allocates memory for an array of count elements. //!Throws boost::interprocess::bad_alloc if there is no enough memory pointer allocate(size_type count, cvoid_ptr hint = 0) - { (void)hint; return pointer(static_cast(mp_mngr->allocate(count*sizeof(value_type)))); } + { + if(size_overflows(count)){ + throw bad_alloc(); + } + (void)hint; return pointer(static_cast(mp_mngr->allocate(count*sizeof(T)))); + } //!Deallocates memory previously allocated. Never throws void deallocate(const pointer &ptr, size_type) diff --git a/test/memory_algorithm_test_template.hpp b/test/memory_algorithm_test_template.hpp index b8eea27..5892e00 100644 --- a/test/memory_algorithm_test_template.hpp +++ b/test/memory_algorithm_test_template.hpp @@ -679,8 +679,7 @@ bool test_many_equal_allocation(Allocator &a) typename multiallocation_chain::size_type n = chain.size(); while(!chain.empty()){ - buffers.push_back(ipcdetail::to_raw_pointer(chain.front())); - chain.pop_front(); + buffers.push_back(ipcdetail::to_raw_pointer(chain.pop_front())); } if(n != std::size_t((i+1)*2)) return false; @@ -788,8 +787,7 @@ bool test_many_different_allocation(Allocator &a) break; typename multiallocation_chain::size_type n = chain.size(); while(!chain.empty()){ - buffers.push_back(ipcdetail::to_raw_pointer(chain.front())); - chain.pop_front(); + buffers.push_back(ipcdetail::to_raw_pointer(chain.pop_front())); } if(n != ArraySize) return false;