Skip to content

Commit

Permalink
Fixed RasPi builds of unit tests.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
madmaxoft committed Aug 4, 2016
1 parent 69916a6 commit d1dee3c
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 44 deletions.
28 changes: 14 additions & 14 deletions src/Bindings/LuaState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1703,42 +1703,42 @@ bool cLuaState::CopyTableFrom(cLuaState & a_SrcLuaState, int a_SrcStackIdx, int
lua_pushnil(a_SrcLuaState); // SRC: <table> <key>
while (lua_next(a_SrcLuaState, -2) != 0) // SRC: <table> <key> <value>
{
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: <table> <key>
{
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: <table> <key> <value>
{
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: <table>
lua_pop(a_SrcLuaState, 1); // SRC: <table> <key>
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;
}

Expand Down
3 changes: 1 addition & 2 deletions src/Bindings/LuaState.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,7 @@ class cLuaState
{
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);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/BlockID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,9 @@ AString DamageTypeToString(eDamageType a_DamageType)

// Unknown damage type:
ASSERT(!"Unknown DamageType");
return Printf("dtUnknown_%d", static_cast<int>(a_DamageType));
#ifndef __clang__
return Printf("dtUnknown_%d", static_cast<int>(a_DamageType));
#endif
}


Expand Down
4 changes: 3 additions & 1 deletion src/ByteBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/ClientHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ AString cClientHandle::FormatMessageType(bool ShouldAppendChatPrefixes, eMessage
}
}
ASSERT(!"Unhandled chat prefix type!");
return "";
#ifndef __clang__
return "";
#endif
}


Expand Down
4 changes: 3 additions & 1 deletion src/CompositeChat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}


Expand Down
2 changes: 1 addition & 1 deletion src/Defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ enum eMobHeadRotation



inline const char * ClickActionToString(eClickAction a_ClickAction)
inline const char * ClickActionToString(int a_ClickAction)
{
switch (a_ClickAction)
{
Expand Down
4 changes: 3 additions & 1 deletion src/Entities/ArrowEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}


Expand Down
4 changes: 3 additions & 1 deletion src/Entities/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,9 @@ bool cEntity::ArmorCoversAgainst(eDamageType a_DamageType)
}
}
ASSERT(!"Invalid damage type!");
return false;
#ifndef __clang__
return false;
#endif
}


Expand Down
4 changes: 3 additions & 1 deletion src/Entities/EntityEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ cEntityEffect * cEntityEffect::CreateEntityEffect(cEntityEffect::eType a_EffectT
}

ASSERT(!"Unhandled entity effect type!");
return nullptr;
#ifndef __clang__
return nullptr;
#endif
}


Expand Down
4 changes: 3 additions & 1 deletion src/Entities/ProjectileEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}


Expand Down
19 changes: 13 additions & 6 deletions src/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,15 +370,22 @@ template class SizeChecker<UInt8, 1>;
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

Expand Down
4 changes: 3 additions & 1 deletion src/HTTP/NameValueParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,9 @@ bool cNameValueParser::Finish(void)
}
}
ASSERT(!"Unhandled parser state!");
return false;
#ifndef __clang__
return false;
#endif
}


Expand Down
8 changes: 6 additions & 2 deletions src/LinearUpscale.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ template <typename TYPE> 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;
Expand Down Expand Up @@ -198,7 +200,9 @@ template <typename TYPE> 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;
Expand Down
45 changes: 35 additions & 10 deletions src/MemorySettingsRepository.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,45 @@ class cMemorySettingsRepository : public cSettingsRepositoryInterface

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
{
Expand Down

0 comments on commit d1dee3c

Please sign in to comment.