mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
partial bitcoin#19277: Add Assert identity function'
Excludes fa34587f1c811d99200453b0936219c473f514b0 and fab80fef61ddd4afeff6e497c7e76bffcd05e8a4
This commit is contained in:
parent
d9c9e4764a
commit
e5897baf30
@ -27,6 +27,7 @@
|
||||
#include <tinyformat.h>
|
||||
#include <index/txindex.h>
|
||||
#include <txmempool.h>
|
||||
#include <util/check.h> // For NDEBUG compile time check
|
||||
#include <util/system.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <util/validation.h>
|
||||
@ -58,10 +59,6 @@
|
||||
|
||||
#include <statsd_client.h>
|
||||
|
||||
#if defined(NDEBUG)
|
||||
# error "Dash Core cannot be compiled without assertions."
|
||||
#endif
|
||||
|
||||
/** Maximum number of in-flight objects from a peer */
|
||||
static constexpr int32_t MAX_PEER_OBJECT_IN_FLIGHT = 100;
|
||||
/** Maximum number of announced objects from a peer */
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include <scheduler.h>
|
||||
#include <txdb.h>
|
||||
#include <txmempool.h>
|
||||
#include <util/check.h>
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
|
@ -21,7 +21,7 @@ class NonFatalCheckError : public std::runtime_error
|
||||
* - where the condition is assumed to be true, not for error handling or validating user input
|
||||
* - where a failure to fulfill the condition is recoverable and does not abort the program
|
||||
*
|
||||
* For example in RPC code, where it is undersirable to crash the whole program, this can be generally used to replace
|
||||
* For example in RPC code, where it is undesirable to crash the whole program, this can be generally used to replace
|
||||
* asserts or recoverable logic errors. A NonFatalCheckError in RPC code is caught and passed as a string to the RPC
|
||||
* caller, which can then report the issue to the developers.
|
||||
*/
|
||||
@ -38,4 +38,18 @@ class NonFatalCheckError : public std::runtime_error
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
#if defined(NDEBUG)
|
||||
#error "Cannot compile without assertions!"
|
||||
#endif
|
||||
|
||||
/** Helper for Assert(). TODO remove in C++14 and replace `decltype(get_pure_r_value(val))` with `T` (templated lambda) */
|
||||
template <typename T>
|
||||
T get_pure_r_value(T&& val)
|
||||
{
|
||||
return std::forward<T>(val);
|
||||
}
|
||||
|
||||
/** Identity function. Abort if the value compares equal to zero */
|
||||
#define Assert(val) [&]() -> decltype(get_pure_r_value(val))& { auto& check = (val); assert(#val && check); return check; }()
|
||||
|
||||
#endif // BITCOIN_UTIL_CHECK_H
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include <ui_interface.h>
|
||||
#include <uint256.h>
|
||||
#include <undo.h>
|
||||
#include <util/check.h> // For NDEBUG compile time check
|
||||
#include <util/strencodings.h>
|
||||
#include <util/translation.h>
|
||||
#include <util/validation.h>
|
||||
@ -62,10 +63,6 @@
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include <boost/thread.hpp> // Required for boost::this_thread::interruption_point();
|
||||
|
||||
#if defined(NDEBUG)
|
||||
# error "Dash Core cannot be compiled without assertions."
|
||||
#endif
|
||||
|
||||
#define MICRO 0.000001
|
||||
#define MILLI 0.001
|
||||
|
||||
|
@ -23,7 +23,7 @@ fi
|
||||
# Macro CHECK_NONFATAL(condition) should be used instead of assert for RPC code, where it
|
||||
# is undesirable to crash the whole program. See: src/util/check.h
|
||||
# src/rpc/server.cpp is excluded from this check since it's mostly meta-code.
|
||||
OUTPUT=$(git grep -nE 'assert *\(.*\);' -- "src/rpc/" "src/wallet/rpc*" ":(exclude)src/rpc/server.cpp")
|
||||
OUTPUT=$(git grep -nE '\<(A|a)ssert *\(.*\);' -- "src/rpc/" "src/wallet/rpc*" ":(exclude)src/rpc/server.cpp")
|
||||
if [[ ${OUTPUT} != "" ]]; then
|
||||
echo "CHECK_NONFATAL(condition) should be used instead of assert for RPC code."
|
||||
echo
|
||||
|
Loading…
Reference in New Issue
Block a user