From 2208226d2c386009943091bd80328948342a6404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Sat, 17 Oct 2015 00:13:38 +0200 Subject: [PATCH] Use uinptr_t instead of size_t, only the former is guaranteed to be able to hold a pointer --- include/boost/intrusive/intrusive_fwd.hpp | 14 +++++++++++++- include/boost/intrusive/pointer_plus_bits.hpp | 14 +++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/include/boost/intrusive/intrusive_fwd.hpp b/include/boost/intrusive/intrusive_fwd.hpp index b6b14c0..f51276d 100644 --- a/include/boost/intrusive/intrusive_fwd.hpp +++ b/include/boost/intrusive/intrusive_fwd.hpp @@ -16,7 +16,11 @@ #ifndef BOOST_CONFIG_HPP # include #endif - +# +#ifndef BOOST_CSTDINT_HPP +# include +#endif +# #if defined(BOOST_HAS_PRAGMA_ONCE) # pragma once #endif @@ -65,6 +69,14 @@ namespace boost { namespace intrusive { +#if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED) +# ifdef BOOST_HAS_INTPTR_T + using ::boost::uintptr_t; +# else + typedef std::size_t uintptr_t; +# endif +#endif + //////////////////////////// // Node algorithms //////////////////////////// diff --git a/include/boost/intrusive/pointer_plus_bits.hpp b/include/boost/intrusive/pointer_plus_bits.hpp index 117aff3..6168ea8 100644 --- a/include/boost/intrusive/pointer_plus_bits.hpp +++ b/include/boost/intrusive/pointer_plus_bits.hpp @@ -64,25 +64,25 @@ struct pointer_plus_bits template struct pointer_plus_bits { - static const std::size_t Mask = ((std::size_t(1u) << NumBits) - 1); + static const uintptr_t Mask = uintptr_t((uintptr_t(1u) << NumBits) - 1); typedef T* pointer; static pointer get_pointer(pointer n) - { return pointer(std::size_t(n) & ~Mask); } + { return pointer(uintptr_t(n) & uintptr_t(~Mask)); } static void set_pointer(pointer &n, pointer p) { - BOOST_INTRUSIVE_INVARIANT_ASSERT(0 == (std::size_t(p) & Mask)); - n = pointer(std::size_t(p) | (std::size_t(n) & Mask)); + BOOST_INTRUSIVE_INVARIANT_ASSERT(0 == (uintptr_t(p) & Mask)); + n = pointer(uintptr_t(p) | (uintptr_t(n) & Mask)); } static std::size_t get_bits(pointer n) - { return (std::size_t(n) & Mask); } + { return std::size_t(uintptr_t(n) & Mask); } static void set_bits(pointer &n, std::size_t c) { - BOOST_INTRUSIVE_INVARIANT_ASSERT(c <= Mask); - n = pointer(std::size_t(get_pointer(n)) | c); + BOOST_INTRUSIVE_INVARIANT_ASSERT(uintptr_t(c) <= Mask); + n = pointer(uintptr_t((get_pointer)(n)) | uintptr_t(c)); } };