Rename arena
This commit is contained in:
@@ -21,7 +21,7 @@ typedef enum {
|
||||
ARENA_STORAGE_TYPE_BUFFER,
|
||||
} ArenaStorageType;
|
||||
|
||||
struct Arena {
|
||||
struct WpArena {
|
||||
u8 *buf;
|
||||
u8 *offset;
|
||||
u8 *prev_offset;
|
||||
@@ -32,63 +32,63 @@ struct Arena {
|
||||
wpMiscUtilsReservePadding(sizeof(u8 *) * 3 + sizeof(u64) + sizeof(ArenaStorageType) + sizeof(b8));
|
||||
};
|
||||
|
||||
b8 wapp_mem_arena_init_buffer(Arena **arena, u8 *buffer, u64 buffer_size) {
|
||||
if (!arena || *arena || buffer_size < sizeof(Arena)) {
|
||||
b8 wpMemArenaInitBuffer(WpArena **arena, u8 *buffer, u64 buffer_size) {
|
||||
if (!arena || *arena || buffer_size < sizeof(WpArena)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*arena = (Arena *)buffer;
|
||||
Arena *arena_ptr = *arena;
|
||||
*arena = (WpArena *)buffer;
|
||||
WpArena *arena_ptr = *arena;
|
||||
|
||||
arena_ptr->buf = (u8 *)(arena_ptr + 1);
|
||||
arena_ptr->offset = arena_ptr->buf;
|
||||
arena_ptr->prev_offset = NULL;
|
||||
arena_ptr->capacity = buffer_size - sizeof(Arena);
|
||||
arena_ptr->capacity = buffer_size - sizeof(WpArena);
|
||||
arena_ptr->type = ARENA_STORAGE_TYPE_BUFFER;
|
||||
arena_ptr->committed = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
b8 wapp_mem_arena_init_allocated_custom(Arena **arena, u64 base_capacity, MemAllocFlags flags, b8 zero_buffer) {
|
||||
b8 wpMemArenaInitAllocatedCustom(WpArena **arena, u64 base_capacity, WpMemAllocFlags flags, b8 zero_buffer) {
|
||||
if (!arena || *arena || base_capacity == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
u64 size = sizeof(Arena) + (base_capacity >= ARENA_MINIMUM_CAPACITY ? base_capacity : ARENA_MINIMUM_CAPACITY);
|
||||
u64 size = sizeof(WpArena) + (base_capacity >= ARENA_MINIMUM_CAPACITY ? base_capacity : ARENA_MINIMUM_CAPACITY);
|
||||
u64 alloc_size = wpMiscUtilsU64RoundUpPow2(size);
|
||||
u8 *allocated = (u8 *)wapp_os_mem_alloc(NULL, alloc_size, WAPP_MEM_ACCESS_READ_WRITE, flags,
|
||||
zero_buffer ? WAPP_MEM_INIT_INITIALISED : WAPP_MEM_INIT_UNINITIALISED);
|
||||
u8 *allocated = (u8 *)wpOsMemAlloc(NULL, alloc_size, WP_MEM_ACCESS_READ_WRITE, flags,
|
||||
zero_buffer ? WP_MEM_INIT_INITIALISED : WP_MEM_INIT_UNINITIALISED);
|
||||
if (!allocated) {
|
||||
return false;
|
||||
}
|
||||
|
||||
b8 committed = (flags & WAPP_MEM_ALLOC_COMMIT) == WAPP_MEM_ALLOC_COMMIT;
|
||||
b8 committed = (flags & WP_MEM_ALLOC_COMMIT) == WP_MEM_ALLOC_COMMIT;
|
||||
|
||||
#ifdef WP_PLATFORM_WINDOWS
|
||||
if (!committed) {
|
||||
wapp_os_mem_alloc(allocated, sizeof(Arena), WAPP_MEM_ACCESS_READ_WRITE, WAPP_MEM_ALLOC_COMMIT,
|
||||
WAPP_MEM_INIT_INITIALISED);
|
||||
wpOsMemAlloc(allocated, sizeof(WpArena), WP_MEM_ACCESS_READ_WRITE, WP_MEM_ALLOC_COMMIT,
|
||||
WP_MEM_INIT_INITIALISED);
|
||||
}
|
||||
#endif // ifdef WP_PLATFORM_WINDOWS
|
||||
|
||||
if (!wapp_mem_arena_init_buffer(arena, allocated, alloc_size)) {
|
||||
wapp_mem_arena_destroy(arena);
|
||||
if (!wpMemArenaInitBuffer(arena, allocated, alloc_size)) {
|
||||
wpMemArenaDestroy(arena);
|
||||
return false;
|
||||
}
|
||||
|
||||
Arena *arena_ptr = *arena;
|
||||
WpArena *arena_ptr = *arena;
|
||||
arena_ptr->type = ARENA_STORAGE_TYPE_ALLOCATED;
|
||||
arena_ptr->committed = committed;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void *wapp_mem_arena_alloc(Arena *arena, u64 size) {
|
||||
return wapp_mem_arena_alloc_aligned(arena, size, DEFAULT_ALIGNMENT);
|
||||
void *wpMemArenaAlloc(WpArena *arena, u64 size) {
|
||||
return wpMemArenaAllocAligned(arena, size, DEFAULT_ALIGNMENT);
|
||||
}
|
||||
|
||||
void *wapp_mem_arena_alloc_aligned(Arena *arena, u64 size, u64 alignment) {
|
||||
void *wpMemArenaAllocAligned(WpArena *arena, u64 size, u64 alignment) {
|
||||
wpDebugAssert(arena != NULL, "`arena` should not be NULL");
|
||||
|
||||
u8 *alloc_start = arena->offset;
|
||||
@@ -102,9 +102,9 @@ void *wapp_mem_arena_alloc_aligned(Arena *arena, u64 size, u64 alignment) {
|
||||
|
||||
#ifdef WP_PLATFORM_WINDOWS
|
||||
if (arena->type == ARENA_STORAGE_TYPE_ALLOCATED && !(arena->committed)) {
|
||||
wapp_os_mem_alloc(alloc_start, (uptr)(arena->offset) - (uptr)(alloc_start),
|
||||
WAPP_MEM_ACCESS_READ_WRITE, WAPP_MEM_ALLOC_COMMIT,
|
||||
WAPP_MEM_INIT_UNINITIALISED);
|
||||
wpOsMemAlloc(alloc_start, (uptr)(arena->offset) - (uptr)(alloc_start),
|
||||
WP_MEM_ACCESS_READ_WRITE, WP_MEM_ALLOC_COMMIT,
|
||||
WP_MEM_INIT_UNINITIALISED);
|
||||
}
|
||||
#endif // ifdef WP_PLATFORM_WINDOWS
|
||||
|
||||
@@ -113,7 +113,7 @@ void *wapp_mem_arena_alloc_aligned(Arena *arena, u64 size, u64 alignment) {
|
||||
return (void *)output;
|
||||
}
|
||||
|
||||
void *wapp_mem_arena_realloc(Arena *arena, void *ptr, u64 old_size, u64 new_size) {
|
||||
void *wpMemArenaRealloc(WpArena *arena, void *ptr, u64 old_size, u64 new_size) {
|
||||
wpDebugAssert(arena != NULL, "`arena` should not be NULL");
|
||||
|
||||
if ((u8*)ptr < arena->buf || (u8*)ptr > arena->offset ||
|
||||
@@ -121,7 +121,7 @@ void *wapp_mem_arena_realloc(Arena *arena, void *ptr, u64 old_size, u64 new_size
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *new_ptr = wapp_mem_arena_alloc(arena, new_size);
|
||||
void *new_ptr = wpMemArenaAlloc(arena, new_size);
|
||||
if (!new_ptr) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -132,7 +132,7 @@ void *wapp_mem_arena_realloc(Arena *arena, void *ptr, u64 old_size, u64 new_size
|
||||
return new_ptr;
|
||||
}
|
||||
|
||||
void *wapp_mem_arena_realloc_aligned(Arena *arena, void *ptr, u64 old_size, u64 new_size, u64 alignment) {
|
||||
void *wpMemArenaReallocAligned(WpArena *arena, void *ptr, u64 old_size, u64 new_size, u64 alignment) {
|
||||
wpDebugAssert(arena != NULL, "`arena` should not be NULL");
|
||||
|
||||
if ((u8*)ptr < arena->buf || (u8*)ptr > arena->offset ||
|
||||
@@ -140,7 +140,7 @@ void *wapp_mem_arena_realloc_aligned(Arena *arena, void *ptr, u64 old_size, u64
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *new_ptr = wapp_mem_arena_alloc_aligned(arena, new_size, alignment);
|
||||
void *new_ptr = wpMemArenaAllocAligned(arena, new_size, alignment);
|
||||
if (!new_ptr) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -151,7 +151,7 @@ void *wapp_mem_arena_realloc_aligned(Arena *arena, void *ptr, u64 old_size, u64
|
||||
return new_ptr;
|
||||
}
|
||||
|
||||
void wapp_mem_arena_temp_begin(Arena *arena) {
|
||||
void wpMemArenaTempBegin(WpArena *arena) {
|
||||
wpDebugAssert(arena != NULL, "`arena` should not be NULL");
|
||||
|
||||
if (arena->prev_offset != NULL) {
|
||||
@@ -161,7 +161,7 @@ void wapp_mem_arena_temp_begin(Arena *arena) {
|
||||
arena->prev_offset = arena->offset;
|
||||
}
|
||||
|
||||
void wapp_mem_arena_temp_end(Arena *arena) {
|
||||
void wpMemArenaTempEnd(WpArena *arena) {
|
||||
wpDebugAssert(arena != NULL, "`arena` should not be NULL");
|
||||
|
||||
if (arena->prev_offset == NULL) {
|
||||
@@ -172,20 +172,20 @@ void wapp_mem_arena_temp_end(Arena *arena) {
|
||||
arena->prev_offset = NULL;
|
||||
}
|
||||
|
||||
void wapp_mem_arena_clear(Arena *arena) {
|
||||
void wpMemArenaClear(WpArena *arena) {
|
||||
wpDebugAssert(arena != NULL, "`arena` should not be NULL");
|
||||
|
||||
memset(arena->buf, 0, arena->offset - arena->buf);
|
||||
arena->offset = arena->buf;
|
||||
}
|
||||
|
||||
void wapp_mem_arena_destroy(Arena **arena) {
|
||||
void wpMemArenaDestroy(WpArena **arena) {
|
||||
wpDebugAssert(arena != NULL && (*arena) != NULL, "`arena` double pointer is not valid");
|
||||
|
||||
Arena *arena_ptr = *arena;
|
||||
WpArena *arena_ptr = *arena;
|
||||
|
||||
if (arena_ptr->type == ARENA_STORAGE_TYPE_ALLOCATED) {
|
||||
wapp_os_mem_free(*arena, sizeof(Arena) + arena_ptr->capacity);
|
||||
wpOsMemFree(*arena, sizeof(WpArena) + arena_ptr->capacity);
|
||||
}
|
||||
|
||||
*arena = NULL;
|
||||
|
||||
@@ -11,32 +11,32 @@
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !WP_PLATFORM_CPP
|
||||
|
||||
typedef struct Arena Arena;
|
||||
typedef struct WpArena WpArena;
|
||||
|
||||
#define wapp_mem_arena_init_allocated(arena_dptr, base_capacity) \
|
||||
(wapp_mem_arena_init_allocated_custom(arena_dptr, base_capacity, WAPP_MEM_ALLOC_RESERVE, false))
|
||||
#define wapp_mem_arena_init_allocated_commit(arena_dptr, base_capacity) \
|
||||
(wapp_mem_arena_init_allocated_custom(arena_dptr, base_capacity, WAPP_MEM_ALLOC_RESERVE | WAPP_MEM_ALLOC_COMMIT, false))
|
||||
#define wapp_mem_arena_init_allocated_zero(arena_dptr, base_capacity) \
|
||||
(wapp_mem_arena_init_allocated_custom(arena_dptr, base_capacity, WAPP_MEM_ALLOC_RESERVE, true))
|
||||
#define wapp_mem_arena_init_allocated_commit_and_zero(arena_dptr, base_capacity) \
|
||||
(wapp_mem_arena_init_allocated_custom(arena_dptr, base_capacity, WAPP_MEM_ALLOC_RESERVE | WAPP_MEM_ALLOC_COMMIT, true))
|
||||
#define wpMemArenaInitAllocated(arena_dptr, base_capacity) \
|
||||
(wpMemArenaInitAllocatedCustom(arena_dptr, base_capacity, WP_MEM_ALLOC_RESERVE, false))
|
||||
#define wpMemArenaInitAllocatedCommit(arena_dptr, base_capacity) \
|
||||
(wpMemArenaInitAllocatedCustom(arena_dptr, base_capacity, WP_MEM_ALLOC_RESERVE | WP_MEM_ALLOC_COMMIT, false))
|
||||
#define wpMemArenaInitAllocatedZero(arena_dptr, base_capacity) \
|
||||
(wpMemArenaInitAllocatedCustom(arena_dptr, base_capacity, WP_MEM_ALLOC_RESERVE, true))
|
||||
#define wpMemArenaInitAllocatedCommitAndZero(arena_dptr, base_capacity) \
|
||||
(wpMemArenaInitAllocatedCustom(arena_dptr, base_capacity, WP_MEM_ALLOC_RESERVE | WP_MEM_ALLOC_COMMIT, true))
|
||||
|
||||
/**
|
||||
* Arena initialisation function. `wapp_mem_arena_init_allocated_custom` provides the most
|
||||
* control over how the Arena is initialised. Wrapper macros are provided for
|
||||
* WpArena initialisation function. `wpMemArenaInitAllocatedCustom` provides the most
|
||||
* control over how the WpArena is initialised. Wrapper macros are provided for
|
||||
* easier use.
|
||||
*/
|
||||
b8 wapp_mem_arena_init_allocated_custom(Arena **arena, u64 base_capacity, MemAllocFlags flags, b8 zero_buffer);
|
||||
b8 wapp_mem_arena_init_buffer(Arena **arena, u8 *buffer, u64 buffer_size);
|
||||
void *wapp_mem_arena_alloc(Arena *arena, u64 size);
|
||||
void *wapp_mem_arena_alloc_aligned(Arena *arena, u64 size, u64 alignment);
|
||||
void *wapp_mem_arena_realloc(Arena *arena, void *ptr, u64 old_size, u64 new_size);
|
||||
void *wapp_mem_arena_realloc_aligned(Arena *arena, void *ptr, u64 old_size, u64 new_size, u64 alignment);
|
||||
void wapp_mem_arena_temp_begin(Arena *arena);
|
||||
void wapp_mem_arena_temp_end(Arena *arena);
|
||||
void wapp_mem_arena_clear(Arena *arena);
|
||||
void wapp_mem_arena_destroy(Arena **arena);
|
||||
b8 wpMemArenaInitAllocatedCustom(WpArena **arena, u64 base_capacity, WpMemAllocFlags flags, b8 zero_buffer);
|
||||
b8 wpMemArenaInitBuffer(WpArena **arena, u8 *buffer, u64 buffer_size);
|
||||
void *wpMemArenaAlloc(WpArena *arena, u64 size);
|
||||
void *wpMemArenaAllocAligned(WpArena *arena, u64 size, u64 alignment);
|
||||
void *wpMemArenaRealloc(WpArena *arena, void *ptr, u64 old_size, u64 new_size);
|
||||
void *wpMemArenaReallocAligned(WpArena *arena, void *ptr, u64 old_size, u64 new_size, u64 alignment);
|
||||
void wpMemArenaTempBegin(WpArena *arena);
|
||||
void wpMemArenaTempEnd(WpArena *arena);
|
||||
void wpMemArenaClear(WpArena *arena);
|
||||
void wpMemArenaDestroy(WpArena **arena);
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
|
||||
@@ -13,9 +13,9 @@ wp_intern void *mem_arena_realloc(void *ptr, u64 old_size, u64 new_size, void *a
|
||||
wp_intern void *mem_arena_realloc_aligned(void *ptr, u64 old_size, u64 new_size, u64 alignment,
|
||||
void *alloc_obj);
|
||||
|
||||
WpAllocator wapp_mem_arena_allocator_init_with_buffer(u8 *buffer, u64 buffer_size) {
|
||||
WpAllocator wpMemArenaAllocatorInitWithBuffer(u8 *buffer, u64 buffer_size) {
|
||||
WpAllocator allocator = {0};
|
||||
b8 initialised = wapp_mem_arena_init_buffer((Arena **)(&allocator.obj), buffer, buffer_size);
|
||||
b8 initialised = wpMemArenaInitBuffer((WpArena **)(&allocator.obj), buffer, buffer_size);
|
||||
if (!initialised) {
|
||||
return allocator;
|
||||
}
|
||||
@@ -25,9 +25,9 @@ WpAllocator wapp_mem_arena_allocator_init_with_buffer(u8 *buffer, u64 buffer_siz
|
||||
return allocator;
|
||||
}
|
||||
|
||||
WpAllocator wapp_mem_arena_allocator_init_custom(u64 base_capacity, MemAllocFlags flags, b8 zero_buffer) {
|
||||
WpAllocator wpMemArenaAllocatorInitCustom(u64 base_capacity, WpMemAllocFlags flags, b8 zero_buffer) {
|
||||
WpAllocator allocator = {0};
|
||||
b8 initialised = wapp_mem_arena_init_allocated_custom((Arena **)(&allocator.obj), base_capacity, flags, zero_buffer);
|
||||
b8 initialised = wpMemArenaInitAllocatedCustom((WpArena **)(&allocator.obj), base_capacity, flags, zero_buffer);
|
||||
if (!initialised) {
|
||||
return allocator;
|
||||
}
|
||||
@@ -37,24 +37,24 @@ WpAllocator wapp_mem_arena_allocator_init_custom(u64 base_capacity, MemAllocFlag
|
||||
return allocator;
|
||||
}
|
||||
|
||||
void wapp_mem_arena_allocator_temp_begin(const WpAllocator *allocator) {
|
||||
void wpMemArenaAllocatorTempBegin(const WpAllocator *allocator) {
|
||||
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
|
||||
wapp_mem_arena_temp_begin((Arena *)(allocator->obj));
|
||||
wpMemArenaTempBegin((WpArena *)(allocator->obj));
|
||||
}
|
||||
|
||||
void wapp_mem_arena_allocator_temp_end(const WpAllocator *allocator) {
|
||||
void wpMemArenaAllocatorTempEnd(const WpAllocator *allocator) {
|
||||
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
|
||||
wapp_mem_arena_temp_end((Arena *)(allocator->obj));
|
||||
wpMemArenaTempEnd((WpArena *)(allocator->obj));
|
||||
}
|
||||
|
||||
void wapp_mem_arena_allocator_clear(WpAllocator *allocator) {
|
||||
void wpMemArenaAllocatorClear(WpAllocator *allocator) {
|
||||
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
|
||||
wapp_mem_arena_clear((Arena *)(allocator->obj));
|
||||
wpMemArenaClear((WpArena *)(allocator->obj));
|
||||
}
|
||||
|
||||
void wapp_mem_arena_allocator_destroy(WpAllocator *allocator) {
|
||||
void wpMemArenaAllocatorDestroy(WpAllocator *allocator) {
|
||||
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
|
||||
wapp_mem_arena_destroy((Arena **)(&(allocator->obj)));
|
||||
wpMemArenaDestroy((WpArena **)(&(allocator->obj)));
|
||||
*allocator = (WpAllocator){0};
|
||||
}
|
||||
|
||||
@@ -66,22 +66,22 @@ wp_intern void initialise_arena_allocator(WpAllocator *allocator) {
|
||||
}
|
||||
|
||||
wp_intern void *mem_arena_alloc(u64 size, void *alloc_obj) {
|
||||
Arena *arena = (Arena *)alloc_obj;
|
||||
return wapp_mem_arena_alloc(arena, size);
|
||||
WpArena *arena = (WpArena *)alloc_obj;
|
||||
return wpMemArenaAlloc(arena, size);
|
||||
}
|
||||
|
||||
wp_intern void *mem_arena_alloc_aligned(u64 size, u64 alignment, void *alloc_obj) {
|
||||
Arena *arena = (Arena *)alloc_obj;
|
||||
return wapp_mem_arena_alloc_aligned(arena, size, alignment);
|
||||
WpArena *arena = (WpArena *)alloc_obj;
|
||||
return wpMemArenaAllocAligned(arena, size, alignment);
|
||||
}
|
||||
|
||||
wp_intern void *mem_arena_realloc(void *ptr, u64 old_size, u64 new_size, void *alloc_obj) {
|
||||
Arena *arena = (Arena *)alloc_obj;
|
||||
return wapp_mem_arena_realloc(arena, ptr, old_size, new_size);
|
||||
WpArena *arena = (WpArena *)alloc_obj;
|
||||
return wpMemArenaRealloc(arena, ptr, old_size, new_size);
|
||||
}
|
||||
|
||||
wp_intern void *mem_arena_realloc_aligned(void *ptr, u64 old_size, u64 new_size, u64 alignment,
|
||||
void *alloc_obj) {
|
||||
Arena *arena = (Arena *)alloc_obj;
|
||||
return wapp_mem_arena_realloc_aligned(arena, ptr, old_size, new_size, alignment);
|
||||
WpArena *arena = (WpArena *)alloc_obj;
|
||||
return wpMemArenaReallocAligned(arena, ptr, old_size, new_size, alignment);
|
||||
}
|
||||
|
||||
@@ -12,32 +12,32 @@
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !WP_PLATFORM_CPP
|
||||
|
||||
#define wapp_mem_arena_allocator_init(base_capacity) \
|
||||
(wapp_mem_arena_allocator_init_custom(base_capacity, WAPP_MEM_ALLOC_RESERVE, false))
|
||||
#define wapp_mem_arena_allocator_init_commit(base_capacity) \
|
||||
(wapp_mem_arena_allocator_init_custom(base_capacity, WAPP_MEM_ALLOC_RESERVE | WAPP_MEM_ALLOC_COMMIT, false))
|
||||
#define wapp_mem_arena_allocator_init_zero(base_capacity) \
|
||||
(wapp_mem_arena_allocator_init_custom(base_capacity, WAPP_MEM_ALLOC_RESERVE, true))
|
||||
#define wapp_mem_arena_allocator_init_commit_and_zero(base_capacity) \
|
||||
(wapp_mem_arena_allocator_init_custom(base_capacity, WAPP_MEM_ALLOC_RESERVE | WAPP_MEM_ALLOC_COMMIT, true))
|
||||
#define wpMemArenaAllocatorInit(base_capacity) \
|
||||
(wpMemArenaAllocatorInitCustom(base_capacity, WP_MEM_ALLOC_RESERVE, false))
|
||||
#define wpMemArenaAllocatorInitCommit(base_capacity) \
|
||||
(wpMemArenaAllocatorInitCustom(base_capacity, WP_MEM_ALLOC_RESERVE | WP_MEM_ALLOC_COMMIT, false))
|
||||
#define wpMemArenaAllocatorInitZero(base_capacity) \
|
||||
(wpMemArenaAllocatorInitCustom(base_capacity, WP_MEM_ALLOC_RESERVE, true))
|
||||
#define wpMemArenaAllocatorInitCommitAndZero(base_capacity) \
|
||||
(wpMemArenaAllocatorInitCustom(base_capacity, WP_MEM_ALLOC_RESERVE | WP_MEM_ALLOC_COMMIT, true))
|
||||
|
||||
/**
|
||||
* Wraps an Arena in an WpAllocator object. It attempts to initialise the Arena
|
||||
* Wraps a WpArena in a WpAllocator object. It attempts to initialise the WpArena
|
||||
* and, if successful, defines the operations supported by it to be used by the
|
||||
* WpAllocator.
|
||||
*
|
||||
* An Arena allocator only supports normal allocation and aligned allocation.
|
||||
* An WpArena allocator only supports normal allocation and aligned allocation.
|
||||
* Reallocation, aligned reallocation and freeing aren't implemented.
|
||||
*
|
||||
* The `wapp_mem_arena_allocator_init_custom` provides the most control over how
|
||||
* the Arena is initialised. Wrapper macros are provided for easier use.
|
||||
* The `wpMemArenaAllocatorInitCustom` provides the most control over how
|
||||
* the WpArena is initialised. Wrapper macros are provided for easier use.
|
||||
*/
|
||||
WpAllocator wapp_mem_arena_allocator_init_custom(u64 base_capacity, MemAllocFlags flags, b8 zero_buffer);
|
||||
WpAllocator wapp_mem_arena_allocator_init_with_buffer(u8 *buffer, u64 buffer_size);
|
||||
void wapp_mem_arena_allocator_temp_begin(const WpAllocator *allocator);
|
||||
void wapp_mem_arena_allocator_temp_end(const WpAllocator *allocator);
|
||||
void wapp_mem_arena_allocator_clear(WpAllocator *allocator);
|
||||
void wapp_mem_arena_allocator_destroy(WpAllocator *allocator);
|
||||
WpAllocator wpMemArenaAllocatorInitCustom(u64 base_capacity, WpMemAllocFlags flags, b8 zero_buffer);
|
||||
WpAllocator wpMemArenaAllocatorInitWithBuffer(u8 *buffer, u64 buffer_size);
|
||||
void wpMemArenaAllocatorTempBegin(const WpAllocator *allocator);
|
||||
void wpMemArenaAllocatorTempEnd(const WpAllocator *allocator);
|
||||
void wpMemArenaAllocatorClear(WpAllocator *allocator);
|
||||
void wpMemArenaAllocatorDestroy(WpAllocator *allocator);
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
|
||||
@@ -10,7 +10,7 @@ wp_intern u8 temp_buf[TEMP_BUF_SIZE] = {0};
|
||||
wp_intern WpAllocator temp_allocator = {0};
|
||||
|
||||
WpTestFuncResult test_arena_allocator(void) {
|
||||
WpAllocator allocator = wapp_mem_arena_allocator_init(4096);
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(4096);
|
||||
b8 result = allocator.obj != NULL && allocator.alloc != NULL &&
|
||||
allocator.alloc_aligned != NULL &&
|
||||
allocator.realloc != NULL && allocator.realloc_aligned != NULL &&
|
||||
@@ -18,7 +18,7 @@ WpTestFuncResult test_arena_allocator(void) {
|
||||
void *ptr = wpMemAllocatorAlloc(&allocator, 20);
|
||||
result = result && (ptr != NULL);
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
@@ -26,7 +26,7 @@ WpTestFuncResult test_arena_allocator(void) {
|
||||
WpTestFuncResult test_arena_allocator_with_buffer(void) {
|
||||
u8 buffer[KiB(4)] = {0};
|
||||
|
||||
WpAllocator allocator = wapp_mem_arena_allocator_init_with_buffer(buffer, KiB(4));
|
||||
WpAllocator allocator = wpMemArenaAllocatorInitWithBuffer(buffer, KiB(4));
|
||||
b8 result = allocator.obj != NULL && allocator.alloc != NULL &&
|
||||
allocator.alloc_aligned != NULL &&
|
||||
allocator.realloc != NULL && allocator.realloc_aligned != NULL &&
|
||||
@@ -34,18 +34,18 @@ WpTestFuncResult test_arena_allocator_with_buffer(void) {
|
||||
void *ptr = wpMemAllocatorAlloc(&allocator, 20);
|
||||
result = result && (ptr != NULL);
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
WpTestFuncResult test_arena_allocator_temp_begin(void) {
|
||||
temp_allocator = wapp_mem_arena_allocator_init_with_buffer(temp_buf, TEMP_BUF_SIZE);
|
||||
temp_allocator = wpMemArenaAllocatorInitWithBuffer(temp_buf, TEMP_BUF_SIZE);
|
||||
|
||||
i32 *num1 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
||||
b8 result = num1 != NULL;
|
||||
|
||||
wapp_mem_arena_allocator_temp_begin(&temp_allocator);
|
||||
wpMemArenaAllocatorTempBegin(&temp_allocator);
|
||||
i32 *num2 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
||||
result = result && num2 != NULL;
|
||||
i32 *num3 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
||||
@@ -55,13 +55,13 @@ WpTestFuncResult test_arena_allocator_temp_begin(void) {
|
||||
}
|
||||
|
||||
WpTestFuncResult test_arena_allocator_temp_end(void) {
|
||||
wapp_mem_arena_allocator_temp_end(&temp_allocator);
|
||||
wpMemArenaAllocatorTempEnd(&temp_allocator);
|
||||
i32 *num1 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
||||
b8 result = num1 != NULL;
|
||||
i32 *num2 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
||||
result = result && num2 == NULL;
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&temp_allocator);
|
||||
wpMemArenaAllocatorDestroy(&temp_allocator);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ wp_intern u8 temp_buf[TEMP_BUF_SIZE] = {};
|
||||
wp_intern WpAllocator temp_allocator = {};
|
||||
|
||||
WpTestFuncResult test_arena_allocator(void) {
|
||||
WpAllocator allocator = wapp_mem_arena_allocator_init(4096);
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(4096);
|
||||
b8 result = allocator.obj != nullptr && allocator.alloc != nullptr &&
|
||||
allocator.alloc_aligned != nullptr &&
|
||||
allocator.realloc != nullptr && allocator.realloc_aligned != nullptr &&
|
||||
@@ -18,7 +18,7 @@ WpTestFuncResult test_arena_allocator(void) {
|
||||
void *ptr = wpMemAllocatorAlloc(&allocator, 20);
|
||||
result = result && (ptr != nullptr);
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
@@ -26,7 +26,7 @@ WpTestFuncResult test_arena_allocator(void) {
|
||||
WpTestFuncResult test_arena_allocator_with_buffer(void) {
|
||||
u8 buffer[KiB(4)] = {0};
|
||||
|
||||
WpAllocator allocator = wapp_mem_arena_allocator_init_with_buffer(buffer, KiB(4));
|
||||
WpAllocator allocator = wpMemArenaAllocatorInitWithBuffer(buffer, KiB(4));
|
||||
b8 result = allocator.obj != NULL && allocator.alloc != NULL &&
|
||||
allocator.alloc_aligned != NULL &&
|
||||
allocator.realloc != NULL && allocator.realloc_aligned != NULL &&
|
||||
@@ -34,18 +34,18 @@ WpTestFuncResult test_arena_allocator_with_buffer(void) {
|
||||
void *ptr = wpMemAllocatorAlloc(&allocator, 20);
|
||||
result = result && (ptr != NULL);
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
WpTestFuncResult test_arena_allocator_temp_begin(void) {
|
||||
temp_allocator = wapp_mem_arena_allocator_init_with_buffer(temp_buf, TEMP_BUF_SIZE);
|
||||
temp_allocator = wpMemArenaAllocatorInitWithBuffer(temp_buf, TEMP_BUF_SIZE);
|
||||
|
||||
i32 *num1 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
||||
b8 result = num1 != NULL;
|
||||
|
||||
wapp_mem_arena_allocator_temp_begin(&temp_allocator);
|
||||
wpMemArenaAllocatorTempBegin(&temp_allocator);
|
||||
i32 *num2 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
||||
result = result && num2 != NULL;
|
||||
i32 *num3 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
||||
@@ -55,13 +55,13 @@ WpTestFuncResult test_arena_allocator_temp_begin(void) {
|
||||
}
|
||||
|
||||
WpTestFuncResult test_arena_allocator_temp_end(void) {
|
||||
wapp_mem_arena_allocator_temp_end(&temp_allocator);
|
||||
wpMemArenaAllocatorTempEnd(&temp_allocator);
|
||||
i32 *num1 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
||||
b8 result = num1 != NULL;
|
||||
i32 *num2 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
||||
result = result && num2 == NULL;
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&temp_allocator);
|
||||
wpMemArenaAllocatorDestroy(&temp_allocator);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
+28
-28
@@ -4,42 +4,42 @@
|
||||
|
||||
#define ARENA_CAPACITY KiB(16)
|
||||
#define ARENA_BUF_SIZE KiB(4)
|
||||
// NOTE (Abdelrahman): Cannot query size of Arena here so it's hardcoded. Similarly, since arena
|
||||
// NOTE (Abdelrahman): Cannot query size of WpArena here so it's hardcoded. Similarly, since arena
|
||||
// allocation are aligned to power of 2 boundaries, the number of i32 values needed is hardcoded.
|
||||
#define TEMP_BUF_SIZE (40 + sizeof(i32) * 8)
|
||||
|
||||
wp_intern Arena *arena = NULL;
|
||||
wp_intern WpArena *arena = NULL;
|
||||
wp_intern i32 count = 20;
|
||||
wp_intern i32 *array = NULL;
|
||||
wp_intern Arena *buf_arena = NULL;
|
||||
wp_intern WpArena *buf_arena = NULL;
|
||||
wp_intern u8 buf[ARENA_BUF_SIZE] = {0};
|
||||
wp_intern Arena *temp_arena = NULL;
|
||||
wp_intern WpArena *temp_arena = NULL;
|
||||
wp_intern u8 temp_buf[TEMP_BUF_SIZE] = {0};
|
||||
|
||||
WpTestFuncResult test_arena_init_buffer(void) {
|
||||
b8 result = wapp_mem_arena_init_buffer(&buf_arena, buf, ARENA_BUF_SIZE);
|
||||
b8 result = wpMemArenaInitBuffer(&buf_arena, buf, ARENA_BUF_SIZE);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
WpTestFuncResult test_arena_init_allocated(void) {
|
||||
b8 result = wapp_mem_arena_init_allocated(&arena, ARENA_CAPACITY);
|
||||
b8 result = wpMemArenaInitAllocated(&arena, ARENA_CAPACITY);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
WpTestFuncResult test_arena_init_succeeds_when_reserving_very_large_size(void) {
|
||||
Arena *large_arena = NULL;
|
||||
WpArena *large_arena = NULL;
|
||||
u64 capacity = GiB(512);
|
||||
b8 result = wapp_mem_arena_init_allocated(&large_arena, capacity);
|
||||
b8 result = wpMemArenaInitAllocated(&large_arena, capacity);
|
||||
if (result) {
|
||||
wapp_mem_arena_destroy(&large_arena);
|
||||
wpMemArenaDestroy(&large_arena);
|
||||
}
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
WpTestFuncResult test_arena_alloc_with_buffer(void) {
|
||||
i32 *arr = (i32 *)wapp_mem_arena_alloc(arena, count * sizeof(i32));
|
||||
i32 *arr = (i32 *)wpMemArenaAlloc(arena, count * sizeof(i32));
|
||||
b8 result = arr != NULL;
|
||||
|
||||
for (i32 i = 0; i < count; ++i) {
|
||||
@@ -50,7 +50,7 @@ WpTestFuncResult test_arena_alloc_with_buffer(void) {
|
||||
}
|
||||
|
||||
WpTestFuncResult test_arena_alloc_succeeds_when_within_capacity(void) {
|
||||
array = wapp_mem_arena_alloc(arena, count * sizeof(i32));
|
||||
array = wpMemArenaAlloc(arena, count * sizeof(i32));
|
||||
b8 result = array != NULL;
|
||||
|
||||
for (i32 i = 0; i < count; ++i) {
|
||||
@@ -61,7 +61,7 @@ WpTestFuncResult test_arena_alloc_succeeds_when_within_capacity(void) {
|
||||
}
|
||||
|
||||
WpTestFuncResult test_arena_alloc_fails_when_over_capacity(void) {
|
||||
u8 *bytes = wapp_mem_arena_alloc(arena, ARENA_CAPACITY * 2);
|
||||
u8 *bytes = wpMemArenaAlloc(arena, ARENA_CAPACITY * 2);
|
||||
b8 result = bytes == NULL;
|
||||
|
||||
return wpTesterResult(result);
|
||||
@@ -70,13 +70,13 @@ WpTestFuncResult test_arena_alloc_fails_when_over_capacity(void) {
|
||||
WpTestFuncResult test_arena_realloc_bigger_size(void) {
|
||||
u64 old_count = 10;
|
||||
u64 new_count = 20;
|
||||
i32 *bytes = wapp_mem_arena_alloc(arena, old_count * sizeof(i32));
|
||||
i32 *bytes = wpMemArenaAlloc(arena, old_count * sizeof(i32));
|
||||
|
||||
for (u64 i = 0; i < old_count; ++i) {
|
||||
bytes[i] = (i32)i;
|
||||
}
|
||||
|
||||
i32 *new_bytes = wapp_mem_arena_realloc(arena, bytes, old_count * sizeof(i32), new_count * sizeof(i32));
|
||||
i32 *new_bytes = wpMemArenaRealloc(arena, bytes, old_count * sizeof(i32), new_count * sizeof(i32));
|
||||
if (!new_bytes) {
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
@@ -93,13 +93,13 @@ WpTestFuncResult test_arena_realloc_bigger_size(void) {
|
||||
WpTestFuncResult test_arena_realloc_smaller_size(void) {
|
||||
u64 old_count = 10;
|
||||
u64 new_count = 5;
|
||||
i32 *bytes = wapp_mem_arena_alloc(arena, old_count * sizeof(i32));
|
||||
i32 *bytes = wpMemArenaAlloc(arena, old_count * sizeof(i32));
|
||||
|
||||
for (u64 i = 0; i < old_count; ++i) {
|
||||
bytes[i] = (i32)i;
|
||||
}
|
||||
|
||||
i32 *new_bytes = wapp_mem_arena_realloc(arena, bytes, old_count * sizeof(i32), new_count * sizeof(i32));
|
||||
i32 *new_bytes = wpMemArenaRealloc(arena, bytes, old_count * sizeof(i32), new_count * sizeof(i32));
|
||||
if (!new_bytes) {
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
@@ -114,33 +114,33 @@ WpTestFuncResult test_arena_realloc_smaller_size(void) {
|
||||
}
|
||||
|
||||
WpTestFuncResult test_arena_temp_begin(void) {
|
||||
b8 result = wapp_mem_arena_init_buffer(&temp_arena, temp_buf, TEMP_BUF_SIZE);
|
||||
i32 *num1 = (i32 *)wapp_mem_arena_alloc(temp_arena, sizeof(i32));
|
||||
b8 result = wpMemArenaInitBuffer(&temp_arena, temp_buf, TEMP_BUF_SIZE);
|
||||
i32 *num1 = (i32 *)wpMemArenaAlloc(temp_arena, sizeof(i32));
|
||||
result = result && num1 != NULL;
|
||||
|
||||
wapp_mem_arena_temp_begin(temp_arena);
|
||||
i32 *num2 = (i32 *)wapp_mem_arena_alloc(temp_arena, sizeof(i32));
|
||||
wpMemArenaTempBegin(temp_arena);
|
||||
i32 *num2 = (i32 *)wpMemArenaAlloc(temp_arena, sizeof(i32));
|
||||
result = result && num2 != NULL;
|
||||
i32 *num3 = (i32 *)wapp_mem_arena_alloc(temp_arena, sizeof(i32));
|
||||
i32 *num3 = (i32 *)wpMemArenaAlloc(temp_arena, sizeof(i32));
|
||||
result = result && num3 == NULL;
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
WpTestFuncResult test_arena_temp_end(void) {
|
||||
wapp_mem_arena_temp_end(temp_arena);
|
||||
i32 *num1 = (i32 *)wapp_mem_arena_alloc(temp_arena, sizeof(i32));
|
||||
wpMemArenaTempEnd(temp_arena);
|
||||
i32 *num1 = (i32 *)wpMemArenaAlloc(temp_arena, sizeof(i32));
|
||||
b8 result = num1 != NULL;
|
||||
i32 *num2 = (i32 *)wapp_mem_arena_alloc(temp_arena, sizeof(i32));
|
||||
i32 *num2 = (i32 *)wpMemArenaAlloc(temp_arena, sizeof(i32));
|
||||
result = result && num2 == NULL;
|
||||
|
||||
wapp_mem_arena_destroy(&temp_arena);
|
||||
wpMemArenaDestroy(&temp_arena);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
WpTestFuncResult test_arena_clear(void) {
|
||||
wapp_mem_arena_clear(arena);
|
||||
wpMemArenaClear(arena);
|
||||
b8 result = true;
|
||||
|
||||
for (i32 i = 0; i < count; ++i) {
|
||||
@@ -154,14 +154,14 @@ WpTestFuncResult test_arena_clear(void) {
|
||||
}
|
||||
|
||||
WpTestFuncResult test_arena_destroy_buffer(void) {
|
||||
wapp_mem_arena_destroy(&buf_arena);
|
||||
wpMemArenaDestroy(&buf_arena);
|
||||
b8 result = buf_arena == NULL;
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
WpTestFuncResult test_arena_destroy_allocated(void) {
|
||||
wapp_mem_arena_destroy(&arena);
|
||||
wpMemArenaDestroy(&arena);
|
||||
b8 result = arena == NULL;
|
||||
|
||||
return wpTesterResult(result);
|
||||
|
||||
+28
-28
@@ -4,42 +4,42 @@
|
||||
|
||||
#define ARENA_CAPACITY KiB(16)
|
||||
#define ARENA_BUF_SIZE KiB(4)
|
||||
// NOTE (Abdelrahman): Cannot query size of Arena here so it's hardcoded. Similarly, since arena
|
||||
// NOTE (Abdelrahman): Cannot query size of WpArena here so it's hardcoded. Similarly, since arena
|
||||
// allocation are aligned to power of 2 boundaries, the number of i32 values needed is hardcoded.
|
||||
#define TEMP_BUF_SIZE (40 + sizeof(i32) * 8)
|
||||
|
||||
wp_intern Arena *arena = NULL;
|
||||
wp_intern WpArena *arena = NULL;
|
||||
wp_intern i32 count = 20;
|
||||
wp_intern i32 *array = NULL;
|
||||
wp_intern Arena *buf_arena = NULL;
|
||||
wp_intern WpArena *buf_arena = NULL;
|
||||
wp_intern u8 buf[ARENA_BUF_SIZE] = {};
|
||||
wp_intern Arena *temp_arena = NULL;
|
||||
wp_intern WpArena *temp_arena = NULL;
|
||||
wp_intern u8 temp_buf[TEMP_BUF_SIZE] = {};
|
||||
|
||||
WpTestFuncResult test_arena_init_buffer(void) {
|
||||
b8 result = wapp_mem_arena_init_buffer(&buf_arena, buf, ARENA_BUF_SIZE);
|
||||
b8 result = wpMemArenaInitBuffer(&buf_arena, buf, ARENA_BUF_SIZE);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
WpTestFuncResult test_arena_init_allocated(void) {
|
||||
b8 result = wapp_mem_arena_init_allocated(&arena, ARENA_CAPACITY);
|
||||
b8 result = wpMemArenaInitAllocated(&arena, ARENA_CAPACITY);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
WpTestFuncResult test_arena_init_succeeds_when_reserving_very_large_size(void) {
|
||||
Arena *large_arena = nullptr;
|
||||
WpArena *large_arena = nullptr;
|
||||
u64 capacity = GiB(512);
|
||||
b8 result = wapp_mem_arena_init_allocated(&large_arena, capacity);
|
||||
b8 result = wpMemArenaInitAllocated(&large_arena, capacity);
|
||||
if (result) {
|
||||
wapp_mem_arena_destroy(&large_arena);
|
||||
wpMemArenaDestroy(&large_arena);
|
||||
}
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
WpTestFuncResult test_arena_alloc_with_buffer(void) {
|
||||
i32 *arr = (i32 *)wapp_mem_arena_alloc(arena, count * sizeof(i32));
|
||||
i32 *arr = (i32 *)wpMemArenaAlloc(arena, count * sizeof(i32));
|
||||
b8 result = arr != NULL;
|
||||
|
||||
for (i32 i = 0; i < count; ++i) {
|
||||
@@ -50,7 +50,7 @@ WpTestFuncResult test_arena_alloc_with_buffer(void) {
|
||||
}
|
||||
|
||||
WpTestFuncResult test_arena_alloc_succeeds_when_within_capacity(void) {
|
||||
array = (i32 *)wapp_mem_arena_alloc(arena, count * sizeof(i32));
|
||||
array = (i32 *)wpMemArenaAlloc(arena, count * sizeof(i32));
|
||||
b8 result = array != nullptr;
|
||||
|
||||
for (i32 i = 0; i < count; ++i) {
|
||||
@@ -61,7 +61,7 @@ WpTestFuncResult test_arena_alloc_succeeds_when_within_capacity(void) {
|
||||
}
|
||||
|
||||
WpTestFuncResult test_arena_alloc_fails_when_over_capacity(void) {
|
||||
u8 *bytes = (u8 *)wapp_mem_arena_alloc(arena, ARENA_CAPACITY * 2);
|
||||
u8 *bytes = (u8 *)wpMemArenaAlloc(arena, ARENA_CAPACITY * 2);
|
||||
b8 result = bytes == nullptr;
|
||||
|
||||
return wpTesterResult(result);
|
||||
@@ -70,13 +70,13 @@ WpTestFuncResult test_arena_alloc_fails_when_over_capacity(void) {
|
||||
WpTestFuncResult test_arena_realloc_bigger_size(void) {
|
||||
u64 old_count = 10;
|
||||
u64 new_count = 20;
|
||||
i32 *bytes = (i32 *)wapp_mem_arena_alloc(arena, old_count * sizeof(i32));
|
||||
i32 *bytes = (i32 *)wpMemArenaAlloc(arena, old_count * sizeof(i32));
|
||||
|
||||
for (u64 i = 0; i < old_count; ++i) {
|
||||
bytes[i] = (i32)i;
|
||||
}
|
||||
|
||||
i32 *new_bytes = (i32 *)wapp_mem_arena_realloc(arena, bytes, old_count * sizeof(i32), new_count * sizeof(i32));
|
||||
i32 *new_bytes = (i32 *)wpMemArenaRealloc(arena, bytes, old_count * sizeof(i32), new_count * sizeof(i32));
|
||||
if (!new_bytes) {
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
@@ -93,13 +93,13 @@ WpTestFuncResult test_arena_realloc_bigger_size(void) {
|
||||
WpTestFuncResult test_arena_realloc_smaller_size(void) {
|
||||
u64 old_count = 10;
|
||||
u64 new_count = 5;
|
||||
i32 *bytes = (i32 *)wapp_mem_arena_alloc(arena, old_count * sizeof(i32));
|
||||
i32 *bytes = (i32 *)wpMemArenaAlloc(arena, old_count * sizeof(i32));
|
||||
|
||||
for (u64 i = 0; i < old_count; ++i) {
|
||||
bytes[i] = (i32)i;
|
||||
}
|
||||
|
||||
i32 *new_bytes = (i32 *)wapp_mem_arena_realloc(arena, bytes, old_count * sizeof(i32), new_count * sizeof(i32));
|
||||
i32 *new_bytes = (i32 *)wpMemArenaRealloc(arena, bytes, old_count * sizeof(i32), new_count * sizeof(i32));
|
||||
if (!new_bytes) {
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
@@ -114,33 +114,33 @@ WpTestFuncResult test_arena_realloc_smaller_size(void) {
|
||||
}
|
||||
|
||||
WpTestFuncResult test_arena_temp_begin(void) {
|
||||
b8 result = wapp_mem_arena_init_buffer(&temp_arena, temp_buf, TEMP_BUF_SIZE);
|
||||
i32 *num1 = (i32 *)wapp_mem_arena_alloc(temp_arena, sizeof(i32));
|
||||
b8 result = wpMemArenaInitBuffer(&temp_arena, temp_buf, TEMP_BUF_SIZE);
|
||||
i32 *num1 = (i32 *)wpMemArenaAlloc(temp_arena, sizeof(i32));
|
||||
result = result && num1 != NULL;
|
||||
|
||||
wapp_mem_arena_temp_begin(temp_arena);
|
||||
i32 *num2 = (i32 *)wapp_mem_arena_alloc(temp_arena, sizeof(i32));
|
||||
wpMemArenaTempBegin(temp_arena);
|
||||
i32 *num2 = (i32 *)wpMemArenaAlloc(temp_arena, sizeof(i32));
|
||||
result = result && num2 != NULL;
|
||||
i32 *num3 = (i32 *)wapp_mem_arena_alloc(temp_arena, sizeof(i32));
|
||||
i32 *num3 = (i32 *)wpMemArenaAlloc(temp_arena, sizeof(i32));
|
||||
result = result && num3 == NULL;
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
WpTestFuncResult test_arena_temp_end(void) {
|
||||
wapp_mem_arena_temp_end(temp_arena);
|
||||
i32 *num1 = (i32 *)wapp_mem_arena_alloc(temp_arena, sizeof(i32));
|
||||
wpMemArenaTempEnd(temp_arena);
|
||||
i32 *num1 = (i32 *)wpMemArenaAlloc(temp_arena, sizeof(i32));
|
||||
b8 result = num1 != NULL;
|
||||
i32 *num2 = (i32 *)wapp_mem_arena_alloc(temp_arena, sizeof(i32));
|
||||
i32 *num2 = (i32 *)wpMemArenaAlloc(temp_arena, sizeof(i32));
|
||||
result = result && num2 == NULL;
|
||||
|
||||
wapp_mem_arena_destroy(&temp_arena);
|
||||
wpMemArenaDestroy(&temp_arena);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
WpTestFuncResult test_arena_clear(void) {
|
||||
wapp_mem_arena_clear(arena);
|
||||
wpMemArenaClear(arena);
|
||||
b8 result = true;
|
||||
|
||||
for (i32 i = 0; i < count; ++i) {
|
||||
@@ -154,14 +154,14 @@ WpTestFuncResult test_arena_clear(void) {
|
||||
}
|
||||
|
||||
WpTestFuncResult test_arena_destroy_buffer(void) {
|
||||
wapp_mem_arena_destroy(&buf_arena);
|
||||
wpMemArenaDestroy(&buf_arena);
|
||||
b8 result = buf_arena == NULL;
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
WpTestFuncResult test_arena_destroy_allocated(void) {
|
||||
wapp_mem_arena_destroy(&arena);
|
||||
wpMemArenaDestroy(&arena);
|
||||
b8 result = arena == nullptr;
|
||||
|
||||
return wpTesterResult(result);
|
||||
|
||||
@@ -23,7 +23,7 @@ WpTestFuncResult test_queue_push(void) {
|
||||
}
|
||||
|
||||
WpTestFuncResult test_queue_push_alloc(void) {
|
||||
WpAllocator arena = wapp_mem_arena_allocator_init(MiB(64));
|
||||
WpAllocator arena = wpMemArenaAllocatorInit(MiB(64));
|
||||
WpI32Queue queue = wpQueue(i32, CAPACITY);
|
||||
|
||||
for (u64 i = 0; i < CAPACITY; ++i) {
|
||||
@@ -65,7 +65,7 @@ WpTestFuncResult test_queue_push_alloc(void) {
|
||||
result = result && arr[i] == (i32)(2 + i);
|
||||
}
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ WpTestFuncResult test_queue_push(void) {
|
||||
}
|
||||
|
||||
WpTestFuncResult test_queue_push_alloc(void) {
|
||||
WpAllocator arena = wapp_mem_arena_allocator_init(MiB(64));
|
||||
WpAllocator arena = wpMemArenaAllocatorInit(MiB(64));
|
||||
WpI32Queue queue = wpQueue(i32, CAPACITY);
|
||||
|
||||
for (u64 i = 0; i < CAPACITY; ++i) {
|
||||
@@ -63,7 +63,7 @@ WpTestFuncResult test_queue_push_alloc(void) {
|
||||
result = result && arr[i] == (i32)(2 + i);
|
||||
}
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
+28
-28
@@ -77,7 +77,7 @@ WpTestFuncResult test_str8_buf(void) {
|
||||
|
||||
WpTestFuncResult test_str8_alloc_buf(void) {
|
||||
b8 result;
|
||||
WpAllocator allocator = wapp_mem_arena_allocator_init(KiB(100));
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(KiB(100));
|
||||
if (wpMemAllocatorInvalid(&allocator)) {
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
@@ -98,14 +98,14 @@ WpTestFuncResult test_str8_alloc_buf(void) {
|
||||
result = result && s->capacity == capacity && s->size == strlen(cstr) && memcmp(s->buf, cstr, s->size) == 0;
|
||||
|
||||
TEST_ALLOC_BUF_CLEANUP:
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
WpTestFuncResult test_str8_alloc_cstr(void) {
|
||||
b8 result;
|
||||
WpAllocator allocator = wapp_mem_arena_allocator_init(KiB(100));
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(KiB(100));
|
||||
if (wpMemAllocatorInvalid(&allocator)) {
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
@@ -119,14 +119,14 @@ WpTestFuncResult test_str8_alloc_cstr(void) {
|
||||
|
||||
result = s->size == length && memcmp(s->buf, str, length) == 0;
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
WpTestFuncResult test_str8_alloc_str8(void) {
|
||||
b8 result;
|
||||
WpAllocator allocator = wapp_mem_arena_allocator_init(KiB(100));
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(KiB(100));
|
||||
if (wpMemAllocatorInvalid(&allocator)) {
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
@@ -139,14 +139,14 @@ WpTestFuncResult test_str8_alloc_str8(void) {
|
||||
|
||||
result = wpStr8Equal(s, &str);
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
WpTestFuncResult test_str8_alloc_substr(void) {
|
||||
b8 result;
|
||||
WpAllocator allocator = wapp_mem_arena_allocator_init(KiB(100));
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(KiB(100));
|
||||
if (wpMemAllocatorInvalid(&allocator)) {
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
@@ -159,7 +159,7 @@ WpTestFuncResult test_str8_alloc_substr(void) {
|
||||
|
||||
result = s->size == 5 && memcmp(s->buf, "elrah", s->size) == 0;
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
@@ -289,7 +289,7 @@ WpTestFuncResult test_str8_slice(void) {
|
||||
|
||||
WpTestFuncResult test_str8_alloc_concat(void) {
|
||||
b8 result;
|
||||
WpAllocator arena = wapp_mem_arena_allocator_init(KiB(100));
|
||||
WpAllocator arena = wpMemArenaAllocatorInit(KiB(100));
|
||||
|
||||
WpStr8 str = wpStr8Lit("Hello world");
|
||||
WpStr8 suffix1 = wpStr8Lit(" from me.");
|
||||
@@ -305,7 +305,7 @@ WpTestFuncResult test_str8_alloc_concat(void) {
|
||||
output = wpStr8AllocConcat(&arena, output, &suffix2);
|
||||
result = result && output->size == concat2.size && wpStr8Equal(output, &concat2);
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
@@ -410,7 +410,7 @@ WpTestFuncResult test_str8_rfind(void) {
|
||||
|
||||
WpTestFuncResult test_str8_split(void) {
|
||||
b8 result;
|
||||
WpAllocator arena = wapp_mem_arena_allocator_init(KiB(100));
|
||||
WpAllocator arena = wpMemArenaAllocatorInit(KiB(100));
|
||||
|
||||
WpStr8 str = wpStr8Lit("hello world from me");
|
||||
WpStr8 delim1 = wpStr8Lit(" ");
|
||||
@@ -443,7 +443,7 @@ WpTestFuncResult test_str8_split(void) {
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
while (running1) {
|
||||
WpStr8 *node = wapp_dbl_list_get(WpStr8, list1, index1);
|
||||
WpStr8 *node = wpDblListGet(WpStr8, list1, index1);
|
||||
result = result && wpStr8Equal(node, &(splits1[index1]));
|
||||
|
||||
++index1;
|
||||
@@ -453,21 +453,21 @@ WpTestFuncResult test_str8_split(void) {
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
while (running2) {
|
||||
WpStr8 *node = wapp_dbl_list_get(WpStr8, list2, index2);
|
||||
WpStr8 *node = wpDblListGet(WpStr8, list2, index2);
|
||||
result = result && wpStr8Equal(node, &(splits2[index2]));
|
||||
|
||||
++index2;
|
||||
running2 = index2 < count2;
|
||||
}
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
WpTestFuncResult test_str8_split_with_max(void) {
|
||||
b8 result;
|
||||
WpAllocator arena = wapp_mem_arena_allocator_init(KiB(100));
|
||||
WpAllocator arena = wpMemArenaAllocatorInit(KiB(100));
|
||||
|
||||
WpStr8 str = wpStr8Lit("hello world from me");
|
||||
WpStr8 delim = wpStr8Lit(" ");
|
||||
@@ -488,21 +488,21 @@ WpTestFuncResult test_str8_split_with_max(void) {
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
while (running) {
|
||||
WpStr8 *node = wapp_dbl_list_get(WpStr8, list, index);
|
||||
WpStr8 *node = wpDblListGet(WpStr8, list, index);
|
||||
result = result && wpStr8Equal(node, &(splits[index]));
|
||||
|
||||
++index;
|
||||
running = index < count;
|
||||
}
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
WpTestFuncResult test_str8_rsplit(void) {
|
||||
b8 result;
|
||||
WpAllocator arena = wapp_mem_arena_allocator_init(KiB(100));
|
||||
WpAllocator arena = wpMemArenaAllocatorInit(KiB(100));
|
||||
|
||||
WpStr8 str = wpStr8Lit("hello world from me");
|
||||
WpStr8 delim1 = wpStr8Lit(" ");
|
||||
@@ -535,7 +535,7 @@ WpTestFuncResult test_str8_rsplit(void) {
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
while (running1) {
|
||||
WpStr8 *node = wapp_dbl_list_get(WpStr8, list1, index1);
|
||||
WpStr8 *node = wpDblListGet(WpStr8, list1, index1);
|
||||
result = result && wpStr8Equal(node, &(splits1[index1]));
|
||||
|
||||
++index1;
|
||||
@@ -545,21 +545,21 @@ WpTestFuncResult test_str8_rsplit(void) {
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
while (running2) {
|
||||
WpStr8 *node = wapp_dbl_list_get(WpStr8, list2, index2);
|
||||
WpStr8 *node = wpDblListGet(WpStr8, list2, index2);
|
||||
result = result && wpStr8Equal(node, &(splits2[index2]));
|
||||
|
||||
++index2;
|
||||
running2 = index2 < count2;
|
||||
}
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
WpTestFuncResult test_str8_rsplit_with_max(void) {
|
||||
b8 result;
|
||||
WpAllocator arena = wapp_mem_arena_allocator_init(KiB(100));
|
||||
WpAllocator arena = wpMemArenaAllocatorInit(KiB(100));
|
||||
|
||||
WpStr8 str = wpStr8Lit("hello world from me");
|
||||
WpStr8 delim = wpStr8Lit(" ");
|
||||
@@ -580,21 +580,21 @@ WpTestFuncResult test_str8_rsplit_with_max(void) {
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
while (running) {
|
||||
WpStr8 *node = wapp_dbl_list_get(WpStr8, list, index);
|
||||
WpStr8 *node = wpDblListGet(WpStr8, list, index);
|
||||
result = result && wpStr8Equal(node, &(splits[index]));
|
||||
|
||||
++index;
|
||||
running = index < count;
|
||||
}
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
WpTestFuncResult test_str8_join(void) {
|
||||
b8 result;
|
||||
WpAllocator arena = wapp_mem_arena_allocator_init(KiB(100));
|
||||
WpAllocator arena = wpMemArenaAllocatorInit(KiB(100));
|
||||
|
||||
WpStr8 str = wpStr8Lit("hello world from me");
|
||||
WpStr8 delim1 = wpStr8Lit(" ");
|
||||
@@ -607,7 +607,7 @@ WpTestFuncResult test_str8_join(void) {
|
||||
result = join1->size == str.size && wpStr8Equal(join1, &str);
|
||||
result = result && join2->size == str.size && wpStr8Equal(join2, &str);
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
@@ -616,10 +616,10 @@ WpTestFuncResult test_str8_from_bytes(void) {
|
||||
b8 result;
|
||||
|
||||
WpStr8 str = wpStr8Buf(1024);
|
||||
U8Array bytes = wapp_array(u8, 'W', 'A', 'P', 'P');
|
||||
WpU8Array bytes = wpArray(u8, 'W', 'A', 'P', 'P');
|
||||
wpStr8FromBytes(&str, bytes);
|
||||
|
||||
result = str.size == wapp_array_count(bytes) * wapp_array_item_size(bytes);
|
||||
result = str.size == wpArrayCount(bytes) * wpArrayItemSize(bytes);
|
||||
result = result && wpStr8Equal(&str, &wpStr8LitRo("WAPP"));
|
||||
|
||||
return wpTesterResult(result);
|
||||
|
||||
+29
-29
@@ -77,7 +77,7 @@ WpTestFuncResult test_str8_buf(void) {
|
||||
|
||||
WpTestFuncResult test_str8_alloc_buf(void) {
|
||||
b8 result;
|
||||
WpAllocator allocator = wapp_mem_arena_allocator_init(KiB(100));
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(KiB(100));
|
||||
if (wpMemAllocatorInvalid(&allocator)) {
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
@@ -87,7 +87,7 @@ WpTestFuncResult test_str8_alloc_buf(void) {
|
||||
WpStr8 *s = wpStr8AllocBuf(&allocator, capacity);
|
||||
if (!s) {
|
||||
result = false;
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
@@ -98,14 +98,14 @@ WpTestFuncResult test_str8_alloc_buf(void) {
|
||||
|
||||
result = result && s->capacity == capacity && s->size == strlen(cstr) && memcmp(s->buf, cstr, s->size) == 0;
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
WpTestFuncResult test_str8_alloc_cstr(void) {
|
||||
b8 result;
|
||||
WpAllocator allocator = wapp_mem_arena_allocator_init(KiB(100));
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(KiB(100));
|
||||
if (wpMemAllocatorInvalid(&allocator)) {
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
@@ -119,14 +119,14 @@ WpTestFuncResult test_str8_alloc_cstr(void) {
|
||||
|
||||
result = s->size == length && memcmp(s->buf, str, length) == 0;
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
WpTestFuncResult test_str8_alloc_str8(void) {
|
||||
b8 result;
|
||||
WpAllocator allocator = wapp_mem_arena_allocator_init(KiB(100));
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(KiB(100));
|
||||
if (wpMemAllocatorInvalid(&allocator)) {
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
@@ -139,14 +139,14 @@ WpTestFuncResult test_str8_alloc_str8(void) {
|
||||
|
||||
result = wpStr8Equal(s, &str);
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
WpTestFuncResult test_str8_alloc_substr(void) {
|
||||
b8 result;
|
||||
WpAllocator allocator = wapp_mem_arena_allocator_init(KiB(100));
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(KiB(100));
|
||||
if (wpMemAllocatorInvalid(&allocator)) {
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
@@ -159,7 +159,7 @@ WpTestFuncResult test_str8_alloc_substr(void) {
|
||||
|
||||
result = s->size == 5 && memcmp(s->buf, "elrah", s->size) == 0;
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
@@ -289,7 +289,7 @@ WpTestFuncResult test_str8_slice(void) {
|
||||
|
||||
WpTestFuncResult test_str8_alloc_concat(void) {
|
||||
b8 result;
|
||||
WpAllocator arena = wapp_mem_arena_allocator_init(KiB(100));
|
||||
WpAllocator arena = wpMemArenaAllocatorInit(KiB(100));
|
||||
|
||||
WpStr8 str = wpStr8Lit("Hello world");
|
||||
WpStr8 suffix1 = wpStr8Lit(" from me.");
|
||||
@@ -305,7 +305,7 @@ WpTestFuncResult test_str8_alloc_concat(void) {
|
||||
output = wpStr8AllocConcat(&arena, output, &suffix2);
|
||||
result = result && output->size == concat2.size && wpStr8Equal(output, &concat2);
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
@@ -410,7 +410,7 @@ WpTestFuncResult test_str8_rfind(void) {
|
||||
|
||||
WpTestFuncResult test_str8_split(void) {
|
||||
b8 result;
|
||||
WpAllocator arena = wapp_mem_arena_allocator_init(KiB(100));
|
||||
WpAllocator arena = wpMemArenaAllocatorInit(KiB(100));
|
||||
|
||||
WpStr8 str = wpStr8Lit("hello world from me");
|
||||
WpStr8 delim1 = wpStr8Lit(" ");
|
||||
@@ -443,7 +443,7 @@ WpTestFuncResult test_str8_split(void) {
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
while (running1) {
|
||||
WpStr8 *node = wapp_dbl_list_get(WpStr8, list1, index1);
|
||||
WpStr8 *node = wpDblListGet(WpStr8, list1, index1);
|
||||
result = result && wpStr8Equal(node, &(splits1[index1]));
|
||||
|
||||
++index1;
|
||||
@@ -453,21 +453,21 @@ WpTestFuncResult test_str8_split(void) {
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
while (running2) {
|
||||
WpStr8 *node = wapp_dbl_list_get(WpStr8, list2, index2);
|
||||
WpStr8 *node = wpDblListGet(WpStr8, list2, index2);
|
||||
result = result && wpStr8Equal(node, &(splits2[index2]));
|
||||
|
||||
++index2;
|
||||
running2 = index2 < count2;
|
||||
}
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
WpTestFuncResult test_str8_split_with_max(void) {
|
||||
b8 result;
|
||||
WpAllocator arena = wapp_mem_arena_allocator_init(KiB(100));
|
||||
WpAllocator arena = wpMemArenaAllocatorInit(KiB(100));
|
||||
|
||||
WpStr8 str = wpStr8Lit("hello world from me");
|
||||
WpStr8 delim = wpStr8Lit(" ");
|
||||
@@ -488,21 +488,21 @@ WpTestFuncResult test_str8_split_with_max(void) {
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
while (running) {
|
||||
WpStr8 *node = wapp_dbl_list_get(WpStr8, list, index);
|
||||
WpStr8 *node = wpDblListGet(WpStr8, list, index);
|
||||
result = result && wpStr8Equal(node, &(splits[index]));
|
||||
|
||||
++index;
|
||||
running = index < count;
|
||||
}
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
WpTestFuncResult test_str8_rsplit(void) {
|
||||
b8 result;
|
||||
WpAllocator arena = wapp_mem_arena_allocator_init(KiB(100));
|
||||
WpAllocator arena = wpMemArenaAllocatorInit(KiB(100));
|
||||
|
||||
WpStr8 str = wpStr8Lit("hello world from me");
|
||||
WpStr8 delim1 = wpStr8Lit(" ");
|
||||
@@ -535,7 +535,7 @@ WpTestFuncResult test_str8_rsplit(void) {
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
while (running1) {
|
||||
WpStr8 *node = wapp_dbl_list_get(WpStr8, list1, index1);
|
||||
WpStr8 *node = wpDblListGet(WpStr8, list1, index1);
|
||||
result = result && wpStr8Equal(node, &(splits1[index1]));
|
||||
|
||||
++index1;
|
||||
@@ -545,21 +545,21 @@ WpTestFuncResult test_str8_rsplit(void) {
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
while (running2) {
|
||||
WpStr8 *node = wapp_dbl_list_get(WpStr8, list2, index2);
|
||||
WpStr8 *node = wpDblListGet(WpStr8, list2, index2);
|
||||
result = result && wpStr8Equal(node, &(splits2[index2]));
|
||||
|
||||
++index2;
|
||||
running2 = index2 < count2;
|
||||
}
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
WpTestFuncResult test_str8_rsplit_with_max(void) {
|
||||
b8 result;
|
||||
WpAllocator arena = wapp_mem_arena_allocator_init(KiB(100));
|
||||
WpAllocator arena = wpMemArenaAllocatorInit(KiB(100));
|
||||
|
||||
WpStr8 str = wpStr8Lit("hello world from me");
|
||||
WpStr8 delim = wpStr8Lit(" ");
|
||||
@@ -580,21 +580,21 @@ WpTestFuncResult test_str8_rsplit_with_max(void) {
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
while (running) {
|
||||
WpStr8 *node = wapp_dbl_list_get(WpStr8, list, index);
|
||||
WpStr8 *node = wpDblListGet(WpStr8, list, index);
|
||||
result = result && wpStr8Equal(node, &(splits[index]));
|
||||
|
||||
++index;
|
||||
running = index < count;
|
||||
}
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
WpTestFuncResult test_str8_join(void) {
|
||||
b8 result;
|
||||
WpAllocator arena = wapp_mem_arena_allocator_init(KiB(100));
|
||||
WpAllocator arena = wpMemArenaAllocatorInit(KiB(100));
|
||||
|
||||
WpStr8 str = wpStr8Lit("hello world from me");
|
||||
WpStr8 delim1 = wpStr8Lit(" ");
|
||||
@@ -607,7 +607,7 @@ WpTestFuncResult test_str8_join(void) {
|
||||
result = join1->size == str.size && wpStr8Equal(join1, &str);
|
||||
result = result && join2->size == str.size && wpStr8Equal(join2, &str);
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
@@ -617,10 +617,10 @@ WpTestFuncResult test_str8_from_bytes(void) {
|
||||
|
||||
WpStr8 str = wpStr8Buf(1024);
|
||||
WpStr8 expected = wpStr8LitRo("WAPP");
|
||||
U8Array bytes = wapp_array(u8, 'W', 'A', 'P', 'P');
|
||||
WpU8Array bytes = wpArray(u8, 'W', 'A', 'P', 'P');
|
||||
wpStr8FromBytes(&str, bytes);
|
||||
|
||||
result = str.size == wapp_array_count(bytes) * wapp_array_item_size(bytes);
|
||||
result = str.size == wpArrayCount(bytes) * wpArrayItemSize(bytes);
|
||||
result = result && wpStr8Equal(&str, &expected);
|
||||
|
||||
return wpTesterResult(result);
|
||||
|
||||
Reference in New Issue
Block a user