memory_arena
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Functions
arena_debug.h File Reference

Debugging utilities and hooks for the arena memory allocator. More...

#include "arena_config.h"
#include <stdarg.h>
#include <stdatomic.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
+ Include dependency graph for arena_debug.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  s_arena_debug
 Debug metadata associated with an arena. More...
 

Macros

#define ALOG(...)   ((void) 0)
 Debug logging macro (enabled only if ARENA_DEBUG_LOG is set).
 
#define ARENA_ASSERT(cond)   ((void) 0)
 
#define ARENA_ASSERT_VALID(arena)   ((void) 0)
 
#define ARENA_CHECK(arena)   ((void) 0)
 
#define arena_poison_memory(ptr, size)   ((void) (ptr), (void) (size))
 No-op poison macro when poisoning is disabled.
 
#define ARENA_POISON_PATTERN   0xDEADBEEF
 Poison value used when overwriting memory in debug mode.
 

Typedefs

typedef void(* arena_error_callback) (const char *message, void *context)
 Type for error callback functions.
 
typedef struct s_arena t_arena
 Arena structure forward declaration.
 
typedef struct s_arena_debug t_arena_debug
 Debug metadata associated with an arena.
 

Functions

void arena_default_error_callback (const char *msg, void *ctx)
 Default fallback error callback (prints to stderr).
 
void arena_generate_id (t_arena *arena)
 Generate a unique debug ID for an arena.
 
void arena_report_error (t_arena *arena, const char *fmt,...)
 Report an error from an arena using its configured error callback.
 
void arena_set_debug_label (t_arena *arena, const char *label)
 Assign a debug label to an arena.
 
void arena_set_error_callback (t_arena *arena, arena_error_callback cb, void *context)
 Set a custom error callback function for reporting arena errors.
 

Detailed Description

Debugging utilities and hooks for the arena memory allocator.

Author
Toonsa
Date
2025

This header defines debug-related features for arena memory systems, including:

These features are controlled via compile-time flags in arena_config.h:

This module is optional and designed to aid development, debugging, diagnostics, and testing of arena-based systems.

Definition in file arena_debug.h.


Data Structure Documentation

◆ s_arena_debug

struct s_arena_debug

Debug metadata associated with an arena.

Definition at line 64 of file arena_debug.h.

Data Fields
arena_error_callback error_cb Callback function for reporting errors.
void * error_context Optional context passed to the error callback.
char id[ARENA_ID_LEN] Unique identifier string (e.g., "A#0001").
const char * label Optional user-provided label for logging/debug.
atomic_int subarena_counter Internal counter for sub-arenas.

Macro Definition Documentation

◆ ALOG

#define ALOG (   ...)    ((void) 0)

◆ ARENA_ASSERT

#define ARENA_ASSERT (   cond)    ((void) 0)

Definition at line 157 of file arena_debug.h.

◆ ARENA_ASSERT_VALID

#define ARENA_ASSERT_VALID (   arena)    ((void) 0)

◆ ARENA_CHECK

#define ARENA_CHECK (   arena)    ((void) 0)

◆ arena_poison_memory

#define arena_poison_memory (   ptr,
  size 
)    ((void) (ptr), (void) (size))

◆ ARENA_POISON_PATTERN

#define ARENA_POISON_PATTERN   0xDEADBEEF

Poison value used when overwriting memory in debug mode.

Examples
/home/toonsa/myProjects/memoryArena/srcs/internal/arena_debug.c.

Definition at line 111 of file arena_debug.h.

Typedef Documentation

◆ arena_error_callback

typedef void(* arena_error_callback) (const char *message, void *context)

Type for error callback functions.

Parameters
messageThe error message string.
contextOptional user-defined context pointer.
Examples
/home/toonsa/myProjects/memoryArena/srcs/internal/arena_debug.c.

Definition at line 58 of file arena_debug.h.

◆ t_arena

typedef struct s_arena t_arena

Arena structure forward declaration.

Definition at line 50 of file arena_debug.h.

◆ t_arena_debug

typedef struct s_arena_debug t_arena_debug

Debug metadata associated with an arena.