Overview / Foundation

assert

Dispatch of assertion failures. Listeners observe the failure and a single policy decides the action. No allocation on the failure path.

Always compiled: part of the core build.Include #include <ethereal/cpp/assert/assert.hpp>C layer

assert.hpp

#include <ethereal/cpp/assert/assert.hpp>

File: assert.hpp Language: C++ (11, 14, 17, 20)

Core assertion facility for the Ethereal framework.

Declares the data model and the dispatch entry points through which every Ethereal assertion failure is reported and resolved. This header does not define the assert macros themselves, see AssertMacros.hpp for those.

Model:

  • SAssertSite: the immutable, per call site description of an assertion. One instance exists per assert in the binary, is constant initialized and lives in read only storage. It is the stable identity of a call site, which is what allows the system to offer "ignore this site" and per site hit counting.
  • SAssertSiteState: the mutable counterpart of a site. Holds the ignore latch and the hit counter. Mutated through atomics by the implementation, never by the caller.
  • SAssertData: the full description of a single failure, built by the implementation and handed to listeners and to the policy. Plain old data, versioned through uStructSize so the layout can grow without breaking an already shipped integration.

Dispatch is split in two, deliberately:

  • Listeners observe. Any number can be installed, they return nothing, and they exist to log, to feed telemetry or to write a crash dump. Registration order is honoured through priority.
  • The policy decides. Exactly one is installed at a time and it returns the EAssertAction that resolves the failure. Splitting the two removes the ambiguity of a reporting callback that also gets to control program flow.

ABI: The registration surface is a C ABI, a function pointer plus an opaque context pointer. This is intentional. The framework ships as both a static (.lib) and a dynamic (.dll) build and cannot place virtual table layout inside its contract, since the integrator may build with a different toolchain. The virtual interfaces below (IAssertListener, IAssertPolicy) are a convenience layer implemented on top of that C ABI through a trampoline, and are safe only when the listener object is compiled by the same toolchain that consumes it.

Callbacks are deliberately not declared noexcept. Under C++17 the exception specification is part of the function type, so marking the typedef would prevent a plain function from being installed and would change the type identity between language modes. The contract is enforced by documentation: an exception must never escape a callback.

Copyright (C) Typename Studios LLC. All Rights Reserved.

enum

EAssertFlag

Ethereal::Assertion#
C++
enum EAssertFlag
{
    /// @brief  No flags set.
    eAssertFlag_None        = 0,

    /// @brief  The failure originated inside Ethereal SDK code rather than
    ///             inside integrator code. Listeners use this to route SDK
    ///             defects to a different sink than application defects.
    eAssertFlag_SDKImpl        = 1u << 0,

    /// @brief  The failure is not recoverable. The default policy always
    ///             resolves a fatal failure with \c eAssertAction_Abort and the
    ///             site cannot be ignored.
    eAssertFlag_Fatal        = 1u << 1,

    /// @brief  Only the first hit of this site is reported. Subsequent hits
    ///             still increment the hit counter but do not reach the
    ///             listeners or the policy.
    eAssertFlag_Once        = 1u << 2,

    /// @brief  The check is expensive and is compiled in only when slow
    ///             assertions are enabled for the build.
    eAssertFlag_Slow        = 1u << 3,

    /// @brief  The expression carries side effects and is evaluated in every
    ///             build configuration, including shipping.
    eAssertFlag_Verify        = 1u << 4,

    /// @brief  The failure was reported through \c ETL_ENSURE, which never
    ///             aborts and returns control to the caller.
    eAssertFlag_Ensure        = 1u << 5
};

Severity and behaviour flags carried by an assertion call site.

Stored as a bitfield in SAssertSite::uFlags. Combining them is expected, the values are disjoint bits.

enum

EAssertAction

Ethereal::Assertion#
C++
enum EAssertAction
{
    /// @brief  Report and resume execution at the call site.
    eAssertAction_Continue    = 0,

    /// @brief  Report, latch the site as ignored and resume. The site will
    ///             not be reported again for the remainder of the process.
    ///             Ignored for sites flagged \c eAssertFlag_Fatal.
    eAssertAction_Ignore    = 1,

    /// @brief  Trap into the debugger at the call site and resume afterwards.
    ///             The break is issued by the macro, not by the dispatcher, so
    ///             the debugger lands on the failing line rather than inside
    ///             the assertion machinery.
    eAssertAction_Break        = 2,

