Rename mem allocator
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -5,28 +5,28 @@
|
||||
#include "../../../common/assert/assert.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
+2
-2
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
+14
-14
@@ -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(" ");
|
||||
|
||||
+14
-14
@@ -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(" ");
|
||||
|
||||
Reference in New Issue
Block a user