Skip to content

Commit

Permalink
21053: Adds additional debugging capabilities related to AMALGAM_FAST…
Browse files Browse the repository at this point in the history
…_MEMORY_INTEGRITY and catching asserts (#199)
  • Loading branch information
howsohazard authored Jul 26, 2024
1 parent 280efff commit 9738dde
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 37 deletions.
28 changes: 12 additions & 16 deletions src/Amalgam/PlatformSpecific.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,23 +223,19 @@ inline void Platform_Assert(bool expr, const char *file, int line)
std::cerr << "Runtime Exception: Debug Assertion Failed at line " << line << " of " << file << "\n";

//platform dependent assertion function
#ifdef _DEBUG

#ifdef OS_WINDOWS
_ASSERT(expr);
#else
raise(SIGTRAP);
#endif
exit(-1);

#ifdef OS_WINDOWS
_ASSERT(expr);
#else
if(Platform_IsDebuggerPresent())
{
//wait for user input
std::string temp;
std::getline(std::cin, temp);
}
exit(-1);
raise(SIGTRAP);
#endif

if(Platform_IsDebuggerPresent())
{
//wait for user input in case the _ASSERT above was optimized out
std::string temp;
std::getline(std::cin, temp);
}

exit(-1);
}
}
3 changes: 1 addition & 2 deletions src/Amalgam/evaluablenode/EvaluableNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1565,8 +1565,7 @@ void EvaluableNode::DestructValue()
void EvaluableNode::Invalidate()
{
#ifdef AMALGAM_FAST_MEMORY_INTEGRITY
if(IsNodeDeallocated())
assert(false);
assert(!IsNodeDeallocated());
#endif

if(!HasExtendedValue())
Expand Down
35 changes: 16 additions & 19 deletions src/Amalgam/evaluablenode/EvaluableNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,41 +233,41 @@ class EvaluableNode
static bool IsTrue(EvaluableNode *n);

//Returns true if the node is some form of associative array
constexpr bool IsAssociativeArray()
__forceinline bool IsAssociativeArray()
{
return DoesEvaluableNodeTypeUseAssocData(GetType());
}

//Returns true if the node is some form of associative array
static constexpr bool IsAssociativeArray(EvaluableNode *n)
static __forceinline bool IsAssociativeArray(EvaluableNode *n)
{
if(n == nullptr)
return false;
return n->IsAssociativeArray();
}

//returns true if the type is immediate
constexpr bool IsImmediate()
__forceinline bool IsImmediate()
{
return IsEvaluableNodeTypeImmediate(GetType());
}

//Returns true if the node is some form of ordered array
constexpr bool IsOrderedArray()
__forceinline bool IsOrderedArray()
{
return DoesEvaluableNodeTypeUseOrderedData(GetType());
}

//Returns true if the node is some form of ordered array
static constexpr bool IsOrderedArray(EvaluableNode *n)
static __forceinline bool IsOrderedArray(EvaluableNode *n)
{
if(n == nullptr)
return false;
return n->IsOrderedArray();
}

//returns true if the EvaluableNode is of a query type
static constexpr bool IsQuery(EvaluableNode *n)
static __forceinline bool IsQuery(EvaluableNode *n)
{
return (n != nullptr && IsEvaluableNodeTypeQuery(n->GetType()));
}
Expand Down Expand Up @@ -299,7 +299,7 @@ class EvaluableNode

//if the node's contents can be represented as a number, which includes numbers, infinity, then return true
// otherwise returns false
static constexpr bool CanRepresentValueAsANumber(EvaluableNode *e)
static __forceinline bool CanRepresentValueAsANumber(EvaluableNode *e)
{
if(e == nullptr)
return true;
Expand All @@ -317,7 +317,7 @@ class EvaluableNode
}

//returns true is node pointer e is nullptr or value of e has type ENT_NULL
static constexpr bool IsNull(EvaluableNode *e)
static __forceinline bool IsNull(EvaluableNode *e)
{
return (e == nullptr || e->GetType() == ENT_NULL);
}
Expand All @@ -327,7 +327,7 @@ class EvaluableNode
static double ToNumber(EvaluableNode *e, double value_if_null = std::numeric_limits<double>::quiet_NaN());

//returns true if the node can directly be interpreted as a number
static constexpr bool IsNumericOrNull(EvaluableNode *e)
static __forceinline bool IsNumericOrNull(EvaluableNode *e)
{
if(e == nullptr)
return true;
Expand All @@ -340,7 +340,7 @@ class EvaluableNode
}

//returns true if the EvaluableNode uses numeric data
constexpr bool IsNumericOrNull()
__forceinline bool IsNumericOrNull()
{
return DoesEvaluableNodeTypeUseNumberData(GetType());
}
Expand Down Expand Up @@ -419,13 +419,10 @@ class EvaluableNode
static size_t GetEstimatedNodeSizeInBytes(EvaluableNode *n);

//gets current type
constexpr EvaluableNodeType &GetType()
__forceinline EvaluableNodeType &GetType()
{
#ifdef AMALGAM_FAST_MEMORY_INTEGRITY
if(type == ENT_DEALLOCATED)
{
assert(false);
}
assert(type != ENT_DEALLOCATED);
#endif
return type;
}
Expand Down Expand Up @@ -456,7 +453,7 @@ class EvaluableNode
void InitNumberValue();

//gets the value by reference
constexpr double &GetNumberValue()
__forceinline double &GetNumberValue()
{
if(DoesEvaluableNodeTypeUseNumberData(GetType()))
return GetNumberValueReference();
Expand All @@ -481,7 +478,7 @@ class EvaluableNode

//sets up the ability to contain a string
void InitStringValue();
constexpr StringInternPool::StringID GetStringID()
__forceinline StringInternPool::StringID GetStringID()
{
if(DoesEvaluableNodeTypeUseStringData(GetType()))
return GetStringIDReference();
Expand Down Expand Up @@ -650,7 +647,7 @@ class EvaluableNode
GetOrderedChildNodesReference().reserve(to_reserve);
}

constexpr std::vector<EvaluableNode *> &GetOrderedChildNodes()
__forceinline std::vector<EvaluableNode *> &GetOrderedChildNodes()
{
if(IsOrderedArray())
return GetOrderedChildNodesReference();
Expand Down Expand Up @@ -729,7 +726,7 @@ class EvaluableNode
GetMappedChildNodesReference().reserve(to_reserve);
}

constexpr AssocType &GetMappedChildNodes()
__forceinline AssocType &GetMappedChildNodes()
{
if(IsAssociativeArray())
return GetMappedChildNodesReference();
Expand Down
10 changes: 10 additions & 0 deletions src/Amalgam/evaluablenode/EvaluableNodeManagement.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ class EvaluableNodeStackStateSaver
stack = _stack;
originalStackSize = stack->size();

#ifdef AMALGAM_FAST_MEMORY_INTEGRITY
assert(initial_element == nullptr || !initial_element->IsNodeDeallocated());
#endif

stack->push_back(initial_element);
}

Expand All @@ -214,6 +218,9 @@ class EvaluableNodeStackStateSaver

__forceinline void PushEvaluableNode(EvaluableNode *n)
{
#ifdef AMALGAM_FAST_MEMORY_INTEGRITY
assert(n == nullptr || !n->IsNodeDeallocated());
#endif
stack->push_back(n);
}

Expand All @@ -231,6 +238,9 @@ class EvaluableNodeStackStateSaver
//replaces the position of the stack with new_value
__forceinline void SetStackLocation(size_t location, EvaluableNode *new_value)
{
#ifdef AMALGAM_FAST_MEMORY_INTEGRITY
assert(new_value == nullptr || !new_value->IsNodeDeallocated());
#endif
(*stack)[location] = new_value;
}

Expand Down

0 comments on commit 9738dde

Please sign in to comment.