From eb5691e8faa5ec20ba5d5dd9bb1944bebca6bc51 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Thu, 6 Feb 2014 11:38:39 -0800 Subject: [PATCH] Change bassert to always call assert --- Builds/VisualStudio2013/beast.vcxproj | 6 +++ Builds/VisualStudio2013/beast.vcxproj.filters | 3 ++ beast/config/CompilerConfig.h | 8 ++++ beast/crypto/UnsignedIntegerCalc.h | 2 +- beast/utility/Utility.cpp | 1 + beast/utility/impl/Assert.cpp | 37 +++++++++++++++++++ modules/beast_core/diagnostic/UnitTest.cpp | 2 +- modules/beast_core/xml/XmlElement.cpp | 2 +- 8 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 beast/utility/impl/Assert.cpp diff --git a/Builds/VisualStudio2013/beast.vcxproj b/Builds/VisualStudio2013/beast.vcxproj index f883a8a237..95c59990fc 100644 --- a/Builds/VisualStudio2013/beast.vcxproj +++ b/Builds/VisualStudio2013/beast.vcxproj @@ -657,6 +657,12 @@ true + + true + true + true + true + true true diff --git a/Builds/VisualStudio2013/beast.vcxproj.filters b/Builds/VisualStudio2013/beast.vcxproj.filters index 36c5a3064a..62d93d70e3 100644 --- a/Builds/VisualStudio2013/beast.vcxproj.filters +++ b/Builds/VisualStudio2013/beast.vcxproj.filters @@ -1844,6 +1844,9 @@ beast\net\impl + + beast\utility\impl + diff --git a/beast/config/CompilerConfig.h b/beast/config/CompilerConfig.h index 217df60400..6b42d30277 100644 --- a/beast/config/CompilerConfig.h +++ b/beast/config/CompilerConfig.h @@ -30,6 +30,8 @@ #error "PlatformConfig.h must come first!" #endif +#include + // This file defines miscellaneous macros for debugging, assertions, etc. #if BEAST_FORCE_DEBUG @@ -109,6 +111,7 @@ extern void beast_reportFatalError (char const* message, char const* fileName, i */ #define BDBG(dbgtext) { beast::String tempDbgBuf; tempDbgBuf << dbgtext; beast::Logger::outputDebugString (tempDbgBuf); } +#if 0 /** This will always cause an assertion failure. It is only compiled in a debug build, (unless BEAST_LOG_ASSERTIONS is enabled for your build). @see bassert @@ -122,6 +125,11 @@ extern void beast_reportFatalError (char const* message, char const* fileName, i @see bassertfalse */ #define bassert(expression) { if (! (expression)) beast_reportFatalError(#expression,__FILE__,__LINE__); } +#else + +#define bassertfalse assert(false) +#define bassert(expression) assert(expression) +#endif #else diff --git a/beast/crypto/UnsignedIntegerCalc.h b/beast/crypto/UnsignedIntegerCalc.h index de3ea63d7e..fffadfab78 100644 --- a/beast/crypto/UnsignedIntegerCalc.h +++ b/beast/crypto/UnsignedIntegerCalc.h @@ -334,7 +334,7 @@ public: } *lhs++ = UInt (part); } - bassert (carry == 0) // overflow + bassert (carry == 0); // overflow return *this; } diff --git a/beast/utility/Utility.cpp b/beast/utility/Utility.cpp index e2b254bfdb..baeef86815 100644 --- a/beast/utility/Utility.cpp +++ b/beast/utility/Utility.cpp @@ -24,6 +24,7 @@ // For Journal and Debug #include "../../modules/beast_core/beast_core.h" +#include "impl/Assert.cpp" #include "impl/Debug.cpp" #include "impl/Journal.cpp" #include "impl/LeakChecked.cpp" diff --git a/beast/utility/impl/Assert.cpp b/beast/utility/impl/Assert.cpp new file mode 100644 index 0000000000..d7503cc21f --- /dev/null +++ b/beast/utility/impl/Assert.cpp @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +/* + 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. +*/ +//============================================================================== + +namespace beast { + +class BassertUnitTests : public UnitTest +{ +public: + void runTest () + { + beginTestCase ("bassert"); + bassert (false); + } + + BassertUnitTests () : UnitTest ("bassert", "beast", runManual) { } +}; + +//------------------------------------------------------------------------------ + +static BassertUnitTests bassertUnitTests; +} diff --git a/modules/beast_core/diagnostic/UnitTest.cpp b/modules/beast_core/diagnostic/UnitTest.cpp index 324dd4e37d..94d74f5d22 100644 --- a/modules/beast_core/diagnostic/UnitTest.cpp +++ b/modules/beast_core/diagnostic/UnitTest.cpp @@ -393,7 +393,7 @@ void UnitTests::runTests (TestList const& tests, int64 randomSeed) void UnitTests::onFailure () { // A failure occurred and the setting to assert on failures is turned on. - bassert (! m_assertOnFailure) + bassert (! m_assertOnFailure); } bool UnitTests::shouldAbortTests() diff --git a/modules/beast_core/xml/XmlElement.cpp b/modules/beast_core/xml/XmlElement.cpp index 7487075086..cfa5de5a28 100644 --- a/modules/beast_core/xml/XmlElement.cpp +++ b/modules/beast_core/xml/XmlElement.cpp @@ -47,7 +47,7 @@ XmlElement::XmlElement (const String& tag) noexcept : tagName (tag) { // the tag name mustn't be empty, or it'll look like a text element! - bassert (tag.containsNonWhitespaceChars()) + bassert (tag.containsNonWhitespaceChars()); // The tag can't contain spaces or other characters that would create invalid XML! bassert (! tag.containsAnyOf (" <>/&"));