diff --git a/src/base/array/array.c b/src/base/array/array.c index 608ca0b..d91a10d 100644 --- a/src/base/array/array.c +++ b/src/base/array/array.c @@ -104,7 +104,7 @@ void _array_copy_capped(GenericArray dst, const GenericArray src, u64 item_size) dst_header->count = copy_count; } -GenericArray _array_append_alloc(const Allocator *allocator, GenericArray array, void *value, +GenericArray _array_append_alloc(const WpAllocator *allocator, GenericArray array, void *value, ArrayInitFlags flags, u64 item_size) { wpRuntimeAssert(allocator != NULL && array != NULL, "`allocator` and `array` should not be NULL"); _array_validate(array, item_size); @@ -133,7 +133,7 @@ RETURN_ARRAY_APPEND_ALLOC: return output; } -GenericArray _array_extend_alloc(const Allocator *allocator, GenericArray dst, const GenericArray src, +GenericArray _array_extend_alloc(const WpAllocator *allocator, GenericArray dst, const GenericArray src, ArrayInitFlags flags, u64 item_size) { wpRuntimeAssert(allocator != NULL && dst != NULL && src != NULL, "`allocator`, `dst` and `src` should not be NULL"); _array_validate(dst, item_size); @@ -165,7 +165,7 @@ RETURN_ARRAY_EXTEND_ALLOC: return output; } -GenericArray _array_copy_alloc(const Allocator *allocator, GenericArray dst, const GenericArray src, +GenericArray _array_copy_alloc(const WpAllocator *allocator, GenericArray dst, const GenericArray src, ArrayInitFlags flags, u64 item_size) { wpRuntimeAssert(allocator != NULL && dst != NULL && src != NULL, "`allocator`, `dst` and `src` should not be NULL"); _array_validate(dst, item_size); @@ -220,14 +220,14 @@ u64 _array_calc_alloc_size(u64 capacity, u64 item_size) { return sizeof(ArrayHeader) + item_size * capacity; } -GenericArray _array_alloc_capacity(const Allocator *allocator, u64 capacity, ArrayInitFlags flags, +GenericArray _array_alloc_capacity(const WpAllocator *allocator, u64 capacity, ArrayInitFlags flags, u64 item_size) { wpRuntimeAssert(allocator != NULL, "`allocator` should not be NULL"); GenericArray output = NULL; u64 allocation_size = _array_calc_alloc_size(capacity, item_size); - void *buffer = wapp_mem_allocator_alloc(allocator, allocation_size); + void *buffer = wpMemAllocatorAlloc(allocator, allocation_size); if (!buffer) { goto RETURN_ARRAY_ALLOC; } diff --git a/src/base/array/array.h b/src/base/array/array.h index 8512a0b..0da6df1 100644 --- a/src/base/array/array.h +++ b/src/base/array/array.h @@ -195,16 +195,16 @@ void _array_set(GenericArray array, u64 index, void *value, u64 item_siz void _array_append_capped(GenericArray array, void *value, u64 item_size); void _array_extend_capped(GenericArray dst, const GenericArray src, u64 item_size); void _array_copy_capped(GenericArray dst, const GenericArray src, u64 item_size); -GenericArray _array_append_alloc(const Allocator *allocator, GenericArray array, void *value, +GenericArray _array_append_alloc(const WpAllocator *allocator, GenericArray array, void *value, ArrayInitFlags flags, u64 item_size); -GenericArray _array_extend_alloc(const Allocator *allocator, GenericArray dst, const GenericArray src, +GenericArray _array_extend_alloc(const WpAllocator *allocator, GenericArray dst, const GenericArray src, ArrayInitFlags flags, u64 item_size); -GenericArray _array_copy_alloc(const Allocator *allocator, GenericArray dst, const GenericArray src, +GenericArray _array_copy_alloc(const WpAllocator *allocator, GenericArray dst, const GenericArray src, ArrayInitFlags flags, u64 item_size); void *_array_pop(GenericArray array, u64 item_size); void _array_clear(GenericArray array, u64 item_size); u64 _array_calc_alloc_size(u64 capacity, u64 item_size); -GenericArray _array_alloc_capacity(const Allocator *allocator, u64 capacity, ArrayInitFlags flags, +GenericArray _array_alloc_capacity(const WpAllocator *allocator, u64 capacity, ArrayInitFlags flags, u64 item_size); GenericArray _array_from_preallocated_buffer(void *buffer, u64 buffer_size, ArrayInitFlags flags, u64 item_size); diff --git a/src/base/dbl_list/dbl_list.c b/src/base/dbl_list/dbl_list.c index d1a61b3..7e17c75 100644 --- a/src/base/dbl_list/dbl_list.c +++ b/src/base/dbl_list/dbl_list.c @@ -11,10 +11,10 @@ wp_intern GenericList _node_to_list(GenericNode *node, u64 item_size); wp_intern inline void _dbl_list_validate(const GenericList *list, u64 item_size); wp_intern inline void _dbl_list_node_validate(const GenericList *list, const GenericNode *node, u64 item_size); -GenericList *_dbl_list_alloc(const Allocator *allocator, u64 item_size) { +GenericList *_dbl_list_alloc(const WpAllocator *allocator, u64 item_size) { wpDebugAssert(allocator != NULL, "`allocator` should not be NULL"); - GenericList *list = wapp_mem_allocator_alloc(allocator, sizeof(GenericList)); + GenericList *list = wpMemAllocatorAlloc(allocator, sizeof(GenericList)); if (!list) { goto DBL_LIST_ALLOC_RETURN; } memset((void *)list, 0, sizeof(GenericList)); @@ -25,10 +25,10 @@ DBL_LIST_ALLOC_RETURN: return list; } -GenericNode *_dbl_list_node_alloc(const Allocator *allocator, void *item, u64 item_size) { +GenericNode *_dbl_list_node_alloc(const WpAllocator *allocator, void *item, u64 item_size) { wpDebugAssert(allocator != NULL, "`allocator` should not be NULL"); - GenericNode *node = wapp_mem_allocator_alloc(allocator, sizeof(GenericNode)); + GenericNode *node = wpMemAllocatorAlloc(allocator, sizeof(GenericNode)); if (!node) { goto DBL_LIST_NODE_ALLOC_RETURN; } memset((void *)node, 0, sizeof(GenericNode)); diff --git a/src/base/dbl_list/dbl_list.h b/src/base/dbl_list/dbl_list.h index 62f9f9a..bfdd2dc 100644 --- a/src/base/dbl_list/dbl_list.h +++ b/src/base/dbl_list/dbl_list.h @@ -166,8 +166,8 @@ typedef GenericNode WpStr8Node; #define wapp_dbl_list_empty(TYPE, LIST_PTR) \ (_dbl_list_empty(LIST_PTR, sizeof(TYPE))) -GenericList *_dbl_list_alloc(const Allocator *allocator, u64 item_size); -GenericNode *_dbl_list_node_alloc(const Allocator *allocator, void *item, u64 item_size); +GenericList *_dbl_list_alloc(const WpAllocator *allocator, u64 item_size); +GenericNode *_dbl_list_node_alloc(const WpAllocator *allocator, void *item, u64 item_size); GenericNode *_dbl_list_get(const GenericList *list, u64 index, u64 item_size); void _dbl_list_push_front(GenericList *list, GenericNode *node, u64 item_size); void _dbl_list_push_back(GenericList *list, GenericNode *node, u64 item_size); diff --git a/src/base/mem/allocator/mem_allocator.c b/src/base/mem/allocator/mem_allocator.c index bb6820e..216d863 100644 --- a/src/base/mem/allocator/mem_allocator.c +++ b/src/base/mem/allocator/mem_allocator.c @@ -5,28 +5,28 @@ #include "../../../common/assert/assert.h" #include -void *wapp_mem_allocator_alloc(const Allocator *allocator, u64 size) { +void *wpMemAllocatorAlloc(const WpAllocator *allocator, u64 size) { wpDebugAssert(allocator != NULL && (allocator->alloc) != NULL, "`allocator` and `allocator->alloc` should not be NULL"); return allocator->alloc(size, allocator->obj); } -void *wapp_mem_allocator_alloc_aligned(const Allocator *allocator, u64 size, u64 alignment) { +void *wpMemAllocatorAllocAligned(const WpAllocator *allocator, u64 size, u64 alignment) { wpDebugAssert(allocator != NULL && (allocator->alloc_aligned) != NULL, "`allocator` and `allocator->alloc_aligned` should not be NULL"); return allocator->alloc_aligned(size, alignment, allocator->obj); } -void *wapp_mem_allocator_realloc(const Allocator *allocator, void *ptr, u64 old_size, u64 new_size) { +void *wpMemAllocatorRealloc(const WpAllocator *allocator, void *ptr, u64 old_size, u64 new_size) { wpDebugAssert(allocator != NULL && (allocator->realloc) != NULL, "`allocator` and `allocator->realloc` should not be NULL"); return allocator->realloc(ptr, old_size, new_size, allocator->obj); } -void *wapp_mem_allocator_realloc_aligned(const Allocator *allocator, void *ptr, u64 old_size, +void *wpMemAllocatorReallocAligned(const WpAllocator *allocator, void *ptr, u64 old_size, u64 new_size, u64 alignment) { wpDebugAssert(allocator != NULL && (allocator->realloc_aligned) != NULL, "`allocator` and `allocator->realloc_aligned` should not be NULL"); return allocator->realloc_aligned(ptr, old_size, new_size, alignment, allocator->obj); } -void wapp_mem_allocator_free(const Allocator *allocator, void **ptr, u64 size) { +void wpMemAllocatorFree(const WpAllocator *allocator, void **ptr, u64 size) { if (!allocator || !(allocator->free)) { return; } diff --git a/src/base/mem/allocator/mem_allocator.h b/src/base/mem/allocator/mem_allocator.h index da624f9..ac3940f 100644 --- a/src/base/mem/allocator/mem_allocator.h +++ b/src/base/mem/allocator/mem_allocator.h @@ -11,37 +11,37 @@ BEGIN_C_LINKAGE #endif // !WP_PLATFORM_CPP -typedef void *(MemAllocFunc)(u64 size, void *alloc_obj); -typedef void *(MemAllocAlignedFunc)(u64 size, u64 alignment, void *alloc_obj); -typedef void *(MemReallocFunc)(void *ptr, u64 old_size, u64 new_size, void *alloc_obj); -typedef void *(MemReallocAlignedFunc)(void *ptr, u64 old_size, u64 new_size, u64 alignment, void *alloc_obj); -typedef void (MemFreeFunc)(void **ptr, u64 size, void *alloc_obj); +typedef void *(WpMemAllocFunc)(u64 size, void *alloc_obj); +typedef void *(WpMemAllocAlignedFunc)(u64 size, u64 alignment, void *alloc_obj); +typedef void *(WpMemReallocFunc)(void *ptr, u64 old_size, u64 new_size, void *alloc_obj); +typedef void *(WpMemReallocAlignedFunc)(void *ptr, u64 old_size, u64 new_size, u64 alignment, void *alloc_obj); +typedef void (WpMemFreeFunc)(void **ptr, u64 size, void *alloc_obj); -typedef struct Allocator Allocator; -struct Allocator { +typedef struct WpAllocator WpAllocator; +struct WpAllocator { void *obj; - MemAllocFunc *alloc; - MemAllocAlignedFunc *alloc_aligned; - MemReallocFunc *realloc; - MemReallocAlignedFunc *realloc_aligned; - MemFreeFunc *free; + WpMemAllocFunc *alloc; + WpMemAllocAlignedFunc *alloc_aligned; + WpMemReallocFunc *realloc; + WpMemReallocAlignedFunc *realloc_aligned; + WpMemFreeFunc *free; }; #ifdef WP_PLATFORM_CPP -#define wapp_mem_allocator_invalid(ALLOCATOR) ([&]() { \ - Allocator alloc{}; \ - return memcmp(ALLOCATOR, &alloc, sizeof(Allocator)) == 0; \ +#define wpMemAllocatorInvalid(ALLOCATOR) ([&]() { \ + WpAllocator alloc{}; \ + return memcmp(ALLOCATOR, &alloc, sizeof(WpAllocator)) == 0; \ }()) #else -#define wapp_mem_allocator_invalid(ALLOCATOR) (memcmp(ALLOCATOR, &((Allocator){0}), sizeof(Allocator)) == 0) +#define wpMemAllocatorInvalid(ALLOCATOR) (memcmp(ALLOCATOR, &((WpAllocator){0}), sizeof(WpAllocator)) == 0) #endif // !WP_PLATFORM_CPP -void *wapp_mem_allocator_alloc(const Allocator *allocator, u64 size); -void *wapp_mem_allocator_alloc_aligned(const Allocator *allocator, u64 size, u64 alignment); -void *wapp_mem_allocator_realloc(const Allocator *allocator, void *ptr, u64 old_size, u64 new_size); -void *wapp_mem_allocator_realloc_aligned(const Allocator *allocator, void *ptr, u64 old_size, +void *wpMemAllocatorAlloc(const WpAllocator *allocator, u64 size); +void *wpMemAllocatorAllocAligned(const WpAllocator *allocator, u64 size, u64 alignment); +void *wpMemAllocatorRealloc(const WpAllocator *allocator, void *ptr, u64 old_size, u64 new_size); +void *wpMemAllocatorReallocAligned(const WpAllocator *allocator, void *ptr, u64 old_size, u64 new_size, u64 alignment); -void wapp_mem_allocator_free(const Allocator *allocator, void **ptr, u64 size); +void wpMemAllocatorFree(const WpAllocator *allocator, void **ptr, u64 size); #ifdef WP_PLATFORM_CPP END_C_LINKAGE diff --git a/src/base/queue/queue.c b/src/base/queue/queue.c index 8acf56d..f79452b 100644 --- a/src/base/queue/queue.c +++ b/src/base/queue/queue.c @@ -22,7 +22,7 @@ void _queue_push(GenericQueue *queue, void *item, u64 item_size) { } } -GenericQueue *_queue_push_alloc(const Allocator *allocator, GenericQueue *queue, void *item, u64 item_size) { +GenericQueue *_queue_push_alloc(const WpAllocator *allocator, GenericQueue *queue, void *item, u64 item_size) { wpDebugAssert(allocator != NULL && queue != NULL && item != NULL, "`allocator`, `queue` and `item` should not be NULL"); wpRuntimeAssert(item_size == wapp_array_item_size(queue->items), "Invalid type"); @@ -37,7 +37,7 @@ GenericQueue *_queue_push_alloc(const Allocator *allocator, GenericQueue *queue, u64 new_capacity = wpMiscUtilsU64RoundUpPow2(capacity * 2); u64 array_size = _array_calc_alloc_size(new_capacity, item_size); u64 alloc_size = sizeof(GenericQueue) + array_size; - void *buffer = wapp_mem_allocator_alloc(allocator, alloc_size); + void *buffer = wpMemAllocatorAlloc(allocator, alloc_size); if (!buffer) { goto RETURN_QUEUE_PUSH_ALLOC; } diff --git a/src/base/queue/queue.h b/src/base/queue/queue.h index 115587b..ad66aa7 100644 --- a/src/base/queue/queue.h +++ b/src/base/queue/queue.h @@ -90,7 +90,7 @@ typedef GenericQueue WpStr8Queue; ) void _queue_push(GenericQueue *queue, void *item, u64 item_size); -GenericQueue *_queue_push_alloc(const Allocator *allocator, GenericQueue *queue, void *item, u64 item_size); +GenericQueue *_queue_push_alloc(const WpAllocator *allocator, GenericQueue *queue, void *item, u64 item_size); void *_queue_pop(GenericQueue *queue, u64 item_size); #ifdef WP_PLATFORM_CPP diff --git a/src/base/strings/str8/str8.c b/src/base/strings/str8/str8.c index 700956b..898df78 100644 --- a/src/base/strings/str8/str8.c +++ b/src/base/strings/str8/str8.c @@ -13,10 +13,10 @@ #define STR8_BUF_ALLOC_SIZE(CAPACITY) (sizeof(WpStr8) + sizeof(c8) * CAPACITY) -WpStr8 *wpStr8AllocBuf(const Allocator *allocator, u64 capacity) { +WpStr8 *wpStr8AllocBuf(const WpAllocator *allocator, u64 capacity) { wpDebugAssert(allocator != NULL, "`allocator` should not be NULL"); - WpStr8 *str = wapp_mem_allocator_alloc(allocator, STR8_BUF_ALLOC_SIZE(capacity)); + WpStr8 *str = wpMemAllocatorAlloc(allocator, STR8_BUF_ALLOC_SIZE(capacity)); if (!str) { goto RETURN_STR8; } @@ -29,7 +29,7 @@ RETURN_STR8: return str; } -WpStr8 *wpStr8AllocAndFillBuf(const Allocator *allocator, u64 capacity) { +WpStr8 *wpStr8AllocAndFillBuf(const WpAllocator *allocator, u64 capacity) { WpStr8 *out = wpStr8AllocBuf(allocator, capacity); if (out) { memset(out->buf, 0, capacity); @@ -38,7 +38,7 @@ WpStr8 *wpStr8AllocAndFillBuf(const Allocator *allocator, u64 capacity) { return out; } -WpStr8 *wpStr8AllocCstr(const Allocator *allocator, const char *str) { +WpStr8 *wpStr8AllocCstr(const WpAllocator *allocator, const char *str) { wpDebugAssert(allocator != NULL && str != NULL, "`allocator` and `str` should not be NULL"); u64 length = strlen(str); @@ -54,7 +54,7 @@ RETURN_ALLOC_CSTR: return output; } -WpStr8 *wpStr8AllocStr8(const Allocator *allocator, WpStr8RO *str) { +WpStr8 *wpStr8AllocStr8(const WpAllocator *allocator, WpStr8RO *str) { wpDebugAssert(allocator != NULL && str != NULL, "`allocator` and `str` should not be NULL"); WpStr8 *output = wpStr8AllocBuf(allocator, str->capacity); @@ -69,7 +69,7 @@ RETURN_ALLOC_STR8: return output; } -WpStr8 *wpStr8AllocSubstr(const Allocator *allocator, WpStr8RO *str, u64 start, u64 end) { +WpStr8 *wpStr8AllocSubstr(const WpAllocator *allocator, WpStr8RO *str, u64 start, u64 end) { wpDebugAssert(allocator != NULL && str != NULL, "`allocator` and `str` should not be NULL"); WpStr8 *output = NULL; @@ -94,9 +94,9 @@ RETURN_ALLOC_SUBSTR: return output; } -void wpStr8DeallocBuf(const Allocator *allocator, WpStr8 **str) { +void wpStr8DeallocBuf(const WpAllocator *allocator, WpStr8 **str) { wpDebugAssert(allocator != NULL && str != NULL && (*str) != NULL, "Either `allocator` is NULL or `str` is an invalid double pointer"); - wapp_mem_allocator_free(allocator, (void **)str, STR8_BUF_ALLOC_SIZE((*str)->capacity)); + wpMemAllocatorFree(allocator, (void **)str, STR8_BUF_ALLOC_SIZE((*str)->capacity)); } c8 wpStr8Get(const WpStr8 *str, u64 index) { @@ -157,7 +157,7 @@ WpStr8 wpStr8Slice(WpStr8RO *str, u64 start, u64 end) { }; } -WpStr8 *wpStr8AllocConcat(const Allocator *allocator, WpStr8 *dst, WpStr8RO *src) { +WpStr8 *wpStr8AllocConcat(const WpAllocator *allocator, WpStr8 *dst, WpStr8RO *src) { wpDebugAssert(allocator != NULL && dst != NULL && src != NULL, "`allocator`, `dst` and `src` should not be NULL"); WpStr8 *output = NULL; @@ -330,7 +330,7 @@ i64 wpStr8Rfind(WpStr8RO *str, WpStr8RO substr) { return -1; } -WpStr8List *wpStr8SplitWithMax(const Allocator *allocator, WpStr8RO *str, WpStr8RO *delimiter, i64 max_splits) { +WpStr8List *wpStr8SplitWithMax(const WpAllocator *allocator, WpStr8RO *str, WpStr8RO *delimiter, i64 max_splits) { wpDebugAssert(allocator != NULL && str != NULL && delimiter != NULL, "`allocator`, `str` and `delimiter` should not be NULL"); WpStr8List *output = wapp_dbl_list_alloc(WpStr8, allocator); @@ -360,7 +360,7 @@ WpStr8List *wpStr8SplitWithMax(const Allocator *allocator, WpStr8RO *str, WpStr8 wapp_dbl_list_push_back_alloc(WpStr8, allocator, output, before_str); } - wapp_mem_allocator_free(allocator, (void **)&rest, sizeof(WpStr8)); + wpMemAllocatorFree(allocator, (void **)&rest, sizeof(WpStr8)); rest = wpStr8AllocSubstr(allocator, str, start + end + delimiter->size, str->size); start += end + delimiter->size; @@ -377,7 +377,7 @@ RETURN_STR8_SPLIT: return output; } -WpStr8List *wpStr8RsplitWithMax(const Allocator *allocator, WpStr8RO *str, WpStr8RO *delimiter, i64 max_splits) { +WpStr8List *wpStr8RsplitWithMax(const WpAllocator *allocator, WpStr8RO *str, WpStr8RO *delimiter, i64 max_splits) { wpDebugAssert(allocator != NULL && str != NULL && delimiter != NULL, "`allocator`, `str` and `delimiter` should not be NULL"); WpStr8List *output = wapp_dbl_list_alloc(WpStr8, allocator); @@ -406,7 +406,7 @@ WpStr8List *wpStr8RsplitWithMax(const Allocator *allocator, WpStr8RO *str, WpStr wapp_dbl_list_push_front_alloc(WpStr8, allocator, output, after_str); } - wapp_mem_allocator_free(allocator, (void **)&rest, sizeof(WpStr8)); + wpMemAllocatorFree(allocator, (void **)&rest, sizeof(WpStr8)); rest = wpStr8AllocSubstr(allocator, rest, 0, end); ++splits; @@ -421,7 +421,7 @@ RETURN_STR8_SPLIT: return output; } -WpStr8 *wpStr8Join(const Allocator *allocator, const WpStr8List *list, WpStr8RO *delimiter) { +WpStr8 *wpStr8Join(const WpAllocator *allocator, const WpStr8List *list, WpStr8RO *delimiter) { wpDebugAssert(allocator != NULL && list != NULL && delimiter != NULL, "`allocator`, `list` and `delimiter` should not be NULL"); u64 capacity = wpStr8ListTotalSize(list) + (delimiter->size * (list->node_count - 1)); diff --git a/src/base/strings/str8/str8.h b/src/base/strings/str8/str8.h index feff37c..50c7909 100644 --- a/src/base/strings/str8/str8.h +++ b/src/base/strings/str8/str8.h @@ -75,15 +75,15 @@ typedef const WpStr8 WpStr8RO; /** * WpStr8 allocated buffers */ -WpStr8 *wpStr8AllocBuf(const Allocator *allocator, u64 capacity); -WpStr8 *wpStr8AllocAndFillBuf(const Allocator *allocator, u64 capacity); -WpStr8 *wpStr8AllocCstr(const Allocator *allocator, const char *str); -WpStr8 *wpStr8AllocStr8(const Allocator *allocator, WpStr8RO *str); -WpStr8 *wpStr8AllocSubstr(const Allocator *allocator, WpStr8RO *str, u64 start, u64 end); -WpStr8 *wpStr8AllocConcat(const Allocator *allocator, WpStr8 *dst, WpStr8RO *src); +WpStr8 *wpStr8AllocBuf(const WpAllocator *allocator, u64 capacity); +WpStr8 *wpStr8AllocAndFillBuf(const WpAllocator *allocator, u64 capacity); +WpStr8 *wpStr8AllocCstr(const WpAllocator *allocator, const char *str); +WpStr8 *wpStr8AllocStr8(const WpAllocator *allocator, WpStr8RO *str); +WpStr8 *wpStr8AllocSubstr(const WpAllocator *allocator, WpStr8RO *str, u64 start, u64 end); +WpStr8 *wpStr8AllocConcat(const WpAllocator *allocator, WpStr8 *dst, WpStr8RO *src); // Only needed for allocators like malloc where each allocation has to be freed on its own. // No need to use it for allocators like Arena. -void wpStr8DeallocBuf(const Allocator *allocator, WpStr8 **str); +void wpStr8DeallocBuf(const WpAllocator *allocator, WpStr8 **str); /** * WpStr8 utilities @@ -114,9 +114,9 @@ i64 wpStr8Rfind(WpStr8RO *str, WpStr8RO substr); */ #define wpStr8Split(ALLOCATOR, STR, DELIMITER) wpStr8SplitWithMax(ALLOCATOR, STR, DELIMITER, -1) #define wpStr8Rsplit(ALLOCATOR, STR, DELIMITER) wpStr8RsplitWithMax(ALLOCATOR, STR, DELIMITER, -1) -WpStr8List *wpStr8SplitWithMax(const Allocator *allocator, WpStr8RO *str, WpStr8RO *delimiter, i64 max_splits); -WpStr8List *wpStr8RsplitWithMax(const Allocator *allocator, WpStr8RO *str, WpStr8RO *delimiter, i64 max_splits); -WpStr8 *wpStr8Join(const Allocator *allocator, const WpStr8List *list, WpStr8RO *delimiter); +WpStr8List *wpStr8SplitWithMax(const WpAllocator *allocator, WpStr8RO *str, WpStr8RO *delimiter, i64 max_splits); +WpStr8List *wpStr8RsplitWithMax(const WpAllocator *allocator, WpStr8RO *str, WpStr8RO *delimiter, i64 max_splits); +WpStr8 *wpStr8Join(const WpAllocator *allocator, const WpStr8List *list, WpStr8RO *delimiter); /** * WpStr8 list utilities diff --git a/src/os/allocators/arena/mem_arena_allocator.c b/src/os/allocators/arena/mem_arena_allocator.c index af42bac..40be23e 100644 --- a/src/os/allocators/arena/mem_arena_allocator.c +++ b/src/os/allocators/arena/mem_arena_allocator.c @@ -6,15 +6,15 @@ #include "../../../common/aliases/aliases.h" #include "../../../common/assert/assert.h" -wp_intern void initialise_arena_allocator(Allocator *allocator); +wp_intern void initialise_arena_allocator(WpAllocator *allocator); wp_intern void *mem_arena_alloc(u64 size, void *alloc_obj); wp_intern void *mem_arena_alloc_aligned(u64 size, u64 alignment, void *alloc_obj); wp_intern void *mem_arena_realloc(void *ptr, u64 old_size, u64 new_size, void *alloc_obj); wp_intern void *mem_arena_realloc_aligned(void *ptr, u64 old_size, u64 new_size, u64 alignment, void *alloc_obj); -Allocator wapp_mem_arena_allocator_init_with_buffer(u8 *buffer, u64 buffer_size) { - Allocator allocator = {0}; +WpAllocator wapp_mem_arena_allocator_init_with_buffer(u8 *buffer, u64 buffer_size) { + WpAllocator allocator = {0}; b8 initialised = wapp_mem_arena_init_buffer((Arena **)(&allocator.obj), buffer, buffer_size); if (!initialised) { return allocator; @@ -25,8 +25,8 @@ Allocator wapp_mem_arena_allocator_init_with_buffer(u8 *buffer, u64 buffer_size) return allocator; } -Allocator wapp_mem_arena_allocator_init_custom(u64 base_capacity, MemAllocFlags flags, b8 zero_buffer) { - Allocator allocator = {0}; +WpAllocator wapp_mem_arena_allocator_init_custom(u64 base_capacity, MemAllocFlags flags, b8 zero_buffer) { + WpAllocator allocator = {0}; b8 initialised = wapp_mem_arena_init_allocated_custom((Arena **)(&allocator.obj), base_capacity, flags, zero_buffer); if (!initialised) { return allocator; @@ -37,28 +37,28 @@ Allocator wapp_mem_arena_allocator_init_custom(u64 base_capacity, MemAllocFlags return allocator; } -void wapp_mem_arena_allocator_temp_begin(const Allocator *allocator) { +void wapp_mem_arena_allocator_temp_begin(const WpAllocator *allocator) { wpDebugAssert(allocator != NULL, "`allocator` should not be NULL"); wapp_mem_arena_temp_begin((Arena *)(allocator->obj)); } -void wapp_mem_arena_allocator_temp_end(const Allocator *allocator) { +void wapp_mem_arena_allocator_temp_end(const WpAllocator *allocator) { wpDebugAssert(allocator != NULL, "`allocator` should not be NULL"); wapp_mem_arena_temp_end((Arena *)(allocator->obj)); } -void wapp_mem_arena_allocator_clear(Allocator *allocator) { +void wapp_mem_arena_allocator_clear(WpAllocator *allocator) { wpDebugAssert(allocator != NULL, "`allocator` should not be NULL"); wapp_mem_arena_clear((Arena *)(allocator->obj)); } -void wapp_mem_arena_allocator_destroy(Allocator *allocator) { +void wapp_mem_arena_allocator_destroy(WpAllocator *allocator) { wpDebugAssert(allocator != NULL, "`allocator` should not be NULL"); wapp_mem_arena_destroy((Arena **)(&(allocator->obj))); - *allocator = (Allocator){0}; + *allocator = (WpAllocator){0}; } -wp_intern void initialise_arena_allocator(Allocator *allocator) { +wp_intern void initialise_arena_allocator(WpAllocator *allocator) { allocator->alloc = mem_arena_alloc; allocator->alloc_aligned = mem_arena_alloc_aligned; allocator->realloc = mem_arena_realloc; diff --git a/src/os/allocators/arena/mem_arena_allocator.h b/src/os/allocators/arena/mem_arena_allocator.h index bab85e4..7d2924d 100644 --- a/src/os/allocators/arena/mem_arena_allocator.h +++ b/src/os/allocators/arena/mem_arena_allocator.h @@ -22,9 +22,9 @@ BEGIN_C_LINKAGE (wapp_mem_arena_allocator_init_custom(base_capacity, WAPP_MEM_ALLOC_RESERVE | WAPP_MEM_ALLOC_COMMIT, true)) /** - * Wraps an Arena in an Allocator object. It attempts to initialise the Arena + * Wraps an Arena in an WpAllocator object. It attempts to initialise the Arena * and, if successful, defines the operations supported by it to be used by the - * Allocator. + * WpAllocator. * * An Arena allocator only supports normal allocation and aligned allocation. * Reallocation, aligned reallocation and freeing aren't implemented. @@ -32,12 +32,12 @@ BEGIN_C_LINKAGE * The `wapp_mem_arena_allocator_init_custom` provides the most control over how * the Arena is initialised. Wrapper macros are provided for easier use. */ -Allocator wapp_mem_arena_allocator_init_custom(u64 base_capacity, MemAllocFlags flags, b8 zero_buffer); -Allocator wapp_mem_arena_allocator_init_with_buffer(u8 *buffer, u64 buffer_size); -void wapp_mem_arena_allocator_temp_begin(const Allocator *allocator); -void wapp_mem_arena_allocator_temp_end(const Allocator *allocator); -void wapp_mem_arena_allocator_clear(Allocator *allocator); -void wapp_mem_arena_allocator_destroy(Allocator *allocator); +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); #ifdef WP_PLATFORM_CPP END_C_LINKAGE diff --git a/src/os/cpath/cpath.c b/src/os/cpath/cpath.c index f5df78a..114df81 100644 --- a/src/os/cpath/cpath.c +++ b/src/os/cpath/cpath.c @@ -63,7 +63,7 @@ CPATH_JOIN_LOOP_END: return CPATH_JOIN_SUCCESS; } -WpStr8 *dirup(const Allocator *allocator, WpStr8RO *path, u64 levels) { +WpStr8 *dirup(const WpAllocator *allocator, WpStr8RO *path, u64 levels) { WpStr8 *output = NULL; if (!allocator || !path) { goto RETURN_DIRUP; @@ -88,8 +88,8 @@ WpStr8 *dirup(const Allocator *allocator, WpStr8RO *path, u64 levels) { goto RETURN_DIRUP; } - Allocator tmp_arena = wapp_mem_arena_allocator_init(MiB(8)); - if (wapp_mem_allocator_invalid(&tmp_arena)) { + WpAllocator tmp_arena = wapp_mem_arena_allocator_init(MiB(8)); + if (wpMemAllocatorInvalid(&tmp_arena)) { goto RETURN_DIRUP; } diff --git a/src/os/cpath/cpath.h b/src/os/cpath/cpath.h index fa5277c..28783b5 100644 --- a/src/os/cpath/cpath.h +++ b/src/os/cpath/cpath.h @@ -36,7 +36,7 @@ enum { }; u32 wapp_cpath_join_path(WpStr8 *dst, const WpStr8List *parts); -WpStr8 *dirup(const Allocator *allocator, WpStr8RO *path, u64 levels); +WpStr8 *dirup(const WpAllocator *allocator, WpStr8RO *path, u64 levels); #ifdef WP_PLATFORM_CPP END_C_LINKAGE diff --git a/src/os/file/file.c b/src/os/file/file.c index 9876411..79e734f 100644 --- a/src/os/file/file.c +++ b/src/os/file/file.c @@ -7,7 +7,7 @@ #include "../../base/array/array.h" #include "../../base/strings/str8/str8.h" -WFile *wapp_file_open(const Allocator *allocator, WpStr8RO *filepath, FileAccessMode mode) { +WFile *wapp_file_open(const WpAllocator *allocator, WpStr8RO *filepath, FileAccessMode mode) { wpDebugAssert(allocator != NULL && filepath != NULL, "`allocator` and `filepath` should not be NULL"); wpDebugAssert(filepath->size < WAPP_PATH_MAX, "`filepath` exceeds max path limit."); return _file_open(allocator, filepath, mode); diff --git a/src/os/file/file.h b/src/os/file/file.h index b0ba1e6..a6fffec 100644 --- a/src/os/file/file.h +++ b/src/os/file/file.h @@ -46,7 +46,7 @@ wp_extern WFile *wapp_file_stdout(void); // wapp_file_stderr to get the standard error stream wp_extern WFile *wapp_file_stderr(void); -WFile *wapp_file_open(const Allocator *allocator, WpStr8RO *filepath, FileAccessMode mode); +WFile *wapp_file_open(const WpAllocator *allocator, WpStr8RO *filepath, FileAccessMode mode); i64 wapp_file_get_current_position(WFile *file); i64 wapp_file_seek(WFile *file, i64 offset, FileSeekOrigin origin); i64 wapp_file_get_length(WFile *file); @@ -61,7 +61,7 @@ i32 wapp_file_close(WFile *file); i32 wapp_file_rename(WpStr8RO *old_filepath, WpStr8RO *new_filepath); i32 wapp_file_remove(WpStr8RO *filepath); -wp_extern WFile *_file_open(const Allocator *allocator, WpStr8RO *filepath, FileAccessMode mode); +wp_extern WFile *_file_open(const WpAllocator *allocator, WpStr8RO *filepath, FileAccessMode mode); wp_extern i64 _file_seek(WFile *file, i64 offset, FileSeekOrigin origin); wp_extern u64 _file_read(void *dst_buf, u64 byte_count, WFile *file, u64 file_length); wp_extern i64 _file_write(const void *src_buf, WFile *file, u64 byte_count); diff --git a/src/os/file/posix/file_posix.c b/src/os/file/posix/file_posix.c index f597148..39eacd0 100644 --- a/src/os/file/posix/file_posix.c +++ b/src/os/file/posix/file_posix.c @@ -64,7 +64,7 @@ WFile *wapp_file_stderr(void) { return &_stderr; } -WFile *_file_open(const Allocator *allocator, WpStr8RO *filepath, FileAccessMode mode) { +WFile *_file_open(const WpAllocator *allocator, WpStr8RO *filepath, FileAccessMode mode) { wp_persist c8 tmp[WAPP_PATH_MAX] = {0}; memset(tmp, 0, WAPP_PATH_MAX); memcpy(tmp, filepath->buf, filepath->size); @@ -74,7 +74,7 @@ WFile *_file_open(const Allocator *allocator, WpStr8RO *filepath, FileAccessMode return NULL; } - WFile *output = wapp_mem_allocator_alloc(allocator, sizeof(WFile)); + WFile *output = wpMemAllocatorAlloc(allocator, sizeof(WFile)); if (output) { output->fd = fd; } diff --git a/src/os/file/win/file_win.c b/src/os/file/win/file_win.c index e6daa4a..7498a06 100644 --- a/src/os/file/win/file_win.c +++ b/src/os/file/win/file_win.c @@ -72,7 +72,7 @@ WFile *wapp_file_stderr(void) { return &_stderr; } -WFile *_file_open(const Allocator *allocator, WpStr8RO *filepath, FileAccessMode mode) { +WFile *_file_open(const WpAllocator *allocator, WpStr8RO *filepath, FileAccessMode mode) { wp_persist c8 tmp[WAPP_PATH_MAX] = {0}; memset(tmp, 0, WAPP_PATH_MAX); memcpy(tmp, filepath->buf, filepath->size); @@ -88,7 +88,7 @@ WFile *_file_open(const Allocator *allocator, WpStr8RO *filepath, FileAccessMode return NULL; } - WFile *output = wapp_mem_allocator_alloc(allocator, sizeof(WFile)); + WFile *output = wpMemAllocatorAlloc(allocator, sizeof(WFile)); if (output) { output->fh = fh; } diff --git a/src/os/shell/commander/commander.c b/src/os/shell/commander/commander.c index 9d642d7..49a18d1 100644 --- a/src/os/shell/commander/commander.c +++ b/src/os/shell/commander/commander.c @@ -25,7 +25,7 @@ CMDResult wapp_shell_commander_execute(CMDOutHandling out_handling, WpStr8 *out_ return CMD_NO_EXIT(SHELL_ERR_INVALID_ARGS); } - Allocator arena = wapp_mem_arena_allocator_init(KiB(500)); + WpAllocator arena = wapp_mem_arena_allocator_init(KiB(500)); WpStr8 *cmd_str = wpStr8Join(&arena, cmd, &wpStr8LitRo(" ")); if (!cmd_str) { diff --git a/tests/allocator/test_allocator.c b/tests/allocator/test_allocator.c index 66c931e..a0f5715 100644 --- a/tests/allocator/test_allocator.c +++ b/tests/allocator/test_allocator.c @@ -7,15 +7,15 @@ #define TEMP_BUF_SIZE (40 + sizeof(i32) * 8) wp_intern u8 temp_buf[TEMP_BUF_SIZE] = {0}; -wp_intern Allocator temp_allocator = {0}; +wp_intern WpAllocator temp_allocator = {0}; WpTestFuncResult test_arena_allocator(void) { - Allocator allocator = wapp_mem_arena_allocator_init(4096); + WpAllocator allocator = wapp_mem_arena_allocator_init(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 = wapp_mem_allocator_alloc(&allocator, 20); + void *ptr = wpMemAllocatorAlloc(&allocator, 20); result = result && (ptr != NULL); wapp_mem_arena_allocator_destroy(&allocator); @@ -26,12 +26,12 @@ WpTestFuncResult test_arena_allocator(void) { WpTestFuncResult test_arena_allocator_with_buffer(void) { u8 buffer[KiB(4)] = {0}; - Allocator allocator = wapp_mem_arena_allocator_init_with_buffer(buffer, KiB(4)); + WpAllocator allocator = wapp_mem_arena_allocator_init_with_buffer(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 = wapp_mem_allocator_alloc(&allocator, 20); + void *ptr = wpMemAllocatorAlloc(&allocator, 20); result = result && (ptr != NULL); wapp_mem_arena_allocator_destroy(&allocator); @@ -42,13 +42,13 @@ WpTestFuncResult test_arena_allocator_with_buffer(void) { WpTestFuncResult test_arena_allocator_temp_begin(void) { temp_allocator = wapp_mem_arena_allocator_init_with_buffer(temp_buf, TEMP_BUF_SIZE); - i32 *num1 = (i32 *)wapp_mem_allocator_alloc(&temp_allocator, sizeof(i32)); + i32 *num1 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32)); b8 result = num1 != NULL; wapp_mem_arena_allocator_temp_begin(&temp_allocator); - i32 *num2 = (i32 *)wapp_mem_allocator_alloc(&temp_allocator, sizeof(i32)); + i32 *num2 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32)); result = result && num2 != NULL; - i32 *num3 = (i32 *)wapp_mem_allocator_alloc(&temp_allocator, sizeof(i32)); + i32 *num3 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32)); result = result && num3 == NULL; return wpTesterResult(result); @@ -56,9 +56,9 @@ WpTestFuncResult test_arena_allocator_temp_begin(void) { WpTestFuncResult test_arena_allocator_temp_end(void) { wapp_mem_arena_allocator_temp_end(&temp_allocator); - i32 *num1 = (i32 *)wapp_mem_allocator_alloc(&temp_allocator, sizeof(i32)); + i32 *num1 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32)); b8 result = num1 != NULL; - i32 *num2 = (i32 *)wapp_mem_allocator_alloc(&temp_allocator, sizeof(i32)); + i32 *num2 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32)); result = result && num2 == NULL; wapp_mem_arena_allocator_destroy(&temp_allocator); diff --git a/tests/allocator/test_allocator.cc b/tests/allocator/test_allocator.cc index 26c5076..46dc74b 100644 --- a/tests/allocator/test_allocator.cc +++ b/tests/allocator/test_allocator.cc @@ -7,15 +7,15 @@ #define TEMP_BUF_SIZE (40 + sizeof(i32) * 8) wp_intern u8 temp_buf[TEMP_BUF_SIZE] = {}; -wp_intern Allocator temp_allocator = {}; +wp_intern WpAllocator temp_allocator = {}; WpTestFuncResult test_arena_allocator(void) { - Allocator allocator = wapp_mem_arena_allocator_init(4096); + WpAllocator allocator = wapp_mem_arena_allocator_init(4096); b8 result = allocator.obj != nullptr && allocator.alloc != nullptr && allocator.alloc_aligned != nullptr && allocator.realloc != nullptr && allocator.realloc_aligned != nullptr && allocator.free == nullptr; - void *ptr = wapp_mem_allocator_alloc(&allocator, 20); + void *ptr = wpMemAllocatorAlloc(&allocator, 20); result = result && (ptr != nullptr); wapp_mem_arena_allocator_destroy(&allocator); @@ -26,12 +26,12 @@ WpTestFuncResult test_arena_allocator(void) { WpTestFuncResult test_arena_allocator_with_buffer(void) { u8 buffer[KiB(4)] = {0}; - Allocator allocator = wapp_mem_arena_allocator_init_with_buffer(buffer, KiB(4)); + WpAllocator allocator = wapp_mem_arena_allocator_init_with_buffer(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 = wapp_mem_allocator_alloc(&allocator, 20); + void *ptr = wpMemAllocatorAlloc(&allocator, 20); result = result && (ptr != NULL); wapp_mem_arena_allocator_destroy(&allocator); @@ -42,13 +42,13 @@ WpTestFuncResult test_arena_allocator_with_buffer(void) { WpTestFuncResult test_arena_allocator_temp_begin(void) { temp_allocator = wapp_mem_arena_allocator_init_with_buffer(temp_buf, TEMP_BUF_SIZE); - i32 *num1 = (i32 *)wapp_mem_allocator_alloc(&temp_allocator, sizeof(i32)); + i32 *num1 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32)); b8 result = num1 != NULL; wapp_mem_arena_allocator_temp_begin(&temp_allocator); - i32 *num2 = (i32 *)wapp_mem_allocator_alloc(&temp_allocator, sizeof(i32)); + i32 *num2 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32)); result = result && num2 != NULL; - i32 *num3 = (i32 *)wapp_mem_allocator_alloc(&temp_allocator, sizeof(i32)); + i32 *num3 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32)); result = result && num3 == NULL; return wpTesterResult(result); @@ -56,9 +56,9 @@ WpTestFuncResult test_arena_allocator_temp_begin(void) { WpTestFuncResult test_arena_allocator_temp_end(void) { wapp_mem_arena_allocator_temp_end(&temp_allocator); - i32 *num1 = (i32 *)wapp_mem_allocator_alloc(&temp_allocator, sizeof(i32)); + i32 *num1 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32)); b8 result = num1 != NULL; - i32 *num2 = (i32 *)wapp_mem_allocator_alloc(&temp_allocator, sizeof(i32)); + i32 *num2 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32)); result = result && num2 == NULL; wapp_mem_arena_allocator_destroy(&temp_allocator); diff --git a/tests/array/test_i32_array.c b/tests/array/test_i32_array.c index 28a8780..d2f70c4 100644 --- a/tests/array/test_i32_array.c +++ b/tests/array/test_i32_array.c @@ -148,7 +148,7 @@ WpTestFuncResult test_i32_array_copy_capped(void) { WpTestFuncResult test_i32_array_alloc_capacity(void) { b8 result; - Allocator allocator = wapp_mem_arena_allocator_init(MiB(4)); + WpAllocator allocator = wapp_mem_arena_allocator_init(MiB(4)); u64 capacity = 32; I32Array array = wapp_array_alloc_capacity(i32, &allocator, capacity, ARRAY_INIT_NONE); @@ -162,7 +162,7 @@ WpTestFuncResult test_i32_array_alloc_capacity(void) { WpTestFuncResult test_i32_array_append_alloc(void) { b8 result; - Allocator allocator = wapp_mem_arena_allocator_init(MiB(4)); + WpAllocator allocator = wapp_mem_arena_allocator_init(MiB(4)); I32Array array1 = wapp_array(i32, 1, 2, 3, 4, 5, 6, 7, 8); I32Array array2 = wapp_array(i32, 1, 2); @@ -189,7 +189,7 @@ WpTestFuncResult test_i32_array_append_alloc(void) { WpTestFuncResult test_i32_array_extend_alloc(void) { b8 result; - Allocator allocator = wapp_mem_arena_allocator_init(MiB(4)); + WpAllocator allocator = wapp_mem_arena_allocator_init(MiB(4)); I32Array array1 = wapp_array(i32, 1, 2, 3, 4, 5, 6, 7, 8); I32Array array2 = wapp_array(i32, 1, 2); I32Array array3 = wapp_array(i32, 1, 2, 3, 4); @@ -208,7 +208,7 @@ WpTestFuncResult test_i32_array_extend_alloc(void) { WpTestFuncResult test_i32_array_copy_alloc(void) { b8 result; - Allocator allocator = wapp_mem_arena_allocator_init(MiB(4)); + WpAllocator allocator = wapp_mem_arena_allocator_init(MiB(4)); I32Array src = wapp_array(i32, 1, 2, 3, 4, 5); I32Array dst1 = wapp_array(i32, 1, 2, 3, 4, 5, 6); I32Array dst2 = wapp_array(i32, 1, 2); diff --git a/tests/array/test_i32_array.cc b/tests/array/test_i32_array.cc index e90e87d..a26fc03 100644 --- a/tests/array/test_i32_array.cc +++ b/tests/array/test_i32_array.cc @@ -150,7 +150,7 @@ WpTestFuncResult test_i32_array_copy_capped(void) { WpTestFuncResult test_i32_array_alloc_capacity(void) { b8 result; - Allocator allocator = wapp_mem_arena_allocator_init(MiB(4)); + WpAllocator allocator = wapp_mem_arena_allocator_init(MiB(4)); u64 capacity = 32; I32Array array = wapp_array_alloc_capacity(i32, &allocator, capacity, ARRAY_INIT_NONE); @@ -164,7 +164,7 @@ WpTestFuncResult test_i32_array_alloc_capacity(void) { WpTestFuncResult test_i32_array_append_alloc(void) { b8 result; - Allocator allocator = wapp_mem_arena_allocator_init(MiB(4)); + WpAllocator allocator = wapp_mem_arena_allocator_init(MiB(4)); I32Array array1 = wapp_array(i32, 1, 2, 3, 4, 5, 6, 7, 8); I32Array array2 = wapp_array(i32, 1, 2); @@ -192,7 +192,7 @@ WpTestFuncResult test_i32_array_append_alloc(void) { WpTestFuncResult test_i32_array_extend_alloc(void) { b8 result; - Allocator allocator = wapp_mem_arena_allocator_init(MiB(4)); + WpAllocator allocator = wapp_mem_arena_allocator_init(MiB(4)); I32Array array1 = wapp_array(i32, 1, 2, 3, 4, 5, 6, 7, 8); I32Array array2 = wapp_array(i32, 1, 2); I32Array array3 = wapp_array(i32, 1, 2, 3, 4); @@ -211,7 +211,7 @@ WpTestFuncResult test_i32_array_extend_alloc(void) { WpTestFuncResult test_i32_array_copy_alloc(void) { b8 result; - Allocator allocator = wapp_mem_arena_allocator_init(MiB(4)); + WpAllocator allocator = wapp_mem_arena_allocator_init(MiB(4)); I32Array src = wapp_array(i32, 1, 2, 3, 4, 5); I32Array dst1 = wapp_array(i32, 1, 2, 3, 4, 5, 6); I32Array dst2 = wapp_array(i32, 1, 2); diff --git a/tests/cpath/test_cpath.c b/tests/cpath/test_cpath.c index 0006c29..5a6562a 100644 --- a/tests/cpath/test_cpath.c +++ b/tests/cpath/test_cpath.c @@ -81,8 +81,8 @@ WpTestFuncResult test_cpath_join_path(void) { } WpTestFuncResult test_cpath_dirname(void) { - Allocator arena = wapp_mem_arena_allocator_init(MiB(8)); - if (wapp_mem_allocator_invalid(&arena)) { + WpAllocator arena = wapp_mem_arena_allocator_init(MiB(8)); + if (wpMemAllocatorInvalid(&arena)) { return wpTesterResult(false); } @@ -129,8 +129,8 @@ WpTestFuncResult test_cpath_dirname(void) { } WpTestFuncResult test_cpath_dirup(void) { - Allocator arena = wapp_mem_arena_allocator_init(MiB(8)); - if (wapp_mem_allocator_invalid(&arena)) { + WpAllocator arena = wapp_mem_arena_allocator_init(MiB(8)); + if (wpMemAllocatorInvalid(&arena)) { return wpTesterResult(false); } diff --git a/tests/cpath/test_cpath.cc b/tests/cpath/test_cpath.cc index d9d9e1f..334e50f 100644 --- a/tests/cpath/test_cpath.cc +++ b/tests/cpath/test_cpath.cc @@ -99,8 +99,8 @@ WpTestFuncResult test_cpath_join_path(void) { } WpTestFuncResult test_cpath_dirname(void) { - Allocator arena = wapp_mem_arena_allocator_init(MiB(8)); - if (wapp_mem_allocator_invalid(&arena)) { + WpAllocator arena = wapp_mem_arena_allocator_init(MiB(8)); + if (wpMemAllocatorInvalid(&arena)) { return wpTesterResult(false); } @@ -149,8 +149,8 @@ WpTestFuncResult test_cpath_dirname(void) { } WpTestFuncResult test_cpath_dirup(void) { - Allocator arena = wapp_mem_arena_allocator_init(MiB(8)); - if (wapp_mem_allocator_invalid(&arena)) { + WpAllocator arena = wapp_mem_arena_allocator_init(MiB(8)); + if (wpMemAllocatorInvalid(&arena)) { return wpTesterResult(false); } diff --git a/tests/file/test_file.c b/tests/file/test_file.c index 09aa20a..4d2c827 100644 --- a/tests/file/test_file.c +++ b/tests/file/test_file.c @@ -3,7 +3,7 @@ #include "test_file.h" #define DST_CAPACITY 5 -wp_intern Allocator arena = {0}; +wp_intern WpAllocator arena = {0}; wp_intern WpStr8RO test_filename = wpStr8LitRoInitialiserList("wapptest.bin"); wp_intern WpStr8RO new_filename = wpStr8LitRoInitialiserList("wapptest2.bin"); wp_intern WFile *test_fp = NULL; diff --git a/tests/file/test_file.cc b/tests/file/test_file.cc index 0e61fe1..8eea795 100644 --- a/tests/file/test_file.cc +++ b/tests/file/test_file.cc @@ -3,7 +3,7 @@ #include "test_file.h" #define DST_CAPACITY 5 -wp_intern Allocator arena = {}; +wp_intern WpAllocator arena = {}; wp_intern WpStr8RO test_filename = wpStr8LitRoInitialiserList("wapptest.bin"); wp_intern WpStr8RO new_filename = wpStr8LitRoInitialiserList("wapptest2.bin"); wp_intern WFile *test_fp = NULL; diff --git a/tests/queue/test_queue.c b/tests/queue/test_queue.c index bd13729..f13b51e 100644 --- a/tests/queue/test_queue.c +++ b/tests/queue/test_queue.c @@ -23,7 +23,7 @@ WpTestFuncResult test_queue_push(void) { } WpTestFuncResult test_queue_push_alloc(void) { - Allocator arena = wapp_mem_arena_allocator_init(MiB(64)); + WpAllocator arena = wapp_mem_arena_allocator_init(MiB(64)); I32Queue queue = wapp_queue(i32, CAPACITY); for (u64 i = 0; i < CAPACITY; ++i) { diff --git a/tests/queue/test_queue.cc b/tests/queue/test_queue.cc index 9e0e2f9..bc48c9b 100644 --- a/tests/queue/test_queue.cc +++ b/tests/queue/test_queue.cc @@ -21,7 +21,7 @@ WpTestFuncResult test_queue_push(void) { } WpTestFuncResult test_queue_push_alloc(void) { - Allocator arena = wapp_mem_arena_allocator_init(MiB(64)); + WpAllocator arena = wapp_mem_arena_allocator_init(MiB(64)); I32Queue queue = wapp_queue(i32, CAPACITY); for (u64 i = 0; i < CAPACITY; ++i) { diff --git a/tests/str8/test_str8.c b/tests/str8/test_str8.c index 162b32c..2951858 100644 --- a/tests/str8/test_str8.c +++ b/tests/str8/test_str8.c @@ -77,8 +77,8 @@ WpTestFuncResult test_str8_buf(void) { WpTestFuncResult test_str8_alloc_buf(void) { b8 result; - Allocator allocator = wapp_mem_arena_allocator_init(KiB(100)); - if (wapp_mem_allocator_invalid(&allocator)) { + WpAllocator allocator = wapp_mem_arena_allocator_init(KiB(100)); + if (wpMemAllocatorInvalid(&allocator)) { return wpTesterResult(false); } @@ -105,8 +105,8 @@ TEST_ALLOC_BUF_CLEANUP: WpTestFuncResult test_str8_alloc_cstr(void) { b8 result; - Allocator allocator = wapp_mem_arena_allocator_init(KiB(100)); - if (wapp_mem_allocator_invalid(&allocator)) { + WpAllocator allocator = wapp_mem_arena_allocator_init(KiB(100)); + if (wpMemAllocatorInvalid(&allocator)) { return wpTesterResult(false); } @@ -126,8 +126,8 @@ WpTestFuncResult test_str8_alloc_cstr(void) { WpTestFuncResult test_str8_alloc_str8(void) { b8 result; - Allocator allocator = wapp_mem_arena_allocator_init(KiB(100)); - if (wapp_mem_allocator_invalid(&allocator)) { + WpAllocator allocator = wapp_mem_arena_allocator_init(KiB(100)); + if (wpMemAllocatorInvalid(&allocator)) { return wpTesterResult(false); } @@ -146,8 +146,8 @@ WpTestFuncResult test_str8_alloc_str8(void) { WpTestFuncResult test_str8_alloc_substr(void) { b8 result; - Allocator allocator = wapp_mem_arena_allocator_init(KiB(100)); - if (wapp_mem_allocator_invalid(&allocator)) { + WpAllocator allocator = wapp_mem_arena_allocator_init(KiB(100)); + if (wpMemAllocatorInvalid(&allocator)) { return wpTesterResult(false); } @@ -289,7 +289,7 @@ WpTestFuncResult test_str8_slice(void) { WpTestFuncResult test_str8_alloc_concat(void) { b8 result; - Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); + WpAllocator arena = wapp_mem_arena_allocator_init(KiB(100)); WpStr8 str = wpStr8Lit("Hello world"); WpStr8 suffix1 = wpStr8Lit(" from me."); @@ -410,7 +410,7 @@ WpTestFuncResult test_str8_rfind(void) { WpTestFuncResult test_str8_split(void) { b8 result; - Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); + WpAllocator arena = wapp_mem_arena_allocator_init(KiB(100)); WpStr8 str = wpStr8Lit("hello world from me"); WpStr8 delim1 = wpStr8Lit(" "); @@ -467,7 +467,7 @@ WpTestFuncResult test_str8_split(void) { WpTestFuncResult test_str8_split_with_max(void) { b8 result; - Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); + WpAllocator arena = wapp_mem_arena_allocator_init(KiB(100)); WpStr8 str = wpStr8Lit("hello world from me"); WpStr8 delim = wpStr8Lit(" "); @@ -502,7 +502,7 @@ WpTestFuncResult test_str8_split_with_max(void) { WpTestFuncResult test_str8_rsplit(void) { b8 result; - Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); + WpAllocator arena = wapp_mem_arena_allocator_init(KiB(100)); WpStr8 str = wpStr8Lit("hello world from me"); WpStr8 delim1 = wpStr8Lit(" "); @@ -559,7 +559,7 @@ WpTestFuncResult test_str8_rsplit(void) { WpTestFuncResult test_str8_rsplit_with_max(void) { b8 result; - Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); + WpAllocator arena = wapp_mem_arena_allocator_init(KiB(100)); WpStr8 str = wpStr8Lit("hello world from me"); WpStr8 delim = wpStr8Lit(" "); @@ -594,7 +594,7 @@ WpTestFuncResult test_str8_rsplit_with_max(void) { WpTestFuncResult test_str8_join(void) { b8 result; - Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); + WpAllocator arena = wapp_mem_arena_allocator_init(KiB(100)); WpStr8 str = wpStr8Lit("hello world from me"); WpStr8 delim1 = wpStr8Lit(" "); diff --git a/tests/str8/test_str8.cc b/tests/str8/test_str8.cc index 9b3bf57..cfd0917 100644 --- a/tests/str8/test_str8.cc +++ b/tests/str8/test_str8.cc @@ -77,8 +77,8 @@ WpTestFuncResult test_str8_buf(void) { WpTestFuncResult test_str8_alloc_buf(void) { b8 result; - Allocator allocator = wapp_mem_arena_allocator_init(KiB(100)); - if (wapp_mem_allocator_invalid(&allocator)) { + WpAllocator allocator = wapp_mem_arena_allocator_init(KiB(100)); + if (wpMemAllocatorInvalid(&allocator)) { return wpTesterResult(false); } @@ -105,8 +105,8 @@ WpTestFuncResult test_str8_alloc_buf(void) { WpTestFuncResult test_str8_alloc_cstr(void) { b8 result; - Allocator allocator = wapp_mem_arena_allocator_init(KiB(100)); - if (wapp_mem_allocator_invalid(&allocator)) { + WpAllocator allocator = wapp_mem_arena_allocator_init(KiB(100)); + if (wpMemAllocatorInvalid(&allocator)) { return wpTesterResult(false); } @@ -126,8 +126,8 @@ WpTestFuncResult test_str8_alloc_cstr(void) { WpTestFuncResult test_str8_alloc_str8(void) { b8 result; - Allocator allocator = wapp_mem_arena_allocator_init(KiB(100)); - if (wapp_mem_allocator_invalid(&allocator)) { + WpAllocator allocator = wapp_mem_arena_allocator_init(KiB(100)); + if (wpMemAllocatorInvalid(&allocator)) { return wpTesterResult(false); } @@ -146,8 +146,8 @@ WpTestFuncResult test_str8_alloc_str8(void) { WpTestFuncResult test_str8_alloc_substr(void) { b8 result; - Allocator allocator = wapp_mem_arena_allocator_init(KiB(100)); - if (wapp_mem_allocator_invalid(&allocator)) { + WpAllocator allocator = wapp_mem_arena_allocator_init(KiB(100)); + if (wpMemAllocatorInvalid(&allocator)) { return wpTesterResult(false); } @@ -289,7 +289,7 @@ WpTestFuncResult test_str8_slice(void) { WpTestFuncResult test_str8_alloc_concat(void) { b8 result; - Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); + WpAllocator arena = wapp_mem_arena_allocator_init(KiB(100)); WpStr8 str = wpStr8Lit("Hello world"); WpStr8 suffix1 = wpStr8Lit(" from me."); @@ -410,7 +410,7 @@ WpTestFuncResult test_str8_rfind(void) { WpTestFuncResult test_str8_split(void) { b8 result; - Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); + WpAllocator arena = wapp_mem_arena_allocator_init(KiB(100)); WpStr8 str = wpStr8Lit("hello world from me"); WpStr8 delim1 = wpStr8Lit(" "); @@ -467,7 +467,7 @@ WpTestFuncResult test_str8_split(void) { WpTestFuncResult test_str8_split_with_max(void) { b8 result; - Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); + WpAllocator arena = wapp_mem_arena_allocator_init(KiB(100)); WpStr8 str = wpStr8Lit("hello world from me"); WpStr8 delim = wpStr8Lit(" "); @@ -502,7 +502,7 @@ WpTestFuncResult test_str8_split_with_max(void) { WpTestFuncResult test_str8_rsplit(void) { b8 result; - Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); + WpAllocator arena = wapp_mem_arena_allocator_init(KiB(100)); WpStr8 str = wpStr8Lit("hello world from me"); WpStr8 delim1 = wpStr8Lit(" "); @@ -559,7 +559,7 @@ WpTestFuncResult test_str8_rsplit(void) { WpTestFuncResult test_str8_rsplit_with_max(void) { b8 result; - Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); + WpAllocator arena = wapp_mem_arena_allocator_init(KiB(100)); WpStr8 str = wpStr8Lit("hello world from me"); WpStr8 delim = wpStr8Lit(" "); @@ -594,7 +594,7 @@ WpTestFuncResult test_str8_rsplit_with_max(void) { WpTestFuncResult test_str8_join(void) { b8 result; - Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); + WpAllocator arena = wapp_mem_arena_allocator_init(KiB(100)); WpStr8 str = wpStr8Lit("hello world from me"); WpStr8 delim1 = wpStr8Lit(" ");