a998f6b981
Release / release (push) Successful in 8s
## Summary Standardize naming conventions across the entire wizapp-stdlib codebase by replacing inconsistent prefixes and snake_case with a unified `wp` prefix + CamelCase scheme. ## Changes ### Naming convention applied | Pattern | Before | After | |---|---|---| | Public functions | `wapp_module_function` | `wpModuleFunction` | | Public types | `GenericXxx`, bare `Xxx` | `WpXxx` | | Constants / enum values | `WAPP_XXX`, `SHELL_XXX` | `WP_XXX`, `WP_SHELL_XXX` | | Internal functions | `_module_function` | `_moduleFunction` | | Storage-class macros | `wapp_extern`, `wapp_intern` | `wp_extern`, `wp_intern` | ### Modules affected All 20 modules were renamed: `arena`, `array`, `dbl_list`, `queue`, `str8`, `mem_allocator`, `mem_utils`, `mem_os`, `file`, `cpath`, `log`, `shell_commander`, `shell_termcolour`, `shell_utils`, `prng/xorshift`, `uuid`, `tester`, `aliases`, `assert`, `misc_utils`, `platform` — plus their test files. ### Backward compatibility Added `src/oldnames.h` with `#define OLD_NAME NEW_NAME` for every renamed symbol, organized by module under Constants → Types → Functions sections. Existing code that includes this file will compile without changes. Reviewed-on: #12 Co-authored-by: Abdelrahman <said.abdelrahman89@gmail.com> Co-committed-by: Abdelrahman <said.abdelrahman89@gmail.com>
68 lines
2.4 KiB
C
68 lines
2.4 KiB
C
#include "test_allocator.h"
|
|
#include "wapp.h"
|
|
#include <stdlib.h>
|
|
|
|
// NOTE (Abdelrahman): Cannot query size of Arena 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 u8 temp_buf[TEMP_BUF_SIZE] = {0};
|
|
wp_intern WpAllocator temp_allocator = {0};
|
|
|
|
WpTestFuncResult test_arena_allocator(void) {
|
|
WpAllocator allocator = wpMemArenaAllocatorInit(4096);
|
|
b8 result = allocator.obj != NULL && allocator.alloc != NULL &&
|
|
allocator.alloc_aligned != NULL &&
|
|
allocator.realloc != NULL && allocator.realloc_aligned != NULL &&
|
|
allocator.free == NULL;
|
|
void *ptr = wpMemAllocatorAlloc(&allocator, 20);
|
|
result = result && (ptr != NULL);
|
|
|
|
wpMemArenaAllocatorDestroy(&allocator);
|
|
|
|
return wpTesterResult(result);
|
|
}
|
|
|
|
WpTestFuncResult test_arena_allocator_with_buffer(void) {
|
|
u8 buffer[KiB(4)] = {0};
|
|
|
|
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 &&
|
|
allocator.free == NULL;
|
|
void *ptr = wpMemAllocatorAlloc(&allocator, 20);
|
|
result = result && (ptr != NULL);
|
|
|
|
wpMemArenaAllocatorDestroy(&allocator);
|
|
|
|
return wpTesterResult(result);
|
|
}
|
|
|
|
WpTestFuncResult test_arena_allocator_temp_begin(void) {
|
|
temp_allocator = wpMemArenaAllocatorInitWithBuffer(temp_buf, TEMP_BUF_SIZE);
|
|
|
|
i32 *num1 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
|
b8 result = num1 != NULL;
|
|
|
|
wpMemArenaAllocatorTempBegin(&temp_allocator);
|
|
i32 *num2 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
|
result = result && num2 != NULL;
|
|
i32 *num3 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
|
result = result && num3 == NULL;
|
|
|
|
return wpTesterResult(result);
|
|
}
|
|
|
|
WpTestFuncResult test_arena_allocator_temp_end(void) {
|
|
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;
|
|
|
|
wpMemArenaAllocatorDestroy(&temp_allocator);
|
|
|
|
return wpTesterResult(result);
|
|
}
|