|
infix
A JIT-Powered FFI Library for C
|
Unit test for the runtime pluggable allocator API (infix_set_allocator). More...
#include "common/compat_c23.h"#include "common/double_tap.h"#include "common/infix_internals.h"#include <infix/infix.h>#include <stddef.h>#include <stdio.h>#include <stdlib.h>Classes | |
| struct | tracked_record_t |
Macros | |
| #define | DBLTAP_IMPLEMENTATION |
| #define | TRACKED_MAX_LIVE 4096 |
Functions | |
| static int | add_ints (int a, int b) |
| static void | tracked_reset (void) |
| static size_t | tracked_find (void *ptr) |
| static void | tracked_add (void *ptr) |
| static void | tracked_remove (void *ptr) |
| static void * | tracked_malloc (size_t size) |
| static void * | tracked_calloc (size_t nelem, size_t size) |
| static void * | tracked_realloc (void *ptr, size_t new_size) |
| static void | tracked_free (void *ptr) |
| static size_t | tracked_total_alloc (void) |
| Total blocks handed out by the tracking allocator (malloc + calloc). | |
| static void | ok_libc_defaults (const char *label) |
| subtest ("installing and restoring the allocator") | |
| subtest ("full lifecycle routed through the custom allocator") | |
| subtest ("switching allocators between objects, never mid-lifecycle") | |
Variables | |
| static tracked_record_t | tracked_live [TRACKED_MAX_LIVE] |
| static size_t | tracked_live_count |
| static size_t | tracked_alloc_count |
| static size_t | tracked_calloc_count |
| static size_t | tracked_realloc_count |
| static size_t | tracked_free_count |
| static bool | tracked_unmatched_free |
| static const infix_allocator_t | tracked_allocator |
| TEST | |
Unit test for the runtime pluggable allocator API (infix_set_allocator).
infix routes every internal heap allocation through the infix_allocator callback table, which hosts replace at runtime with infix_set_allocator(). This test installs a tracking allocator and verifies that a realistic infix lifecycle (registry creation, bulk type registration, signature parsing, JIT emission, an actual FFI call, and teardown) allocates and frees exclusively through the installed callbacks, that calloc and realloc reach the table too, that nothing leaks, and that passing NULL restores the libc defaults.
This is the regression test for the "wrong pool" scenario that bit Affix: memory handed to one allocator must always be released through the same allocator. tracked_free flags any pointer it never allocated (which would mean an allocation escaped the table), and the balance check flags any block still live after teardown (which would mean a free escaped the table).
Note on the trampoline cache: infix_forward_create deduplicates identical trampolines in a process-wide, refcounted cache, and infix_forward_destroy only releases the caller's reference, so a destroyed trampoline stays alive until _infix_cache_clear(). The test flushes that cache (through the currently installed allocator) so the balance check measures a complete lifecycle.
Unlike 811_fault_injection.c (which overrides infix's allocator at compile time with #define infix_malloc ...), this test uses the public runtime API and links the real library, exercising exactly the table indirection that consumers of a prebuilt libinfix rely on.
| #define DBLTAP_IMPLEMENTATION |
| #define TRACKED_MAX_LIVE 4096 |
|
static |
|
static |
| subtest | ( | "full lifecycle routed through the custom allocator" | ) |
| subtest | ( | "installing and restoring the allocator" | ) |
| subtest | ( | "switching allocators between | objects, |
| never mid-lifecycle" | |||
| ) |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
Total blocks handed out by the tracking allocator (malloc + calloc).
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |