From 1682fe3a39943adff58136b89aee64a0e56921b8 Mon Sep 17 00:00:00 2001 From: Nik Bougalis Date: Tue, 11 Sep 2018 19:07:33 -0700 Subject: [PATCH] Cleanup unused Beast bits and pieces: This cleanup does not remove Boost.Beast code, but old-style Beast which is no longer relevant or helpful. --- CMakeLists.txt | 17 -- src/ripple/app/main/Main.cpp | 21 -- src/ripple/beast/core/CompilerConfig.h | 143 -------------- src/ripple/beast/core/Config.h | 1 - src/ripple/beast/core/ConfigCheck.h | 22 --- src/ripple/beast/core/LexicalCast.h | 1 + src/ripple/beast/core/StandardConfig.h | 4 - .../beast/unity/beast_utility_unity.cpp | 1 - src/ripple/beast/utility/Debug.h | 66 ------- src/ripple/beast/utility/Zero.h | 2 - src/ripple/beast/utility/src/beast_Debug.cpp | 112 ----------- src/ripple/beast/utility/weak_fn.h | 179 ------------------ src/ripple/peerfinder/impl/SlotImp.h | 1 - src/ripple/peerfinder/impl/StoreSqdb.h | 1 - src/ripple/shamap/SHAMapTreeNode.h | 5 - src/ripple/shamap/impl/SHAMapTreeNode.cpp | 11 -- src/test/beast/beast_Debug_test.cpp | 14 +- src/test/beast/beast_weak_fn_test.cpp | 147 -------------- src/test/unity/beast_test_unity2.cpp | 1 - 19 files changed, 3 insertions(+), 746 deletions(-) delete mode 100644 src/ripple/beast/core/CompilerConfig.h delete mode 100644 src/ripple/beast/utility/Debug.h delete mode 100644 src/ripple/beast/utility/src/beast_Debug.cpp delete mode 100644 src/ripple/beast/utility/weak_fn.h delete mode 100644 src/test/beast/beast_weak_fn_test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ca547dc2f..d8d19962b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -171,19 +171,12 @@ endif () option (beast_no_unit_test_inline "Prevents unit test definitions from being inserted into global table" OFF) -option (beast_force_debug - "Force BEAST_DEBUG regardless of DEBUG settings" - OFF) # NOTE - THIS OPTION CURRENTLY DOES NOT COMPILE : # TODO: fix or remove option (verify_nodeobject_keys "This verifies that the hash of node objects matches the payload. \ This check is expensive - use with caution." OFF) -option (dump_leaks_on_exit - "Displays heap blocks and counted objects which were not disposed of\ - during exit. Only implemented for windows builds." - ON) option (single_io_service_thread "Restricts the number of threads calling io_service::run to one. \ This can be useful when debugging." @@ -192,10 +185,6 @@ option (boost_show_deprecated "Allow boost to fail on deprecated usage. Only useful if you're trying\ to find deprecated calls." OFF) -# beast_check_mem_leaks can't be an option() because we want to support an -# "undefined" which means use default behavior -# option (beast_check_mem_leaks -# "Force beast mem leak checking. Default is on for DEBUG builds. Only implemented on WIN32" if (WIN32) option (beast_disable_autolink "Disables autolinking of system libraries on WIN32" OFF) else () @@ -386,10 +375,7 @@ target_compile_definitions (opts BOOST_BEAST_ALLOW_DEPRECATED BOOST_FILESYSTEM_DEPRECATED > - BEAST_CHECK_MEMORY_LEAKS=$ - RIPPLE_DUMP_LEAKS_ON_EXIT=$ $<$:BEAST_NO_UNIT_TEST_INLINE=1> - $<$:BEAST_FORCE_DEBUG=1> $<$:BEAST_DONT_AUTOLINK_TO_WIN32_LIBRARIES=1> $<$:RIPPLE_SINGLE_IO_SERVICE_THREAD=1> # doesn't currently compile ? : @@ -1327,7 +1313,6 @@ else () src/ripple/beast/net/impl/IPAddressV4.cpp src/ripple/beast/net/impl/IPAddressV6.cpp src/ripple/beast/net/impl/IPEndpoint.cpp - src/ripple/beast/utility/src/beast_Debug.cpp src/ripple/beast/utility/src/beast_Journal.cpp src/ripple/beast/utility/src/beast_PropertyStream.cpp) endif () @@ -1558,7 +1543,6 @@ install ( DESTINATION include/ripple/beast/clock) install ( FILES - src/ripple/beast/core/CompilerConfig.h src/ripple/beast/core/Config.h src/ripple/beast/core/ConfigCheck.h src/ripple/beast/core/LexicalCast.h @@ -2081,7 +2065,6 @@ else () src/test/beast/beast_asio_error_test.cpp src/test/beast/beast_basic_seconds_clock_test.cpp src/test/beast/beast_io_latency_probe_test.cpp - src/test/beast/beast_weak_fn_test.cpp src/test/beast/define_print.cpp #[===============================[ nounity, test sources: diff --git a/src/ripple/app/main/Main.cpp b/src/ripple/app/main/Main.cpp index 90300dc1d7..79a0902d6e 100644 --- a/src/ripple/app/main/Main.cpp +++ b/src/ripple/app/main/Main.cpp @@ -37,7 +37,6 @@ #include #include #include -#include #include #include @@ -766,26 +765,6 @@ int main (int argc, char** argv) "GCC version 5.1.0 or later is required to compile rippled."); #endif - // - // These debug heap calls do nothing in release or non Visual Studio builds. - // - - // Checks the heap at every allocation and deallocation (slow). - // - //beast::Debug::setAlwaysCheckHeap (false); - - // Keeps freed memory blocks and fills them with a guard value. - // - //beast::Debug::setHeapDelayedFree (false); - - // At exit, reports all memory blocks which have not been freed. - // -#if RIPPLE_DUMP_LEAKS_ON_EXIT - beast::Debug::setHeapReportLeaks (true); -#else - beast::Debug::setHeapReportLeaks (false); -#endif - atexit(&google::protobuf::ShutdownProtobufLibrary); std::set_terminate(ripple::terminateHandler); diff --git a/src/ripple/beast/core/CompilerConfig.h b/src/ripple/beast/core/CompilerConfig.h deleted file mode 100644 index 9a7590b0ee..0000000000 --- a/src/ripple/beast/core/CompilerConfig.h +++ /dev/null @@ -1,143 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2013, Vinnie Falco - - Portions of this file are from JUCE. - Copyright (c) 2013 - Raw Material Software Ltd. - Please visit http://www.juce.com - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#ifndef BEAST_CONFIG_COMPILERCONFIG_H_INCLUDED -#define BEAST_CONFIG_COMPILERCONFIG_H_INCLUDED - -#include -#include - -// This file defines miscellaneous macros for debugging, assertions, etc. - -#if BEAST_FORCE_DEBUG -# undef BEAST_DEBUG -# define BEAST_DEBUG 1 -#endif - -/** This macro defines the C calling convention used as the standard for Beast calls. -*/ -#if BEAST_MSVC -# define BEAST_CDECL __cdecl -#else -# define BEAST_CDECL -#endif - -//------------------------------------------------------------------------------ - -#if ! DOXYGEN - #define BEAST_JOIN_MACRO_HELPER(a, b) a ## b - #define BEAST_STRINGIFY_MACRO_HELPER(a) #a -#endif - -/** A good old-fashioned C macro concatenation helper. - This combines two items (which may themselves be macros) into a single string, - avoiding the pitfalls of the ## macro operator. -*/ -#define BEAST_JOIN_MACRO(item1, item2) BEAST_JOIN_MACRO_HELPER (item1, item2) - -/** A handy C macro for stringifying any symbol, rather than just a macro parameter. -*/ -#define BEAST_STRINGIFY(item) BEAST_STRINGIFY_MACRO_HELPER (item) - -//------------------------------------------------------------------------------ - -#if BEAST_MSVC || DOXYGEN -/** This can be placed before a stack or member variable declaration to tell - the compiler to align it to the specified number of bytes. -*/ -#define BEAST_ALIGN(bytes) __declspec (align (bytes)) -#else -#define BEAST_ALIGN(bytes) __attribute__ ((aligned (bytes))) -#endif - -//------------------------------------------------------------------------------ - -// Cross-compiler deprecation macros.. -#ifdef DOXYGEN - /** This macro can be used to wrap a function which has been deprecated. */ - #define BEAST_DEPRECATED(functionDef) -#elif BEAST_MSVC && ! BEAST_NO_DEPRECATION_WARNINGS - #define BEAST_DEPRECATED(functionDef) __declspec(deprecated) functionDef -#elif BEAST_GCC && ! BEAST_NO_DEPRECATION_WARNINGS - #define BEAST_DEPRECATED(functionDef) functionDef __attribute__ ((deprecated)) -#else - #define BEAST_DEPRECATED(functionDef) functionDef -#endif - -//------------------------------------------------------------------------------ - -#if BEAST_GCC -# define BEAST_PACKED __attribute__((packed)) -#elif ! DOXYGEN -# define BEAST_PACKED -#endif - -//------------------------------------------------------------------------------ - -// Here, we'll check for C++11 compiler support, and if it's not available, define -// a few workarounds, so that we can still use some of the newer language features. -#if defined (__GXX_EXPERIMENTAL_CXX0X__) && defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 405 -# define BEAST_COMPILER_SUPPORTS_NOEXCEPT 1 -# define BEAST_COMPILER_SUPPORTS_NULLPTR 1 -# define BEAST_COMPILER_SUPPORTS_MOVE_SEMANTICS 1 -# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 407 && ! defined (BEAST_COMPILER_SUPPORTS_OVERRIDE_AND_FINAL) -# define BEAST_COMPILER_SUPPORTS_OVERRIDE_AND_FINAL 1 -# endif -#endif - -#if BEAST_CLANG && defined (__has_feature) -# if __has_feature (cxx_nullptr) -# define BEAST_COMPILER_SUPPORTS_NULLPTR 1 -# endif -# if __has_feature (cxx_noexcept) -# define BEAST_COMPILER_SUPPORTS_NOEXCEPT 1 -# endif -# if __has_feature (cxx_rvalue_references) -# define BEAST_COMPILER_SUPPORTS_MOVE_SEMANTICS 1 -# endif -# ifndef BEAST_COMPILER_SUPPORTS_OVERRIDE_AND_FINAL -# define BEAST_COMPILER_SUPPORTS_OVERRIDE_AND_FINAL 1 -# endif -# ifndef BEAST_COMPILER_SUPPORTS_ARC -# define BEAST_COMPILER_SUPPORTS_ARC 1 -# endif -#endif - -#if defined (_MSC_VER) && _MSC_VER >= 1600 -# define BEAST_COMPILER_SUPPORTS_NULLPTR 1 -# define BEAST_COMPILER_SUPPORTS_MOVE_SEMANTICS 1 -#endif - -#if defined (_MSC_VER) && _MSC_VER >= 1700 -# define BEAST_COMPILER_SUPPORTS_OVERRIDE_AND_FINAL 1 -#endif - -#if BEAST_COMPILER_SUPPORTS_MOVE_SEMANTICS -# define BEAST_MOVE_ARG(type) type&& -# define BEAST_MOVE_CAST(type) static_cast -#else -# define BEAST_MOVE_ARG(type) type -# define BEAST_MOVE_CAST(type) type -#endif - -#endif diff --git a/src/ripple/beast/core/Config.h b/src/ripple/beast/core/Config.h index c343bbc30f..c98951582c 100644 --- a/src/ripple/beast/core/Config.h +++ b/src/ripple/beast/core/Config.h @@ -25,7 +25,6 @@ #define BEAST_CONFIG_H_INCLUDED #include -#include #include #include diff --git a/src/ripple/beast/core/ConfigCheck.h b/src/ripple/beast/core/ConfigCheck.h index 0c44837ef8..74423471df 100644 --- a/src/ripple/beast/core/ConfigCheck.h +++ b/src/ripple/beast/core/ConfigCheck.h @@ -24,28 +24,6 @@ // Apply sensible defaults for the configuration settings // -#ifndef BEAST_FORCE_DEBUG -#define BEAST_FORCE_DEBUG 0 -#endif - -#ifndef BEAST_LOG_ASSERTIONS -# if BEAST_ANDROID -# define BEAST_LOG_ASSERTIONS 1 -# else -# define BEAST_LOG_ASSERTIONS 0 -# endif -#endif - -#if BEAST_DEBUG && ! defined (BEAST_CHECK_MEMORY_LEAKS) -#define BEAST_CHECK_MEMORY_LEAKS 1 -#endif - -#ifndef BEAST_DISABLE_CONTRACT_CHECKS -#define BEAST_DISABLE_CONTRACT_CHECKS 0 -#endif - -//------------------------------------------------------------------------------ - #ifndef BEAST_DONT_AUTOLINK_TO_WIN32_LIBRARIES #define BEAST_DONT_AUTOLINK_TO_WIN32_LIBRARIES 0 #endif diff --git a/src/ripple/beast/core/LexicalCast.h b/src/ripple/beast/core/LexicalCast.h index c20015a4f6..e104b94b7a 100644 --- a/src/ripple/beast/core/LexicalCast.h +++ b/src/ripple/beast/core/LexicalCast.h @@ -22,6 +22,7 @@ #include #include +#include #include #include #include diff --git a/src/ripple/beast/core/StandardConfig.h b/src/ripple/beast/core/StandardConfig.h index c2cb0cc1b2..c9e44a5b49 100644 --- a/src/ripple/beast/core/StandardConfig.h +++ b/src/ripple/beast/core/StandardConfig.h @@ -24,10 +24,6 @@ #ifndef BEAST_CONFIG_STANDARDCONFIG_H_INCLUDED #define BEAST_CONFIG_STANDARDCONFIG_H_INCLUDED -#ifndef BEAST_CONFIG_COMPILERCONFIG_H_INCLUDED -#error "CompilerConfig.h must be included first" -#endif - // Now we'll include some common OS headers.. #if BEAST_MSVC #pragma warning (push) diff --git a/src/ripple/beast/unity/beast_utility_unity.cpp b/src/ripple/beast/unity/beast_utility_unity.cpp index 4c24ae3015..1b6d5db284 100644 --- a/src/ripple/beast/unity/beast_utility_unity.cpp +++ b/src/ripple/beast/unity/beast_utility_unity.cpp @@ -17,6 +17,5 @@ */ //============================================================================== -#include #include #include diff --git a/src/ripple/beast/utility/Debug.h b/src/ripple/beast/utility/Debug.h deleted file mode 100644 index 69ab73f41b..0000000000 --- a/src/ripple/beast/utility/Debug.h +++ /dev/null @@ -1,66 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2013, Vinnie Falco - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#ifndef BEAST_UTILITY_DEBUG_H_INCLUDED -#define BEAST_UTILITY_DEBUG_H_INCLUDED - -#include - -namespace beast { - -// Auxiliary outines for debugging - -namespace Debug -{ - -// -// These control the MSVC C Runtime Debug heap. -// -// The calls currently do nothing on other platforms. -// - -/** Calls checkHeap() at every allocation and deallocation. -*/ -extern void setAlwaysCheckHeap (bool bAlwaysCheck); - -/** Keep freed memory blocks in the heap's linked list, assign them the - _FREE_BLOCK type, and fill them with the byte value 0xDD. -*/ -extern void setHeapDelayedFree (bool bDelayedFree); - -/** Perform automatic leak checking at program exit through a call to - dumpMemoryLeaks() and generate an error report if the application - failed to free all the memory it allocated. -*/ -extern void setHeapReportLeaks (bool bReportLeaks); - -/** Report all memory blocks which have not been freed. -*/ -extern void reportLeaks (); - -/** Confirms the integrity of the memory blocks allocated in the - debug heap (debug version only. -*/ -extern void checkHeap (); - -} - -} - -#endif diff --git a/src/ripple/beast/utility/Zero.h b/src/ripple/beast/utility/Zero.h index 7411aae516..d231747499 100644 --- a/src/ripple/beast/utility/Zero.h +++ b/src/ripple/beast/utility/Zero.h @@ -20,8 +20,6 @@ #ifndef BEAST_UTILITY_ZERO_H_INCLUDED #define BEAST_UTILITY_ZERO_H_INCLUDED -#include - namespace beast { /** Zero allows classes to offer efficient comparisons to zero. diff --git a/src/ripple/beast/utility/src/beast_Debug.cpp b/src/ripple/beast/utility/src/beast_Debug.cpp deleted file mode 100644 index 8be4b2b21e..0000000000 --- a/src/ripple/beast/utility/src/beast_Debug.cpp +++ /dev/null @@ -1,112 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2013, Vinnie Falco - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#include - -namespace beast { - -namespace Debug { - -//------------------------------------------------------------------------------ - -#if BEAST_MSVC && defined (_DEBUG) - -#if BEAST_CHECK_MEMORY_LEAKS -struct DebugFlagsInitialiser -{ - DebugFlagsInitialiser() - { - // Activate leak checks on exit in the MSVC Debug CRT (C Runtime) - // - _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); - } -}; - -static DebugFlagsInitialiser debugFlagsInitialiser; -#endif - -void setAlwaysCheckHeap (bool bAlwaysCheck) -{ - int flags = _CrtSetDbgFlag (_CRTDBG_REPORT_FLAG); - - if (bAlwaysCheck) flags |= _CRTDBG_CHECK_ALWAYS_DF; // on - else flags &= ~_CRTDBG_CHECK_ALWAYS_DF; // off - - _CrtSetDbgFlag (flags); -} - -void setHeapDelayedFree (bool bDelayedFree) -{ - int flags = _CrtSetDbgFlag (_CRTDBG_REPORT_FLAG); - - if (bDelayedFree) flags |= _CRTDBG_DELAY_FREE_MEM_DF; // on - else flags &= ~_CRTDBG_DELAY_FREE_MEM_DF; // off - - _CrtSetDbgFlag (flags); -} - -void setHeapReportLeaks (bool bReportLeaks) -{ - int flags = _CrtSetDbgFlag (_CRTDBG_REPORT_FLAG); - - if (bReportLeaks) flags |= _CRTDBG_LEAK_CHECK_DF; // on - else flags &= ~_CRTDBG_LEAK_CHECK_DF; // off - - _CrtSetDbgFlag (flags); -} - -void reportLeaks () -{ - _CrtDumpMemoryLeaks (); -} - -void checkHeap () -{ - _CrtCheckMemory (); -} - -//------------------------------------------------------------------------------ - -#else - -void setAlwaysCheckHeap (bool) -{ -} - -void setHeapDelayedFree (bool) -{ -} - -void setHeapReportLeaks (bool) -{ -} - -void reportLeaks () -{ -} - -void checkHeap () -{ -} - -#endif - -} - -} diff --git a/src/ripple/beast/utility/weak_fn.h b/src/ripple/beast/utility/weak_fn.h deleted file mode 100644 index f53b70844e..0000000000 --- a/src/ripple/beast/utility/weak_fn.h +++ /dev/null @@ -1,179 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2014, Vinnie Falco - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#ifndef BEAST_WEAK_FN_H_INCLUDED -#define BEAST_WEAK_FN_H_INCLUDED - -#include -#include - -// Original version: -// http://lists.boost.org/Archives/boost/att-189469/weak_fn.hpp -// -// This work was adapted from source code with this copyright notice: -// -// weak_fun.hpp -// -// Copyright (c) 2009 Artyom Beilis -// -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// - -namespace beast { - -// Policy throws if weak pointer is expired -template -struct throw_if_invalid -{ - explicit throw_if_invalid() = default; - - V operator()() const - { - throw std::bad_weak_ptr(); - } -}; - -// Policy returns a value if weak pointer is expired -template -struct return_default_if_invalid -{ - return_default_if_invalid() - : def_value_() - { } - - return_default_if_invalid(V def_value) - : def_value_(def_value) - { } - - V operator()() const - { - return def_value_; - } - -private: - V def_value_; -}; - -// Policy does nothing if weak pointer is expired -template -struct ignore_if_invalid -{ - explicit ignore_if_invalid() = default; - - V operator()() const - { - return V(); - } -}; - -template -using default_invalid_policy = ignore_if_invalid; - -namespace detail { - -template -class weak_binder - : private boost::beast::detail::empty_base_optimization -{ -private: - using member_type = R (T::*)(Args...); - using pointer_type = std::weak_ptr; - using shared_type = std::shared_ptr; - member_type member_; - pointer_type object_; - -public: - using result_type = R; - - weak_binder (member_type member, - Policy policy, pointer_type object) - : boost::beast::detail::empty_base_optimization(std::move(policy)) - , member_(member) - , object_(object) - { } - - R operator()(Args... args) - { - if(auto p = object_.lock()) - return ((*p).*member_)(args...); - return this->member()(); - } -}; - -} // detail - -/** Returns a callback that can be used with std::bind and a weak_ptr. - When called, it tries to lock weak_ptr to get a shared_ptr. If successful, - it calls given member function with given arguments. If not successful, - the policy functor is called. Built-in policies are: - - ignore_if_invalid does nothing - throw_if_invalid throws `bad_weak_ptr` - return_default_if_invalid returns a chosen value - - Example: - - struct Foo { - void bar(int i) { - std::cout << i << std::endl; - } - }; - - struct do_something { - void operator()() { - std::cout << "outdated reference" << std::endl; - } - }; - - int main() - { - std::shared_ptr sp(new Foo()); - std::weak_ptr wp(sp); - - std::bind(weak_fn(&Foo::bar, wp), _1)(1); - sp.reset(); - std::bind(weak_fn(&Foo::bar, wp), 1)(); - std::bind(weak_fn(&Foo::bar, wp, do_something()), 1)(); - } -*/ -/** @{ */ -template -detail::weak_binder -weak_fn (R (T::*member)(Args...), std::shared_ptr p, - Policy policy) -{ - return detail::weak_binder(member, policy, p); -} - -template -detail::weak_binder, Args...> -weak_fn (R (T::*member)(Args...), std::shared_ptr p) -{ - return detail::weak_binder, Args...>(member, - default_invalid_policy{}, p); -} -/** @} */ - -} // beast - -#endif diff --git a/src/ripple/peerfinder/impl/SlotImp.h b/src/ripple/peerfinder/impl/SlotImp.h index 3c0c454961..298d766789 100644 --- a/src/ripple/peerfinder/impl/SlotImp.h +++ b/src/ripple/peerfinder/impl/SlotImp.h @@ -22,7 +22,6 @@ #include #include -#include #include #include #include diff --git a/src/ripple/peerfinder/impl/StoreSqdb.h b/src/ripple/peerfinder/impl/StoreSqdb.h index 4510e3b178..243e84e24b 100644 --- a/src/ripple/peerfinder/impl/StoreSqdb.h +++ b/src/ripple/peerfinder/impl/StoreSqdb.h @@ -22,7 +22,6 @@ #include #include -#include #include namespace ripple { diff --git a/src/ripple/shamap/SHAMapTreeNode.h b/src/ripple/shamap/SHAMapTreeNode.h index 882a76b91c..3122d42653 100644 --- a/src/ripple/shamap/SHAMapTreeNode.h +++ b/src/ripple/shamap/SHAMapTreeNode.h @@ -135,11 +135,6 @@ public: make(Slice const& rawNode, std::uint32_t seq, SHANodeFormat format, SHAMapHash const& hash, bool hashValid, beast::Journal j, SHAMapNodeID const& id = SHAMapNodeID{}); - - // debugging -#ifdef BEAST_DEBUG - static void dump (SHAMapNodeID const&, beast::Journal journal); -#endif }; class SHAMapInnerNodeV2; diff --git a/src/ripple/shamap/impl/SHAMapTreeNode.cpp b/src/ripple/shamap/impl/SHAMapTreeNode.cpp index 1aa8f4d879..0222db491c 100644 --- a/src/ripple/shamap/impl/SHAMapTreeNode.cpp +++ b/src/ripple/shamap/impl/SHAMapTreeNode.cpp @@ -600,17 +600,6 @@ int SHAMapInnerNode::getBranchCount () const return count; } -#ifdef BEAST_DEBUG - -void -SHAMapAbstractNode::dump(const SHAMapNodeID & id, beast::Journal journal) -{ - JLOG(journal.debug()) << - "SHAMapTreeNode(" << id.getNodeID () << ")"; -} - -#endif // BEAST_DEBUG - std::string SHAMapAbstractNode::getString(const SHAMapNodeID & id) const { diff --git a/src/test/beast/beast_Debug_test.cpp b/src/test/beast/beast_Debug_test.cpp index c9a68204b5..b5d168c740 100644 --- a/src/test/beast/beast_Debug_test.cpp +++ b/src/test/beast/beast_Debug_test.cpp @@ -17,7 +17,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ //============================================================================== #include -#include + namespace beast { // A simple unit test to determine the diagnostic settings in a build. @@ -43,21 +43,11 @@ public: #endif } - static int beastForceDebug() - { -#ifdef BEAST_FORCE_DEBUG - return BEAST_FORCE_DEBUG; -#else - return 0; -#endif - } - void run() override { log << "_DEBUG = " << envDebug() << '\n' << "BEAST_DEBUG = " << beastDebug() << '\n' << - "BEAST_FORCE_DEBUG = " << beastForceDebug() << '\n' << "sizeof(std::size_t) = " << sizeof(std::size_t) << std::endl; pass(); } @@ -65,4 +55,4 @@ public: BEAST_DEFINE_TESTSUITE(Debug, utility, beast); -} \ No newline at end of file +} diff --git a/src/test/beast/beast_weak_fn_test.cpp b/src/test/beast/beast_weak_fn_test.cpp deleted file mode 100644 index d913f7e68b..0000000000 --- a/src/test/beast/beast_weak_fn_test.cpp +++ /dev/null @@ -1,147 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2013, Vinnie Falco - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#include -#include - -namespace beast { - -class weak_fn_test : public beast::unit_test::suite -{ -public: - struct T - { - bool& called_; - - explicit - T (bool& called) - : called_(called) - { - } - - void - fv() - { - called_ = true; - } - - void - fi(int i) - { - called_ = true; - } - - void - fis(int, std::string) - { - called_ = true; - } - - int - fri() - { - called_ = true; - return 2; - } - }; - - void - run() override - { - { - bool called = false; - auto const p = std::make_shared(called); - std::bind(weak_fn(&T::fv, p))(); - BEAST_EXPECT(called); - } - - { - bool called = false; - auto p = std::make_shared(called); - auto call = std::bind(weak_fn(&T::fv, p)); - p.reset(); - call(); - BEAST_EXPECT(! called); - } - - { - bool called = false; - auto p = std::make_shared(called); - std::bind(weak_fn(&T::fi, p), 1)(); - BEAST_EXPECT(called); - } - - { - bool called = false; - auto p = std::make_shared(called); - std::bind(weak_fn(&T::fi, p), - std::placeholders::_1)(1); - BEAST_EXPECT(called); - } - - { - bool called = false; - auto p = std::make_shared(called); - std::bind(weak_fn(&T::fis, p), - 1, std::placeholders::_1)("foo"); - BEAST_EXPECT(called); - } - - { - bool called = false; - auto p = std::make_shared(called); - try - { - auto call = std::bind(weak_fn(&T::fis, p, throw_if_invalid<>()), - 1, std::placeholders::_1); - p.reset(); - call("foo"); - fail(); - } - catch(std::bad_weak_ptr const&) - { - BEAST_EXPECT(! called); - } - } - - { - bool called = false; - auto p = std::make_shared(called); - BEAST_EXPECT(std::bind(weak_fn(&T::fri, p))() == 2); - BEAST_EXPECT(called); - } - - { - bool called = false; - auto p = std::make_shared(called); - auto call = std::bind(weak_fn(&T::fv, p, - [&called]() - { - called = true; - })); - p.reset(); - call(); - BEAST_EXPECT(called); - } - } -}; - -BEAST_DEFINE_TESTSUITE(weak_fn,asio,beast); - -} diff --git a/src/test/unity/beast_test_unity2.cpp b/src/test/unity/beast_test_unity2.cpp index edc1ceb269..1e384c0668 100644 --- a/src/test/unity/beast_test_unity2.cpp +++ b/src/test/unity/beast_test_unity2.cpp @@ -18,7 +18,6 @@ */ //============================================================================== -#include #include #include #include