    /// @brief  Terminate the process. Handled inside the dispatcher, which
    ///             does not return to the call site.
    eAssertAction_Abort        = 3
};

Resolution returned by the assertion policy.

Ordered by severity. The implementation never downgrades a resolution, so a policy that returns eAssertAction_Continue for a site flagged eAssertFlag_Fatal is still overridden into eAssertAction_Abort.

struct

SAssertSite

Ethereal::Assertion#
C++
struct SAssertSite
{
    /// @brief  Stringified expression that failed.
    const char * sExpression;

    /// @brief  Source file where the assertion is written.
    const char * sFileName;

    /// @brief  Decorated function signature enclosing the assertion.
    const char * sFunctionName;

    /// @brief  Line number of the assertion.
    ETL_INT32 iLine;

    /// @brief  Combination of \c EAssertFlag values.
    ETL_UINT32 uFlags;
};

Immutable description of a single assertion call site.

One constant initialized instance is emitted per assert macro expansion. Every member is a compile time constant, so the object requires no dynamic initialization and no thread safe static guard.

struct

SAssertSiteState

Ethereal::Assertion#
C++
struct SAssertSiteState
{
    /// @brief  Non zero once the site has been latched as ignored.
    ETL_INT32 iIgnored;

    /// @brief  Number of times the site has failed, including ignored hits.
    ETL_UINT32 uHitCount;
};

Mutable state associated with an assertion call site.

One instance is emitted per assert macro expansion alongside the matching SAssertSite. The fields are read and written through atomic primitives by the implementation and must never be touched directly by the caller.

Declared as plain integers rather than std::atomic so this header carries no standard library dependency and so the struct remains constant initializable.

struct

SAssertData

Ethereal::Assertion#
C++
struct SAssertData
{
    /// @brief  Size of this structure in bytes, as seen by the producer.
    ///            Listeners must check this before reading members that were
    ///             added after the version they were compiled against.
    ETL_UINT32 uStructSize;

    /// @brief  Padding, keeps the following pointer naturally aligned on
    ///             64 bit targets and makes the layout explicit.
    ETL_UINT32 uReserved;

    /// @brief  The call site that failed. Never null.
    const SAssertSite * pSite;

    /// @brief  Formatted message describing the failure, or \c nullptr when
    ///             the assertion carried no message.
    const char * sMessage;

    /// @brief  Identifier of the thread on which the assertion fired.
    ETL_UINT32 uThreadID;

    /// @brief  Value of the site hit counter for this failure, one based.
    ETL_UINT32 uHitCount;

    /// @brief  Depth of assertion reentrancy on the current thread. Zero for
    ///             a normal failure, greater than zero when the assertion fired
    ///             from inside a listener or a policy.
    ETL_INT32 iReentrancyDepth;

    /// @brief  Padding to a multiple of eight bytes.
    ETL_INT32 iReserved2;
};

Full description of a single assertion failure.

Built by the implementation and passed to every listener and to the policy. Plain old data by design, since it crosses the module boundary. New members are appended at the end and guarded by uStructSize, which lets a listener compiled against an older header remain valid.

The referenced strings are owned by the caller and remain valid only for the duration of the callback. A listener that needs to retain them must copy them.

alias

HAssertListener

Ethereal::Assertion#
typedef ETL_UINT32 HAssertListener;

Opaque handle to a registered listener. Zero is the invalid handle.

alias

void

Ethereal::Assertion#
typedef void ( *FnAssertListener )( const SAssertData & sData, void * pContext );

Signature of an assertion listener.

Observes a failure. Called for every failure that is not suppressed by an ignore latch or by eAssertFlag_Once, in descending priority order, before the policy runs.

A listener must be reentrancy safe, must not allocate on the failure path when it can be avoided, and must never let an exception escape. Blocking inside a listener blocks the failing thread and every other thread that asserts while it holds the dispatch.

sData
Description of the failure.
pContext
The opaque pointer supplied at registration.
alias

EAssertAction

Ethereal::Assertion#
typedef EAssertAction ( *FnAssertPolicy )( const SAssertData & sData, void * pContext );

Signature of the assertion policy.

Resolves a failure into an action. Exactly one policy is active at a time and it runs after every listener has been called. The same reentrancy, allocation and exception constraints that apply to listeners apply here.

sData
Description of the failure.
pContext
The opaque pointer supplied at installation.
The action the framework should take.
function

ETL_AddAssertListener

Ethereal::Assertion#
HAssertListener ETL_AddAssertListener( FnAssertListener pfnListener, void * pContext, ETL_INT32 iPriority );

Registers an assertion listener.

Listeners are stored in a fixed capacity table, so registration performs no allocation and can be called before the memory system is up. The table capacity is ETL_ASSERT_MAX_LISTENERS.

Registering the same function and context pair twice installs it twice and it will be called twice.

pfnListener
Listener to install. Must not be nullptr.
pContext
Opaque pointer forwarded to every invocation.
iPriority
Higher priority listeners run first. Ties resolve in registration order.
A handle to the registration, or zero when the table is full or pfnListener is nullptr.
function

ETL_RemoveAssertListener

Ethereal::Assertion#
bool ETL_RemoveAssertListener( HAssertListener hListener );

Removes a previously registered listener.

Safe to call while another thread is dispatching. The removal takes effect for failures that begin after the call returns, a dispatch already in flight completes against the snapshot it captured. The caller must keep the listener and its context alive until this function has returned.

hListener
Handle returned by ETL_AddAssertListener.
true when the handle was found and removed.
function

ETL_SetAssertPolicy

Ethereal::Assertion#
void ETL_SetAssertPolicy( FnAssertPolicy pfnPolicy, void * pContext );

Installs the assertion policy.

Replaces the active policy. Passing nullptr restores the built in default, which aborts on fatal failures, breaks when a debugger is attached and otherwise resumes.

Intended to run once during startup, before assertions can fire from other threads.

pfnPolicy
Policy to install, or nullptr to restore the default.
pContext
Opaque pointer forwarded to every invocation.
function

ETL_GetAssertPolicy

Ethereal::Assertion#
FnAssertPolicy ETL_GetAssertPolicy( void ** ppOutContext );

Returns the active policy.

ppOutContext
Optional, receives the context associated with the policy.
The installed policy, or nullptr when the default is active.
function

ETL_SetDefaultAssertListenerEnabled

Ethereal::Assertion#
void ETL_SetDefaultAssertListenerEnabled( bool bEnabled );

Enables or disables the built in listener.

The built in listener writes a formatted report to the standard error stream and, on Windows, to the debugger output. It is enabled by default. Disable it once a host log has been wired in through ETL_AddAssertListener to avoid duplicated output.

bEnabled
Whether the built in listener should run.
function

ETL_Assert_Report

Ethereal::Assertion#
bool ETL_Assert_Report( const SAssertSite & sSite, SAssertSiteState & sState );

Reports an assertion failure carrying no message.

Called by the assert macros. Increments the site hit counter, honours the ignore latch and eAssertFlag_Once, runs the listeners, then the policy. Terminates the process without returning when the resolution is eAssertAction_Abort.

Not meant to be invoked directly.

sSite
The failing call site.
sState
Mutable state of the call site.
true when the call site should trap into the debugger.
function

ETL_Assert_ReportMsg

Ethereal::Assertion#
bool ETL_Assert_ReportMsg( const SAssertSite & sSite, SAssertSiteState & sState, const char * sMessage );

Reports an assertion failure carrying a literal message.

sSite
The failing call site.
sState
Mutable state of the call site.
sMessage
Message describing the failure. May be nullptr.
true when the call site should trap into the debugger.
function

ETL_Assert_ReportSite

Ethereal::Assertion#
bool ETL_Assert_ReportSite( const SAssertSite & sSite, const char * sMessage );

Reports an assertion failure, resolving the call site state internally.

Same dispatch as ETL_Assert_ReportMsg, but the caller does not supply the mutable state: it is looked up in an internal table keyed by the call site identity, and created on first failure.

This exists because the assert macros cannot own the state themselves. A function local static inside a macro expansion makes any enclosing constexpr function unable to yield a constant expression (MSVC C3615), and large parts of the framework, Math and Bits above all, assert from inside constexpr functions. Keeping the state on this side of the boundary lets those macros expand to plain statements while the ignore latch and the hit counter still behave per call site.

The key is the address of the stringified expression together with the line number. Both are compile time constants at the call site, so the identity is stable across the life of the process even when the file name is a run time value, as it is in a Release build using an obfuscated substitute.

