From d791fe3013a595d364f5e08e18c58c4d78544417 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Thu, 17 Jul 2014 19:51:11 -0700 Subject: [PATCH] Fix msvc static initialization in SHAMapNodeID --- src/ripple/module/app/shamap/SHAMapNodeID.cpp | 51 ++++++++++--------- src/ripple/module/app/shamap/SHAMapNodeID.h | 44 ++++------------ src/ripple/unity/app.cpp | 10 ---- 3 files changed, 37 insertions(+), 68 deletions(-) diff --git a/src/ripple/module/app/shamap/SHAMapNodeID.cpp b/src/ripple/module/app/shamap/SHAMapNodeID.cpp index d2a5d85b0e..36b13ce03e 100644 --- a/src/ripple/module/app/shamap/SHAMapNodeID.cpp +++ b/src/ripple/module/app/shamap/SHAMapNodeID.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include #include #include @@ -25,33 +26,33 @@ namespace ripple { -static std::size_t const mask_size = 65; - -static -bool -MasksInit (uint256 (&masks)[mask_size]) -{ - uint256 selector; - - for (int i = 0; i < mask_size-1; i += 2) - { - masks[i] = selector; - * (selector.begin () + (i / 2)) = 0xF0; - masks[i + 1] = selector; - * (selector.begin () + (i / 2)) = 0xFF; - } - - masks[mask_size-1] = selector; - return true; -} - -static uint256 const& -Masks (int depth) +SHAMapNodeID::Masks (int depth) { - static uint256 masks[mask_size]; - static bool initialized = MasksInit(masks); - return masks[depth]; + enum + { + mask_size = 65 + }; + + struct masks_t + { + uint256 entry [mask_size]; + + masks_t() + { + uint256 selector; + for (int i = 0; i < mask_size-1; i += 2) + { + entry[i] = selector; + * (selector.begin () + (i / 2)) = 0xF0; + entry[i + 1] = selector; + * (selector.begin () + (i / 2)) = 0xFF; + } + entry[mask_size-1] = selector; + } + }; + static beast::static_initializer masks; + return masks->entry[depth]; } // canonicalize the hash to a node ID for this depth diff --git a/src/ripple/module/app/shamap/SHAMapNodeID.h b/src/ripple/module/app/shamap/SHAMapNodeID.h index fc4aead1b0..58a075b45b 100644 --- a/src/ripple/module/app/shamap/SHAMapNodeID.h +++ b/src/ripple/module/app/shamap/SHAMapNodeID.h @@ -31,10 +31,10 @@ namespace ripple { class SHAMapNodeID { private: - uint256 mNodeID; - int mDepth; + int mDepth; mutable size_t mHash; + public: SHAMapNodeID () : mDepth (0), mHash (0) { @@ -125,14 +125,22 @@ public: } private: + static + uint256 const& + Masks (int depth); + void setMHash () const; }; +//------------------------------------------------------------------------------ + inline std::ostream& operator<< (std::ostream& out, SHAMapNodeID const& node) { return out << node.getString (); } +//------------------------------------------------------------------------------ + class SHAMapNode_hash { public: @@ -146,36 +154,6 @@ public: } }; -} // ripple - -//------------------------------------------------------------------------------ - -/* -namespace std { - -template <> -struct hash -{ - std::size_t operator() (ripple::SHAMapNodeID const& value) const - { - return value.getMHash (); - } -}; - -} -*/ - -//------------------------------------------------------------------------------ - -/* -namespace boost { - -template <> -struct hash : std::hash -{ -}; - -} -*/ +} // ripple #endif diff --git a/src/ripple/unity/app.cpp b/src/ripple/unity/app.cpp index 48f10c2e3e..0542c45ea9 100644 --- a/src/ripple/unity/app.cpp +++ b/src/ripple/unity/app.cpp @@ -70,16 +70,6 @@ int main (int argc, char** argv) "GCC version 4.8.1 or later is required to compile rippled."); #endif -#ifdef _MSC_VER - static_assert (_MSC_VER >= 1800, - "Visual Studio 2013 or later is required to compile rippled."); - // Warm up a function-local static under SHAMapNodeID to workaround - // vc++ lack of support for thread safe function-local statics - { - SHAMapNodeID node{0, uint256{}}; - } -#endif - static_assert (BOOST_VERSION >= 105500, "Boost version 1.55 or later is required to compile rippled");