Files
cig/test_borrow_allocator.c
T
roodletoof 01b8150625 refactor
remove the free function entirely. all allocators are now expected to
implement reset instead. I reallized I never ever want to free an
individual allocation ever again. The forever_allocator is a special
case wherEreset is a no-op. The arena allocator was deleted. It will be
replaced soon.
2025-12-02 20:21:12 +01:00

27 lines
779 B
C

#include <criterion/criterion.h>
#include "cig.h"
#define EXPECT 5
Test(borrow_allocator, test) {
allocator_t balloc = borrow_allocator(&borrow_allocator_create());
int *ptr = allocator_alloc(balloc, sizeof(int));
*ptr = EXPECT;
cr_assert_eq(*ptr, EXPECT);
allocator_reset(balloc);
}
#define IS_SIZE 900
Test(borrow_allocator, with) {
with_borrow(foo) {
with_borrow(bar) {
}
int *is = allocator_alloc(foo, sizeof(int) * IS_SIZE);
for (int i = 0; i < IS_SIZE; i++) is[i] = i;
is = allocator_alloc(foo, sizeof(int) * IS_SIZE);
for (int i = 0; i < IS_SIZE; i++) is[i] = i;
is = allocator_alloc(foo, sizeof(int) * IS_SIZE);
for (int i = 0; i < IS_SIZE; i++) is[i] = i;
break;
}
}