Not meant to be invoked directly.

sSite
The failing call site.
sMessage
Message describing the failure. May be nullptr.
true when the call site should trap into the debugger.
function

ETL_Assert_ReportF

Ethereal::Assertion#
bool ETL_Assert_ReportF( const SAssertSite & sSite, SAssertSiteState & sState, const char * sFormat, ... );

Reports an assertion failure carrying a formatted message.

Formatting is performed into a fixed size stack buffer and never allocates. A message longer than ETL_ASSERT_MESSAGE_LENGTH is truncated. The arguments are evaluated only on failure, since the call sits behind the failing branch in the macro.

sSite
The failing call site.
sState
Mutable state of the call site.
sFormat
printf style format string. Must not be nullptr.
true when the call site should trap into the debugger.
function

ETL_Assert_Abort

Ethereal::Assertion#
void ETL_Assert_Abort( void );

Terminates the process through the assertion fatal path.

Flushes pending output and fails fast. Declared as returning void but never returns.

function

ETL_Assert_Break

Ethereal::Assertion#
void ETL_Assert_Break( void );

Fallback debugger trap for targets with no intrinsic available.

function

ETL_Assert_IsDebuggerPresent

Ethereal::Assertion#
bool ETL_Assert_IsDebuggerPresent( void );

Reports whether a debugger is attached to the process.

The result is cached after the first successful query, so this is cheap enough to call from the failure path. Attaching a debugger after the first query is therefore not observed.

true when a debugger is attached.
class

IAssertListener

Ethereal::Assertion#

Virtual interface for assertion listeners.

class IAssertListener

Convenience wrapper over FnAssertListener. Registration installs a trampoline that forwards to OnAssertFailed, so the underlying dispatch remains a plain function pointer call.

Unlike the C surface, this interface places virtual table layout in the contract. Use it only when the implementing object is compiled by the same toolchain as the module that consumes it. Across a mixed toolchain boundary, register the function pointer directly.

The implementation must outlive its registration.

destructor

~IAssertListener

#
virtual ~IAssertListener()

Virtual destructor.

function

OnAssertFailed

#
virtual void OnAssertFailed( const SAssertData & sData ) = 0;

Called for every reported assertion failure.

sData
Description of the failure.
class

IAssertPolicy

Ethereal::Assertion#

Virtual interface for the assertion policy.

class IAssertPolicy

Convenience wrapper over FnAssertPolicy. The same toolchain and lifetime constraints described on IAssertListener apply.

destructor

~IAssertPolicy

#
virtual ~IAssertPolicy()

Virtual destructor.

function

OnResolveAssert

#
virtual EAssertAction OnResolveAssert( const SAssertData & sData ) = 0;

Resolves a reported failure into an action.

sData
Description of the failure.
The action the framework should take.
function

ETL_AddAssertListener

Ethereal::Assertion#
HAssertListener ETL_AddAssertListener( IAssertListener * pListener, ETL_INT32 iPriority );

Registers a listener object.

pListener
Listener to install. Must not be nullptr and must outlive the registration.
iPriority
Higher priority listeners run first.
A handle to the registration, or zero on failure.
function

ETL_SetAssertPolicy

Ethereal::Assertion#
void ETL_SetAssertPolicy( IAssertPolicy * pPolicy );

Installs a policy object.

pPolicy
Policy to install, or nullptr to restore the default. Must outlive the installation.

assert_inc.h

#include <ethereal/cpp/assert/assert_inc.h>

File: assert_inc.h Language: C++ (11, 14, 17, 20)

Aggregated entry point for the Ethereal assertion module, C++ side.

Pulls in the dispatch model and then the shared macro layer. This is the header every C++ module includes when it needs to assert. The individual assert headers are not meant to be included directly.

Copyright (C) Typename Studios LLC. All Rights Reserved.

macro

ETHEREAL_ASSERT_INC

#
#define ETHEREAL_ASSERT_INC

Indicates that the Ethereal Assert module is being included as a unified unit.

@def ETHEREAL_ASSERT_INC

Defined internally when the module is reached through this aggregated entry point. When present, the individual assert headers skip their own dependencies, which prevents redundant includes and circular chains between them.

Internal build coordination only. Must not be defined manually by user code.