From d1dee3c9092b7c270b297366757c9fc8d03bb0dd Mon Sep 17 00:00:00 2001 From: Mattes D Date: Tue, 2 Aug 2016 13:12:34 +0200 Subject: [PATCH] Fixed RasPi builds of unit tests. On RasPi with gcc 4.8.2, the asserts wouldn't compile when tests were enabled. Enforced the assumption that ASSERT code is generated only in Debug builds. --- src/Bindings/LuaState.cpp | 28 +++++++++---------- src/Bindings/LuaState.h | 3 +-- src/BlockID.cpp | 4 ++- src/ByteBuffer.cpp | 4 ++- src/ClientHandle.cpp | 4 ++- src/CompositeChat.cpp | 4 ++- src/Defines.h | 2 +- src/Entities/ArrowEntity.cpp | 4 ++- src/Entities/Entity.cpp | 4 ++- src/Entities/EntityEffect.cpp | 4 ++- src/Entities/ProjectileEntity.cpp | 4 ++- src/Globals.h | 19 ++++++++----- src/HTTP/NameValueParser.cpp | 4 ++- src/LinearUpscale.h | 8 ++++-- src/MemorySettingsRepository.h | 45 ++++++++++++++++++++++++------- 15 files changed, 97 insertions(+), 44 deletions(-) diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 5e6c24365..b399f9659 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -1703,42 +1703,42 @@ bool cLuaState::CopyTableFrom(cLuaState & a_SrcLuaState, int a_SrcStackIdx, int lua_pushnil(a_SrcLuaState); // SRC: while (lua_next(a_SrcLuaState, -2) != 0) // SRC:
{ - assert(lua_gettop(a_SrcLuaState) == srcTop + 3); - assert(lua_gettop(m_LuaState) == dstTop + 1); + ASSERT(lua_gettop(a_SrcLuaState) == srcTop + 3); + ASSERT(lua_gettop(m_LuaState) == dstTop + 1); // Copy the key: if (!CopySingleValueFrom(a_SrcLuaState, -2, a_NumAllowedNestingLevels)) // DST:
{ lua_pop(m_LuaState, 1); lua_pop(a_SrcLuaState, 3); - assert(lua_gettop(a_SrcLuaState) == srcTop); - assert(lua_gettop(m_LuaState) == dstTop); + ASSERT(lua_gettop(a_SrcLuaState) == srcTop); + ASSERT(lua_gettop(m_LuaState) == dstTop); return false; } - assert(lua_gettop(a_SrcLuaState) == srcTop + 3); - assert(lua_gettop(m_LuaState) == dstTop + 2); + ASSERT(lua_gettop(a_SrcLuaState) == srcTop + 3); + ASSERT(lua_gettop(m_LuaState) == dstTop + 2); // Copy the value: if (!CopySingleValueFrom(a_SrcLuaState, -1, a_NumAllowedNestingLevels - 1)) // DST:
{ lua_pop(m_LuaState, 2); // DST: empty lua_pop(a_SrcLuaState, 3); // SRC: empty - assert(lua_gettop(a_SrcLuaState) == srcTop); - assert(lua_gettop(m_LuaState) == dstTop); + ASSERT(lua_gettop(a_SrcLuaState) == srcTop); + ASSERT(lua_gettop(m_LuaState) == dstTop); return false; } - assert(lua_gettop(a_SrcLuaState) == srcTop + 3); - assert(lua_gettop(m_LuaState) == dstTop + 3); + ASSERT(lua_gettop(a_SrcLuaState) == srcTop + 3); + ASSERT(lua_gettop(m_LuaState) == dstTop + 3); // Set the value and fix up stacks: lua_rawset(m_LuaState, -3); // DST:
lua_pop(a_SrcLuaState, 1); // SRC:
- assert(lua_gettop(a_SrcLuaState) == srcTop + 2); - assert(lua_gettop(m_LuaState) == dstTop + 1); + ASSERT(lua_gettop(a_SrcLuaState) == srcTop + 2); + ASSERT(lua_gettop(m_LuaState) == dstTop + 1); } lua_pop(a_SrcLuaState, 1); // SRC: empty - assert(lua_gettop(a_SrcLuaState) == srcTop); - assert(lua_gettop(m_LuaState) == dstTop + 1); + ASSERT(lua_gettop(a_SrcLuaState) == srcTop); + ASSERT(lua_gettop(m_LuaState) == dstTop + 1); return true; } diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index 106d8a783..c34feca9d 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -256,8 +256,7 @@ public: { if (m_LuaState != nullptr) { - auto top = lua_gettop(m_LuaState); - ASSERT(m_StackLen == top); + ASSERT(m_StackLen == lua_gettop(m_LuaState)); lua_pop(m_LuaState, 1); } } diff --git a/src/BlockID.cpp b/src/BlockID.cpp index 357f6a5a4..a558db2f7 100644 --- a/src/BlockID.cpp +++ b/src/BlockID.cpp @@ -392,7 +392,9 @@ AString DamageTypeToString(eDamageType a_DamageType) // Unknown damage type: ASSERT(!"Unknown DamageType"); - return Printf("dtUnknown_%d", static_cast(a_DamageType)); + #ifndef __clang__ + return Printf("dtUnknown_%d", static_cast(a_DamageType)); + #endif } diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index 77e3f61fd..b5f862a73 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -135,7 +135,9 @@ bool cByteBuffer::Write(const void * a_Bytes, size_t a_Count) // Store the current free space for a check after writing: size_t CurFreeSpace = GetFreeSpace(); - size_t CurReadableSpace = GetReadableSpace(); + #ifdef _DEBUG + size_t CurReadableSpace = GetReadableSpace(); + #endif size_t WrittenBytes = 0; if (CurFreeSpace < a_Count) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 997510684..7dbf5a0a4 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -238,7 +238,9 @@ AString cClientHandle::FormatMessageType(bool ShouldAppendChatPrefixes, eMessage } } ASSERT(!"Unhandled chat prefix type!"); - return ""; + #ifndef __clang__ + return ""; + #endif } diff --git a/src/CompositeChat.cpp b/src/CompositeChat.cpp index d110d5908..2a112f810 100644 --- a/src/CompositeChat.cpp +++ b/src/CompositeChat.cpp @@ -284,7 +284,9 @@ cLogger::eLogLevel cCompositeChat::MessageTypeToLogLevel(eMessageType a_MessageT case mtLeave: return cLogger::llRegular; } ASSERT(!"Unhandled MessageType"); - return cLogger::llError; + #ifndef __clang__ + return cLogger::llError; + #endif } diff --git a/src/Defines.h b/src/Defines.h index 13049ce4f..615beeabd 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -203,7 +203,7 @@ enum eMobHeadRotation -inline const char * ClickActionToString(eClickAction a_ClickAction) +inline const char * ClickActionToString(int a_ClickAction) { switch (a_ClickAction) { diff --git a/src/Entities/ArrowEntity.cpp b/src/Entities/ArrowEntity.cpp index 380af101c..59d742f8d 100644 --- a/src/Entities/ArrowEntity.cpp +++ b/src/Entities/ArrowEntity.cpp @@ -67,7 +67,9 @@ bool cArrowEntity::CanPickup(const cPlayer & a_Player) const case psInCreative: return a_Player.IsGameModeCreative(); } ASSERT(!"Unhandled pickup state"); - return false; + #ifndef __clang__ + return false; + #endif } diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 98be99a27..2adbc3142 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -741,7 +741,9 @@ bool cEntity::ArmorCoversAgainst(eDamageType a_DamageType) } } ASSERT(!"Invalid damage type!"); - return false; + #ifndef __clang__ + return false; + #endif } diff --git a/src/Entities/EntityEffect.cpp b/src/Entities/EntityEffect.cpp index 9b80e6238..620be395b 100644 --- a/src/Entities/EntityEffect.cpp +++ b/src/Entities/EntityEffect.cpp @@ -217,7 +217,9 @@ cEntityEffect * cEntityEffect::CreateEntityEffect(cEntityEffect::eType a_EffectT } ASSERT(!"Unhandled entity effect type!"); - return nullptr; + #ifndef __clang__ + return nullptr; + #endif } diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 72dccbfb4..c4f705668 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -357,7 +357,9 @@ AString cProjectileEntity::GetMCAClassName(void) const case pkFishingFloat: return ""; // Unknown, perhaps MC doesn't save this? } ASSERT(!"Unhandled projectile entity kind!"); - return ""; + #ifndef __clang__ + return ""; + #endif } diff --git a/src/Globals.h b/src/Globals.h index 25d2f740e..e3a537eaa 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -370,15 +370,22 @@ template class SizeChecker; fflush(stdout); \ } #endif - #define ASSERT(x) do { if (!(x)) { throw cAssertFailure();} } while (0) - #define testassert(x) do { if (!(x)) { REPORT_ERROR("Test failure: %s, file %s, line %d\n", #x, __FILE__, __LINE__); exit(1); } } while (0) - #define CheckAsserts(x) do { try {x} catch (cAssertFailure) { break; } REPORT_ERROR("Test failure: assert didn't fire for %s, file %s, line %d\n", #x, __FILE__, __LINE__); exit(1); } while (0) + + #ifdef _DEBUG + #define ASSERT(x) do { if (!(x)) { throw cAssertFailure();} } while (0) + #define testassert(x) do { if (!(x)) { REPORT_ERROR("Test failure: %s, file %s, line %d\n", #x, __FILE__, __LINE__); exit(1); } } while (0) + #define CheckAsserts(x) do { try {x} catch (cAssertFailure) { break; } REPORT_ERROR("Test failure: assert didn't fire for %s, file %s, line %d\n", #x, __FILE__, __LINE__); exit(1); } while (0) + #else + #define ASSERT(...) + #define testassert(...) + #define CheckAsserts(...) LOG("Assert checking is disabled in Release-mode executables (file %s, line %d)", __FILE__, __LINE__) + #endif #else - #ifdef _DEBUG - #define ASSERT( x) ( !!(x) || ( LOGERROR("Assertion failed: %s, file %s, line %i", #x, __FILE__, __LINE__), PrintStackTrace(), assert(0), 0)) + #ifdef _DEBUG + #define ASSERT(x) ( !!(x) || ( LOGERROR("Assertion failed: %s, file %s, line %i", #x, __FILE__, __LINE__), PrintStackTrace(), assert(0), 0)) #else - #define ASSERT(x) ((void)(x)) + #define ASSERT(x) #endif #endif diff --git a/src/HTTP/NameValueParser.cpp b/src/HTTP/NameValueParser.cpp index f759c4d21..94df82438 100644 --- a/src/HTTP/NameValueParser.cpp +++ b/src/HTTP/NameValueParser.cpp @@ -405,7 +405,9 @@ bool cNameValueParser::Finish(void) } } ASSERT(!"Unhandled parser state!"); - return false; + #ifndef __clang__ + return false; + #endif } diff --git a/src/LinearUpscale.h b/src/LinearUpscale.h index b75cb4f82..d0c2bb41a 100644 --- a/src/LinearUpscale.h +++ b/src/LinearUpscale.h @@ -118,7 +118,9 @@ template void LinearUpscale2DArray( // Interpolate each XY cell: int DstSizeX = (a_SrcSizeX - 1) * a_UpscaleX + 1; - int DstSizeY = (a_SrcSizeY - 1) * a_UpscaleY + 1; + #ifdef _DEBUG + int DstSizeY = (a_SrcSizeY - 1) * a_UpscaleY + 1; + #endif for (int y = 0; y < (a_SrcSizeY - 1); y++) { int DstY = y * a_UpscaleY; @@ -198,7 +200,9 @@ template void LinearUpscale3DArray( // Interpolate each XYZ cell: int DstSizeX = (a_SrcSizeX - 1) * a_UpscaleX + 1; int DstSizeY = (a_SrcSizeY - 1) * a_UpscaleY + 1; - int DstSizeZ = (a_SrcSizeZ - 1) * a_UpscaleZ + 1; + #ifdef _DEBUG + int DstSizeZ = (a_SrcSizeZ - 1) * a_UpscaleZ + 1; + #endif for (int z = 0; z < (a_SrcSizeZ - 1); z++) { int DstZ = z * a_UpscaleZ; diff --git a/src/MemorySettingsRepository.h b/src/MemorySettingsRepository.h index aee4bafd4..d452ec269 100644 --- a/src/MemorySettingsRepository.h +++ b/src/MemorySettingsRepository.h @@ -53,20 +53,45 @@ private: struct sValue { - sValue(AString value) : m_Type(eType::String), m_stringValue (value) {} - sValue(Int64 value) : m_Type(eType::Int64), m_intValue(value) {} - sValue(bool value) : m_Type(eType::Bool), m_boolValue(value) {} + sValue(AString value): + #ifdef _DEBUG + m_Type(eType::String), + #endif + m_stringValue (value) + { + } + + sValue(Int64 value): + #ifdef _DEBUG + m_Type(eType::Int64), + #endif + m_intValue(value) + { + } + + sValue(bool value): + #ifdef _DEBUG + m_Type(eType::Bool), + #endif + m_boolValue(value) + { + } AString getStringValue() const { ASSERT(m_Type == eType::String); return m_stringValue; } Int64 getIntValue() const { ASSERT(m_Type == eType::Int64); return m_intValue; } bool getBoolValue() const { ASSERT(m_Type == eType::Bool); return m_boolValue; } - private: - enum class eType - { - String, - Int64, - Bool - } m_Type; + + private: + + #ifdef _DEBUG + enum class eType + { + String, + Int64, + Bool + } m_Type; + #endif + AString m_stringValue; union {