Skip to content
MISRA_BUDGET_ALLOCATOR_MAGIC

MISRA_BUDGET_ALLOCATOR_MAGIC

Description

Per-type magic for BudgetAllocator. Stamped into Allocator.base.__magic by BudgetAllocatorInit*. The budget implementation functions validate this exact value so other allocator instances reinterpreted as a BudgetAllocator * are rejected at runtime as type-confusion.

Usage example (Cross-references)

Usage examples (Cross-references)
    
    static void budget_validate_self(const Allocator *self) {
        if (!self || self->__magic != MISRA_BUDGET_ALLOCATOR_MAGIC) {
            LOG_FATAL("type-confusion: allocator passed to budget_allocator_* is not a BudgetAllocator");
        }
                       .effort      = ALLOCATOR_EFFORT_ONCE,
                       .retry_limit = 0,
                       .__magic     = MISRA_BUDGET_ALLOCATOR_MAGIC},
            .buf        = (char *)buf,
            .buf_bytes  = buf_bytes,
Last updated on