This commit is contained in:
@@ -17,10 +17,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- Add `wpU8Const`, `wpU16Const`, `wpU32Const`, `wpU64Const`, `wpI8Const`, `wpI16Const`, `wpI32Const`, and `wpI64Const`
|
||||
- `wpPrngXorshiftInitWithSeed` to allow for user control with PRNG
|
||||
- `wpPrngXorshift256InRange`, `wpPrngXorshift256ssInRange`, `wpPrngXorshift256pInRange`, `wpPrngXorshift256Choice`, `wpPrngXorshift256ssChoice` and `wpPrngXorshift256pChoice` utilities
|
||||
- `wpStr8Clear`
|
||||
|
||||
### Changed
|
||||
|
||||
- Switched to using `wpMiscUtilsRotl64` in `xorshift`
|
||||
- Remove all uses of names starting with underscore
|
||||
|
||||
## [2.4.0] - 2026-08-30
|
||||
|
||||
|
||||
+72
-72
@@ -7,81 +7,81 @@
|
||||
#include "../../common/aliases/aliases.h"
|
||||
#include <stddef.h>
|
||||
|
||||
#define _arrayHeader(ARRAY) (WpArrayHeader *)(wpMiscUtilsOffsetPointer(ARRAY, (i64)sizeof(WpArrayHeader) * -1))
|
||||
#define arrayHeader(ARRAY) (WpArrayHeader *)(wpMiscUtilsOffsetPointer(ARRAY, (i64)sizeof(WpArrayHeader) * -1))
|
||||
|
||||
wp_persist inline void _arrayValidate(const WpArray array, u64 item_size);
|
||||
wp_persist inline void arrayValidate(const WpArray array, u64 item_size);
|
||||
|
||||
u64 _arrayCount(WpArray array) {
|
||||
u64 arrayCount(WpArray array) {
|
||||
wpDebugAssert(array != NULL, "`array` should not be NULL");
|
||||
|
||||
WpArrayHeader *header = _arrayHeader(array);
|
||||
WpArrayHeader *header = arrayHeader(array);
|
||||
wpRuntimeAssert(WP_ARRAY_MAGIC == header->magic, "`array` is not a valid wapp array");
|
||||
|
||||
return header->count;
|
||||
}
|
||||
|
||||
u64 _arrayCapacity(WpArray array) {
|
||||
u64 arrayCapacity(WpArray array) {
|
||||
wpDebugAssert(array != NULL, "`array` should not be NULL");
|
||||
|
||||
WpArrayHeader *header = _arrayHeader(array);
|
||||
WpArrayHeader *header = arrayHeader(array);
|
||||
wpRuntimeAssert(WP_ARRAY_MAGIC == header->magic, "`array` is not a valid wapp array");
|
||||
|
||||
return header->capacity;
|
||||
}
|
||||
|
||||
u64 _arrayItemSize(WpArray array) {
|
||||
u64 arrayItemSize(WpArray array) {
|
||||
wpDebugAssert(array != NULL, "`array` should not be NULL");
|
||||
|
||||
WpArrayHeader *header = _arrayHeader(array);
|
||||
WpArrayHeader *header = arrayHeader(array);
|
||||
wpRuntimeAssert(WP_ARRAY_MAGIC == header->magic, "`array` is not a valid wapp array");
|
||||
|
||||
return header->item_size;
|
||||
}
|
||||
|
||||
void _arraySetCount(WpArray array, u64 count) {
|
||||
void arraySetCount(WpArray array, u64 count) {
|
||||
wpDebugAssert(array != NULL, "`array` should not be NULL");
|
||||
|
||||
WpArrayHeader *header = _arrayHeader(array);
|
||||
WpArrayHeader *header = arrayHeader(array);
|
||||
wpRuntimeAssert(WP_ARRAY_MAGIC == header->magic, "`array` is not a valid wapp array");
|
||||
|
||||
header->count = count;
|
||||
}
|
||||
|
||||
void *_arrayGet(WpArray array, u64 index, u64 item_size) {
|
||||
void *arrayGet(WpArray array, u64 index, u64 item_size) {
|
||||
wpRuntimeAssert(array != NULL, "`array` should not be NULL");
|
||||
_arrayValidate(array, item_size);
|
||||
arrayValidate(array, item_size);
|
||||
|
||||
WpArrayHeader *header = _arrayHeader(array);
|
||||
WpArrayHeader *header = arrayHeader(array);
|
||||
wpRuntimeAssert(index < header->count, "`index` is out of bounds");
|
||||
|
||||
return wpMiscUtilsOffsetPointer(array, header->item_size * index);
|
||||
}
|
||||
|
||||
void _arraySet(WpArray array, u64 index, void *value, u64 item_size) {
|
||||
void *item = _arrayGet(array, index, item_size);
|
||||
void arraySet(WpArray array, u64 index, void *value, u64 item_size) {
|
||||
void *item = arrayGet(array, index, item_size);
|
||||
|
||||
WpArrayHeader *header = _arrayHeader(array);
|
||||
WpArrayHeader *header = arrayHeader(array);
|
||||
memcpy(item, value, header->item_size);
|
||||
}
|
||||
|
||||
void _arrayAppendCapped(WpArray array, void *value, u64 item_size) {
|
||||
void arrayAppendCapped(WpArray array, void *value, u64 item_size) {
|
||||
wpRuntimeAssert(array != NULL, "`array` should not be NULL");
|
||||
_arrayValidate(array, item_size);
|
||||
arrayValidate(array, item_size);
|
||||
|
||||
WpArrayHeader *header = _arrayHeader(array);
|
||||
WpArrayHeader *header = arrayHeader(array);
|
||||
if (header->count >= header->capacity) { return; }
|
||||
|
||||
u64 index = (header->count)++;
|
||||
_arraySet(array, index, value, item_size);
|
||||
arraySet(array, index, value, item_size);
|
||||
}
|
||||
|
||||
void _arrayExtendCappend(WpArray dst, const WpArray src, u64 item_size) {
|
||||
void arrayExtendCappend(WpArray dst, const WpArray src, u64 item_size) {
|
||||
wpRuntimeAssert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL");
|
||||
_arrayValidate(dst, item_size);
|
||||
_arrayValidate(src, item_size);
|
||||
arrayValidate(dst, item_size);
|
||||
arrayValidate(src, item_size);
|
||||
|
||||
WpArrayHeader *src_header = _arrayHeader(src);
|
||||
WpArrayHeader *dst_header = _arrayHeader(dst);
|
||||
WpArrayHeader *src_header = arrayHeader(src);
|
||||
WpArrayHeader *dst_header = arrayHeader(dst);
|
||||
u64 remaining_capacity = dst_header->capacity - dst_header->count;
|
||||
|
||||
u64 copy_count = src_header->count < remaining_capacity ? src_header->count : remaining_capacity;
|
||||
@@ -90,94 +90,94 @@ void _arrayExtendCappend(WpArray dst, const WpArray src, u64 item_size) {
|
||||
dst_header->count += copy_count;
|
||||
}
|
||||
|
||||
void _arrayCopyCapped(WpArray dst, const WpArray src, u64 item_size) {
|
||||
void arrayCopyCapped(WpArray dst, const WpArray src, u64 item_size) {
|
||||
wpRuntimeAssert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL");
|
||||
_arrayValidate(dst, item_size);
|
||||
_arrayValidate(src, item_size);
|
||||
arrayValidate(dst, item_size);
|
||||
arrayValidate(src, item_size);
|
||||
|
||||
_arrayClear(dst, item_size);
|
||||
arrayClear(dst, item_size);
|
||||
|
||||
WpArrayHeader *src_header = _arrayHeader(src);
|
||||
WpArrayHeader *dst_header = _arrayHeader(dst);
|
||||
WpArrayHeader *src_header = arrayHeader(src);
|
||||
WpArrayHeader *dst_header = arrayHeader(dst);
|
||||
u64 copy_count = src_header->count < dst_header->capacity ? src_header->count : dst_header->capacity;
|
||||
memcpy((void *)dst, (void *)src, copy_count * src_header->item_size);
|
||||
dst_header->count = copy_count;
|
||||
}
|
||||
|
||||
WpArray _arrayAppendAlloc(const WpAllocator *allocator, WpArray array, void *value,
|
||||
WpArray arrayAppendAlloc(const WpAllocator *allocator, WpArray array, void *value,
|
||||
WpArrayInitFlags flags, u64 item_size) {
|
||||
wpRuntimeAssert(allocator != NULL && array != NULL, "`allocator` and `array` should not be NULL");
|
||||
_arrayValidate(array, item_size);
|
||||
arrayValidate(array, item_size);
|
||||
|
||||
WpArray output = array;
|
||||
|
||||
WpArrayHeader *header = _arrayHeader(array);
|
||||
WpArrayHeader *header = arrayHeader(array);
|
||||
if (header->count >= header->capacity) {
|
||||
u64 new_capacity = wpMiscUtilsU64RoundUpPow2(header->capacity * 2);
|
||||
output = (WpArray )_arrayAllocCapacity(allocator, new_capacity, flags,
|
||||
output = (WpArray )arrayAllocCapacity(allocator, new_capacity, flags,
|
||||
header->item_size);
|
||||
if (!output) {
|
||||
output = array;
|
||||
goto RETURN_ARRAY_APPEND_ALLOC;
|
||||
}
|
||||
_arrayCopyCapped(output, array, item_size);
|
||||
arrayCopyCapped(output, array, item_size);
|
||||
}
|
||||
|
||||
_arrayAppendCapped(output, value, item_size);
|
||||
arrayAppendCapped(output, value, item_size);
|
||||
|
||||
if ((flags & WP_ARRAY_INIT_FILLED) == WP_ARRAY_INIT_FILLED) {
|
||||
_arraySetCount(output, _arrayCapacity(output));
|
||||
arraySetCount(output, arrayCapacity(output));
|
||||
}
|
||||
|
||||
RETURN_ARRAY_APPEND_ALLOC:
|
||||
return output;
|
||||
}
|
||||
|
||||
WpArray _arrayExtendAlloc(const WpAllocator *allocator, WpArray dst, const WpArray src,
|
||||
WpArray arrayExtendAlloc(const WpAllocator *allocator, WpArray dst, const WpArray src,
|
||||
WpArrayInitFlags flags, u64 item_size) {
|
||||
wpRuntimeAssert(allocator != NULL && dst != NULL && src != NULL, "`allocator`, `dst` and `src` should not be NULL");
|
||||
_arrayValidate(dst, item_size);
|
||||
_arrayValidate(src, item_size);
|
||||
arrayValidate(dst, item_size);
|
||||
arrayValidate(src, item_size);
|
||||
|
||||
WpArray output = dst;
|
||||
|
||||
WpArrayHeader *src_header = _arrayHeader(src);
|
||||
WpArrayHeader *dst_header = _arrayHeader(dst);
|
||||
WpArrayHeader *src_header = arrayHeader(src);
|
||||
WpArrayHeader *dst_header = arrayHeader(dst);
|
||||
u64 remaining_capacity = dst_header->capacity - dst_header->count;
|
||||
if (src_header->count >= remaining_capacity) {
|
||||
u64 new_capacity = wpMiscUtilsU64RoundUpPow2(dst_header->capacity * 2);
|
||||
output = (WpArray )_arrayAllocCapacity(allocator, new_capacity,
|
||||
output = (WpArray )arrayAllocCapacity(allocator, new_capacity,
|
||||
flags, dst_header->item_size);
|
||||
if (!output) {
|
||||
output = dst;
|
||||
goto RETURN_ARRAY_EXTEND_ALLOC;
|
||||
}
|
||||
_arrayCopyCapped(output, dst, item_size);
|
||||
arrayCopyCapped(output, dst, item_size);
|
||||
}
|
||||
|
||||
_arrayExtendCappend(output, src, item_size);
|
||||
arrayExtendCappend(output, src, item_size);
|
||||
|
||||
if ((flags & WP_ARRAY_INIT_FILLED) == WP_ARRAY_INIT_FILLED) {
|
||||
_arraySetCount(output, _arrayCapacity(output));
|
||||
arraySetCount(output, arrayCapacity(output));
|
||||
}
|
||||
|
||||
RETURN_ARRAY_EXTEND_ALLOC:
|
||||
return output;
|
||||
}
|
||||
|
||||
WpArray _arrayCopyAlloc(const WpAllocator *allocator, WpArray dst, const WpArray src,
|
||||
WpArray arrayCopyAlloc(const WpAllocator *allocator, WpArray dst, const WpArray src,
|
||||
WpArrayInitFlags flags, u64 item_size) {
|
||||
wpRuntimeAssert(allocator != NULL && dst != NULL && src != NULL, "`allocator`, `dst` and `src` should not be NULL");
|
||||
_arrayValidate(dst, item_size);
|
||||
_arrayValidate(src, item_size);
|
||||
arrayValidate(dst, item_size);
|
||||
arrayValidate(src, item_size);
|
||||
|
||||
WpArray output = dst;
|
||||
|
||||
WpArrayHeader *src_header = _arrayHeader(src);
|
||||
WpArrayHeader *dst_header = _arrayHeader(dst);
|
||||
WpArrayHeader *src_header = arrayHeader(src);
|
||||
WpArrayHeader *dst_header = arrayHeader(dst);
|
||||
if (src_header->count >= dst_header->capacity) {
|
||||
u64 new_capacity = wpMiscUtilsU64RoundUpPow2(dst_header->capacity * 2);
|
||||
output = (WpArray )_arrayAllocCapacity(allocator, new_capacity,
|
||||
output = (WpArray )arrayAllocCapacity(allocator, new_capacity,
|
||||
flags, src_header->item_size);
|
||||
if (!output) {
|
||||
output = dst;
|
||||
@@ -185,61 +185,61 @@ WpArray _arrayCopyAlloc(const WpAllocator *allocator, WpArray dst, const WpArray
|
||||
}
|
||||
}
|
||||
|
||||
_arrayCopyCapped(output, src, item_size);
|
||||
arrayCopyCapped(output, src, item_size);
|
||||
|
||||
if ((flags & WP_ARRAY_INIT_FILLED) == WP_ARRAY_INIT_FILLED) {
|
||||
_arraySetCount(output, _arrayCapacity(output));
|
||||
arraySetCount(output, arrayCapacity(output));
|
||||
}
|
||||
|
||||
RETURN_ARRAY_COPY_ALLOC:
|
||||
return output;
|
||||
}
|
||||
|
||||
void *_arrayPop(WpArray array, u64 item_size) {
|
||||
void *arrayPop(WpArray array, u64 item_size) {
|
||||
wpRuntimeAssert(array != NULL, "`array` should not be NULL");
|
||||
_arrayValidate(array, item_size);
|
||||
arrayValidate(array, item_size);
|
||||
|
||||
WpArrayHeader *header = _arrayHeader(array);
|
||||
WpArrayHeader *header = arrayHeader(array);
|
||||
if (header->count == 0) { return NULL; }
|
||||
|
||||
u64 index = header->count - 1;
|
||||
void *out = _arrayGet(array, index, item_size);
|
||||
void *out = arrayGet(array, index, item_size);
|
||||
--(header->count);
|
||||
return out;
|
||||
}
|
||||
|
||||
void _arrayClear(WpArray array, u64 item_size) {
|
||||
void arrayClear(WpArray array, u64 item_size) {
|
||||
wpRuntimeAssert(array != NULL, "`array` should not be NULL");
|
||||
_arrayValidate(array, item_size);
|
||||
arrayValidate(array, item_size);
|
||||
|
||||
WpArrayHeader *header = _arrayHeader(array);
|
||||
WpArrayHeader *header = arrayHeader(array);
|
||||
header->count = 0;
|
||||
}
|
||||
|
||||
u64 _arrayCalcAllocSize(u64 capacity, u64 item_size) {
|
||||
u64 arrayCalcAllocSize(u64 capacity, u64 item_size) {
|
||||
return sizeof(WpArrayHeader) + item_size * capacity;
|
||||
}
|
||||
|
||||
WpArray _arrayAllocCapacity(const WpAllocator *allocator, u64 capacity, WpArrayInitFlags flags,
|
||||
WpArray arrayAllocCapacity(const WpAllocator *allocator, u64 capacity, WpArrayInitFlags flags,
|
||||
u64 item_size) {
|
||||
wpRuntimeAssert(allocator != NULL, "`allocator` should not be NULL");
|
||||
|
||||
WpArray output = NULL;
|
||||
|
||||
u64 allocation_size = _arrayCalcAllocSize(capacity, item_size);
|
||||
u64 allocation_size = arrayCalcAllocSize(capacity, item_size);
|
||||
void *buffer = wpMemAllocatorAlloc(allocator, allocation_size);
|
||||
if (!buffer) {
|
||||
goto RETURN_ARRAY_ALLOC;
|
||||
}
|
||||
|
||||
output = _arrayFromPreallocatedBuffer(buffer, allocation_size, flags, item_size);
|
||||
output = arrayFromPreallocatedBuffer(buffer, allocation_size, flags, item_size);
|
||||
|
||||
RETURN_ARRAY_ALLOC:
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
WpArray _arrayFromPreallocatedBuffer(void *buffer, u64 buffer_size, WpArrayInitFlags flags,
|
||||
WpArray arrayFromPreallocatedBuffer(void *buffer, u64 buffer_size, WpArrayInitFlags flags,
|
||||
u64 item_size) {
|
||||
wpRuntimeAssert(buffer != NULL, "`buffer` should not be NULL");
|
||||
|
||||
@@ -259,18 +259,18 @@ WpArray _arrayFromPreallocatedBuffer(void *buffer, u64 buffer_size, WpArrayInitF
|
||||
return output;
|
||||
}
|
||||
|
||||
void _arrayDealloc(const WpAllocator *allocator, WpArray *array, u64 item_size) {
|
||||
void arrayDealloc(const WpAllocator *allocator, WpArray *array, u64 item_size) {
|
||||
wpRuntimeAssert(allocator != NULL, "`allocator` should not be NULL");
|
||||
|
||||
u64 capacity = wpArrayCapacity(*array);
|
||||
u64 allocation_size = _arrayCalcAllocSize(capacity, item_size);
|
||||
void *header = (void *)_arrayHeader(*array);
|
||||
u64 allocation_size = arrayCalcAllocSize(capacity, item_size);
|
||||
void *header = (void *)arrayHeader(*array);
|
||||
wpMemAllocatorFree(allocator, &header, allocation_size);
|
||||
*array = NULL;
|
||||
}
|
||||
|
||||
wp_persist inline void _arrayValidate(const WpArray array, u64 item_size) {
|
||||
WpArrayHeader *header = _arrayHeader(array);
|
||||
wp_persist inline void arrayValidate(const WpArray array, u64 item_size) {
|
||||
WpArrayHeader *header = arrayHeader(array);
|
||||
wpRuntimeAssert(WP_ARRAY_MAGIC == header->magic, "`array` is not a valid wapp array");
|
||||
wpRuntimeAssert(item_size == header->item_size, "Invalid item type provided");
|
||||
}
|
||||
|
||||
+73
-73
@@ -14,8 +14,8 @@ BEGIN_C_LINKAGE
|
||||
|
||||
#define WP_ARRAY_MAGIC wpU64Const(0x57415f415252)
|
||||
|
||||
#define _calcArrayCount(TYPE, ...) wpMiscUtilsVaArgsCount(TYPE, __VA_ARGS__)
|
||||
#define _calcArrayCapacity(TYPE, ...) wpMiscUtilsU64RoundUpPow2(_calcArrayCount(TYPE, __VA_ARGS__) * 2)
|
||||
#define calcArrayCount(TYPE, ...) wpMiscUtilsVaArgsCount(TYPE, __VA_ARGS__)
|
||||
#define calcArrayCapacity(TYPE, ...) wpMiscUtilsU64RoundUpPow2(calcArrayCount(TYPE, __VA_ARGS__) * 2)
|
||||
|
||||
typedef struct WpStr8 WpStr8;
|
||||
|
||||
@@ -48,17 +48,17 @@ typedef enum {
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
#define wpArray(TYPE, ...) ([&]() { \
|
||||
u64 capacity = _calcArrayCapacity(TYPE, __VA_ARGS__); \
|
||||
u64 capacity = calcArrayCapacity(TYPE, __VA_ARGS__); \
|
||||
\
|
||||
TYPE items[_calcArrayCapacity(TYPE, __VA_ARGS__)] = {__VA_ARGS__}; \
|
||||
TYPE items[calcArrayCapacity(TYPE, __VA_ARGS__)] = {__VA_ARGS__}; \
|
||||
\
|
||||
wp_persist u8 array[ \
|
||||
sizeof(WpArrayHeader) + _calcArrayCapacity(TYPE, __VA_ARGS__) * sizeof(TYPE) \
|
||||
sizeof(WpArrayHeader) + calcArrayCapacity(TYPE, __VA_ARGS__) * sizeof(TYPE) \
|
||||
] = {0}; \
|
||||
WpArrayHeader *header = (WpArrayHeader *)array; \
|
||||
header->magic = WP_ARRAY_MAGIC; \
|
||||
header->count = _calcArrayCount(TYPE, __VA_ARGS__); \
|
||||
header->capacity = _calcArrayCapacity(TYPE, __VA_ARGS__); \
|
||||
header->count = calcArrayCount(TYPE, __VA_ARGS__); \
|
||||
header->capacity = calcArrayCapacity(TYPE, __VA_ARGS__); \
|
||||
header->item_size = sizeof(TYPE); \
|
||||
\
|
||||
u8 *buf = (u8 *)(header + 1); \
|
||||
@@ -78,25 +78,25 @@ typedef enum {
|
||||
return (TYPE *)(header + 1); \
|
||||
}())
|
||||
#define wpArrayPop(TYPE, ARRAY) ([&]() { \
|
||||
if (ARRAY == NULL || _arrayCount((WpArray)ARRAY) == 0) { \
|
||||
if (ARRAY == NULL || arrayCount((WpArray)ARRAY) == 0) { \
|
||||
TYPE result{}; \
|
||||
return result; \
|
||||
} \
|
||||
\
|
||||
return *((TYPE *)_arrayPop((WpArray)ARRAY, sizeof(TYPE))); \
|
||||
return *((TYPE *)arrayPop((WpArray)ARRAY, sizeof(TYPE))); \
|
||||
}())
|
||||
#else
|
||||
#define _stackArray(TYPE, SIZE) struct {WpArrayHeader header; \
|
||||
#define stackArray(TYPE, SIZE) struct {WpArrayHeader header; \
|
||||
TYPE items[SIZE]; \
|
||||
wpMiscUtilsReservePadding(sizeof(WpArrayHeader) + \
|
||||
sizeof(TYPE) * SIZE);}
|
||||
#define wpArray(TYPE, ...) \
|
||||
((TYPE *)( \
|
||||
(_stackArray(TYPE, _calcArrayCapacity(TYPE, __VA_ARGS__))){ \
|
||||
(stackArray(TYPE, calcArrayCapacity(TYPE, __VA_ARGS__))){ \
|
||||
.header = { \
|
||||
.magic = WP_ARRAY_MAGIC, \
|
||||
.count = _calcArrayCount(TYPE, __VA_ARGS__), \
|
||||
.capacity = _calcArrayCapacity(TYPE, __VA_ARGS__), \
|
||||
.count = calcArrayCount(TYPE, __VA_ARGS__), \
|
||||
.capacity = calcArrayCapacity(TYPE, __VA_ARGS__), \
|
||||
.item_size = sizeof(TYPE), \
|
||||
}, \
|
||||
.items = {__VA_ARGS__}, \
|
||||
@@ -104,7 +104,7 @@ typedef enum {
|
||||
))
|
||||
#define wpArrayWithCapacity(TYPE, CAPACITY, FLAGS) \
|
||||
((TYPE *)( \
|
||||
(_stackArray(TYPE, CAPACITY)){ \
|
||||
(stackArray(TYPE, CAPACITY)){ \
|
||||
.header = { \
|
||||
.magic = WP_ARRAY_MAGIC, \
|
||||
.count = (FLAGS & WP_ARRAY_INIT_FILLED) ? CAPACITY : 0, \
|
||||
@@ -115,71 +115,71 @@ typedef enum {
|
||||
}.items \
|
||||
))
|
||||
#define wpArrayPop(TYPE, ARRAY) \
|
||||
(ARRAY == NULL || _arrayCount((WpArray)ARRAY) == 0 ? \
|
||||
(ARRAY == NULL || arrayCount((WpArray)ARRAY) == 0 ? \
|
||||
(TYPE){0} : \
|
||||
*((TYPE *)_arrayPop((WpArray)ARRAY, sizeof(TYPE))) \
|
||||
*((TYPE *)arrayPop((WpArray)ARRAY, sizeof(TYPE))) \
|
||||
)
|
||||
#endif // !WP_PLATFORM_CPP
|
||||
|
||||
#define wpArrayCount(ARRAY) \
|
||||
(_arrayCount((WpArray)ARRAY))
|
||||
(arrayCount((WpArray)ARRAY))
|
||||
#define wpArrayCapacity(ARRAY) \
|
||||
(_arrayCapacity((WpArray)ARRAY))
|
||||
(arrayCapacity((WpArray)ARRAY))
|
||||
#define wpArrayItemSize(ARRAY) \
|
||||
(_arrayItemSize((WpArray)ARRAY))
|
||||
(arrayItemSize((WpArray)ARRAY))
|
||||
#define wpArraySetCount(ARRAY, COUNT) \
|
||||
(_arraySetCount((WpArray)ARRAY, COUNT))
|
||||
(arraySetCount((WpArray)ARRAY, COUNT))
|
||||
#define wpArrayGet(TYPE, ARRAY, INDEX) \
|
||||
((TYPE *)_arrayGet((WpArray)ARRAY, \
|
||||
INDEX, \
|
||||
sizeof(TYPE)))
|
||||
((TYPE *)arrayGet((WpArray)ARRAY, \
|
||||
INDEX, \
|
||||
sizeof(TYPE)))
|
||||
#define wpArraySet(TYPE, ARRAY, INDEX, VALUE_PTR) \
|
||||
(_arraySet((WpArray)ARRAY, \
|
||||
INDEX, \
|
||||
(u8 *)VALUE_PTR, \
|
||||
sizeof(TYPE)))
|
||||
(arraySet((WpArray)ARRAY, \
|
||||
INDEX, \
|
||||
(u8 *)VALUE_PTR, \
|
||||
sizeof(TYPE)))
|
||||
#define wpArrayAppendCapped(TYPE, ARRAY, VALUE_PTR) \
|
||||
(_arrayAppendCapped((WpArray)ARRAY, \
|
||||
(u8 *)VALUE_PTR, \
|
||||
sizeof(TYPE)))
|
||||
(arrayAppendCapped((WpArray)ARRAY, \
|
||||
(u8 *)VALUE_PTR, \
|
||||
sizeof(TYPE)))
|
||||
#define wpArrayExtendCapped(TYPE, DST_ARRAY, SRC_ARRAY) \
|
||||
(_arrayExtendCappend((WpArray)DST_ARRAY, \
|
||||
(WpArray)SRC_ARRAY, \
|
||||
sizeof(TYPE)))
|
||||
#define wpArrayCopyCapped(TYPE, DST_ARRAY, SRC_ARRAY) \
|
||||
(_arrayCopyCapped((WpArray)DST_ARRAY, \
|
||||
(arrayExtendCappend((WpArray)DST_ARRAY, \
|
||||
(WpArray)SRC_ARRAY, \
|
||||
sizeof(TYPE)))
|
||||
#define wpArrayCopyCapped(TYPE, DST_ARRAY, SRC_ARRAY) \
|
||||
(arrayCopyCapped((WpArray)DST_ARRAY, \
|
||||
(WpArray)SRC_ARRAY, \
|
||||
sizeof(TYPE)))
|
||||
#define wpArrayAppendAlloc(TYPE, ALLOCATOR_PTR, ARRAY, VALUE_PTR, FLAGS) \
|
||||
((TYPE *)_arrayAppendAlloc(ALLOCATOR_PTR, \
|
||||
(WpArray)ARRAY, \
|
||||
(u8 *)VALUE_PTR, \
|
||||
FLAGS, \
|
||||
sizeof(TYPE)))
|
||||
((TYPE *)arrayAppendAlloc(ALLOCATOR_PTR, \
|
||||
(WpArray)ARRAY, \
|
||||
(u8 *)VALUE_PTR, \
|
||||
FLAGS, \
|
||||
sizeof(TYPE)))
|
||||
#define wpArrayExtendAlloc(TYPE, ALLOCATOR_PTR, DST_ARRAY, SRC_ARRAY, FLAGS) \
|
||||
((TYPE *)_arrayExtendAlloc(ALLOCATOR_PTR, \
|
||||
(WpArray)DST_ARRAY, \
|
||||
(WpArray)SRC_ARRAY, \
|
||||
FLAGS, \
|
||||
sizeof(TYPE)))
|
||||
((TYPE *)arrayExtendAlloc(ALLOCATOR_PTR, \
|
||||
(WpArray)DST_ARRAY, \
|
||||
(WpArray)SRC_ARRAY, \
|
||||
FLAGS, \
|
||||
sizeof(TYPE)))
|
||||
#define wpArrayCopyAlloc(TYPE, ALLOCATOR_PTR, DST_ARRAY, SRC_ARRAY, FLAGS) \
|
||||
((TYPE *)_arrayCopyAlloc(ALLOCATOR_PTR, \
|
||||
(WpArray)DST_ARRAY, \
|
||||
(WpArray)SRC_ARRAY, \
|
||||
FLAGS, \
|
||||
sizeof(TYPE)))
|
||||
((TYPE *)arrayCopyAlloc(ALLOCATOR_PTR, \
|
||||
(WpArray)DST_ARRAY, \
|
||||
(WpArray)SRC_ARRAY, \
|
||||
FLAGS, \
|
||||
sizeof(TYPE)))
|
||||
#define wpArrayClear(TYPE, ARRAY) \
|
||||
(_arrayClear((WpArray)ARRAY, \
|
||||
(arrayClear((WpArray)ARRAY, \
|
||||
sizeof(TYPE)))
|
||||
#define wpArrayCalcAllocSize(TYPE, CAPACITY) _arrayCalcAllocSize(CAPACITY, sizeof(TYPE))
|
||||
#define wpArrayCalcAllocSize(TYPE, CAPACITY) arrayCalcAllocSize(CAPACITY, sizeof(TYPE))
|
||||
#define wpArrayAllocCapacity(TYPE, ALLOCATOR_PTR, CAPACITY, FLAGS) \
|
||||
((TYPE *)_arrayAllocCapacity(ALLOCATOR_PTR, CAPACITY, FLAGS, sizeof(TYPE)))
|
||||
((TYPE *)arrayAllocCapacity(ALLOCATOR_PTR, CAPACITY, FLAGS, sizeof(TYPE)))
|
||||
#define wpArrayFromPreallcatedBuffer(TYPE, BUFFER, BUFFER_SIZE) \
|
||||
((TYPE *)_array_from_preallcated_buffer(BUFFER, BUFFER_SIZE, sizeof(TYPE)))
|
||||
((TYPE *)array_from_preallcated_buffer(BUFFER, BUFFER_SIZE, sizeof(TYPE)))
|
||||
// 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.
|
||||
#define wpArrayDealloc(TYPE, ALLOCATOR_PTR, ARRAY_DPTR) \
|
||||
(_arrayDealloc(ALLOCATOR_PTR, (WpArray *)ARRAY_DPTR, sizeof(TYPE)))
|
||||
(arrayDealloc(ALLOCATOR_PTR, (WpArray *)ARRAY_DPTR, sizeof(TYPE)))
|
||||
|
||||
|
||||
typedef struct WpArrayHeader WpArrayHeader;
|
||||
@@ -190,29 +190,29 @@ struct WpArrayHeader {
|
||||
u64 item_size;
|
||||
};
|
||||
|
||||
u64 _arrayCount(WpArray array);
|
||||
u64 _arrayCapacity(WpArray array);
|
||||
u64 _arrayItemSize(WpArray array);
|
||||
void _arraySetCount(WpArray array, u64 count);
|
||||
void *_arrayGet(WpArray array, u64 index, u64 item_size);
|
||||
void _arraySet(WpArray array, u64 index, void *value, u64 item_size);
|
||||
void _arrayAppendCapped(WpArray array, void *value, u64 item_size);
|
||||
void _arrayExtendCappend(WpArray dst, const WpArray src, u64 item_size);
|
||||
void _arrayCopyCapped(WpArray dst, const WpArray src, u64 item_size);
|
||||
WpArray _arrayAppendAlloc(const WpAllocator *allocator, WpArray array, void *value,
|
||||
u64 arrayCount(WpArray array);
|
||||
u64 arrayCapacity(WpArray array);
|
||||
u64 arrayItemSize(WpArray array);
|
||||
void arraySetCount(WpArray array, u64 count);
|
||||
void *arrayGet(WpArray array, u64 index, u64 item_size);
|
||||
void arraySet(WpArray array, u64 index, void *value, u64 item_size);
|
||||
void arrayAppendCapped(WpArray array, void *value, u64 item_size);
|
||||
void arrayExtendCappend(WpArray dst, const WpArray src, u64 item_size);
|
||||
void arrayCopyCapped(WpArray dst, const WpArray src, u64 item_size);
|
||||
WpArray arrayAppendAlloc(const WpAllocator *allocator, WpArray array, void *value,
|
||||
WpArrayInitFlags flags, u64 item_size);
|
||||
WpArray _arrayExtendAlloc(const WpAllocator *allocator, WpArray dst, const WpArray src,
|
||||
WpArray arrayExtendAlloc(const WpAllocator *allocator, WpArray dst, const WpArray src,
|
||||
WpArrayInitFlags flags, u64 item_size);
|
||||
WpArray _arrayCopyAlloc(const WpAllocator *allocator, WpArray dst, const WpArray src,
|
||||
WpArray arrayCopyAlloc(const WpAllocator *allocator, WpArray dst, const WpArray src,
|
||||
WpArrayInitFlags flags, u64 item_size);
|
||||
void *_arrayPop(WpArray array, u64 item_size);
|
||||
void _arrayClear(WpArray array, u64 item_size);
|
||||
u64 _arrayCalcAllocSize(u64 capacity, u64 item_size);
|
||||
WpArray _arrayAllocCapacity(const WpAllocator *allocator, u64 capacity, WpArrayInitFlags flags,
|
||||
void *arrayPop(WpArray array, u64 item_size);
|
||||
void arrayClear(WpArray array, u64 item_size);
|
||||
u64 arrayCalcAllocSize(u64 capacity, u64 item_size);
|
||||
WpArray arrayAllocCapacity(const WpAllocator *allocator, u64 capacity, WpArrayInitFlags flags,
|
||||
u64 item_size);
|
||||
WpArray _arrayFromPreallocatedBuffer(void *buffer, u64 buffer_size, WpArrayInitFlags flags,
|
||||
WpArray arrayFromPreallocatedBuffer(void *buffer, u64 buffer_size, WpArrayInitFlags flags,
|
||||
u64 item_size);
|
||||
void _arrayDealloc(const WpAllocator *allocator, WpArray *array, u64 item_size);
|
||||
void arrayDealloc(const WpAllocator *allocator, WpArray *array, u64 item_size);
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
#include "../../common/platform/platform.h"
|
||||
#include <stddef.h>
|
||||
|
||||
wp_intern WpDblList _node_to_list(WpDblNode *node, u64 item_size);
|
||||
wp_intern inline void _dblListValidate(const WpDblList *list, u64 item_size);
|
||||
wp_intern inline void _dblListNodeValidate(const WpDblList *list, const WpDblNode *node, u64 item_size);
|
||||
wp_intern WpDblList nodeToList(WpDblNode *node, u64 item_size);
|
||||
wp_intern inline void dblListValidate(const WpDblList *list, u64 item_size);
|
||||
wp_intern inline void dblListNodeValidate(const WpDblList *list, const WpDblNode *node, u64 item_size);
|
||||
|
||||
WpDblList *_dblListAlloc(const WpAllocator *allocator, u64 item_size) {
|
||||
WpDblList *dblListAlloc(const WpAllocator *allocator, u64 item_size) {
|
||||
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
|
||||
|
||||
WpDblList *list = wpMemAllocatorAlloc(allocator, sizeof(WpDblList));
|
||||
@@ -25,7 +25,7 @@ DBL_LIST_ALLOC_RETURN:
|
||||
return list;
|
||||
}
|
||||
|
||||
WpDblNode *_dblListNodeAlloc(const WpAllocator *allocator, void *item, u64 item_size) {
|
||||
WpDblNode *dblListNodeAlloc(const WpAllocator *allocator, void *item, u64 item_size) {
|
||||
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
|
||||
|
||||
WpDblNode *node = wpMemAllocatorAlloc(allocator, sizeof(WpDblNode));
|
||||
@@ -40,9 +40,9 @@ DBL_LIST_NODE_ALLOC_RETURN:
|
||||
return node;
|
||||
}
|
||||
|
||||
WpDblNode *_dblListGet(const WpDblList *list, u64 index, u64 item_size) {
|
||||
WpDblNode *dblListGet(const WpDblList *list, u64 index, u64 item_size) {
|
||||
wpDebugAssert(list != NULL, "`list` should not be NULL");
|
||||
_dblListValidate(list, item_size);
|
||||
dblListValidate(list, item_size);
|
||||
wpRuntimeAssert(index < list->node_count, "`index` is out of bounds");
|
||||
|
||||
WpDblNode *output = NULL;
|
||||
@@ -56,12 +56,12 @@ WpDblNode *_dblListGet(const WpDblList *list, u64 index, u64 item_size) {
|
||||
return output;
|
||||
}
|
||||
|
||||
void _dblListPushFront(WpDblList *list, WpDblNode *node, u64 item_size) {
|
||||
void dblListPushFront(WpDblList *list, WpDblNode *node, u64 item_size) {
|
||||
wpDebugAssert(list != NULL && node != NULL && (node->item) != NULL, "`list`, `node` and `node->item` should not be NULL");
|
||||
_dblListValidate(list, item_size);
|
||||
_dblListNodeValidate(list, node, item_size);
|
||||
dblListValidate(list, item_size);
|
||||
dblListNodeValidate(list, node, item_size);
|
||||
|
||||
WpDblList node_list = _node_to_list(node, item_size);
|
||||
WpDblList node_list = nodeToList(node, item_size);
|
||||
|
||||
if (list->node_count == 0) {
|
||||
*list = node_list;
|
||||
@@ -79,12 +79,12 @@ void _dblListPushFront(WpDblList *list, WpDblNode *node, u64 item_size) {
|
||||
node_list.last->header.next = first;
|
||||
}
|
||||
|
||||
void _dblListPushBack(WpDblList *list, WpDblNode *node, u64 item_size) {
|
||||
void dblListPushBack(WpDblList *list, WpDblNode *node, u64 item_size) {
|
||||
wpDebugAssert(list != NULL && node != NULL && (node->item) != NULL, "`list`, `node` and `node->item` should not be NULL");
|
||||
_dblListValidate(list, item_size);
|
||||
_dblListNodeValidate(list, node, item_size);
|
||||
dblListValidate(list, item_size);
|
||||
dblListNodeValidate(list, node, item_size);
|
||||
|
||||
WpDblList node_list = _node_to_list(node, item_size);
|
||||
WpDblList node_list = nodeToList(node, item_size);
|
||||
|
||||
if (list->node_count == 0) {
|
||||
*list = node_list;
|
||||
@@ -102,25 +102,25 @@ void _dblListPushBack(WpDblList *list, WpDblNode *node, u64 item_size) {
|
||||
node_list.first->header.prev = last;
|
||||
}
|
||||
|
||||
void _dblListInsert(WpDblList *list, WpDblNode *node, u64 index, u64 item_size) {
|
||||
void dblListInsert(WpDblList *list, WpDblNode *node, u64 index, u64 item_size) {
|
||||
wpDebugAssert(list != NULL && node != NULL && (node->item) != NULL, "`list`, `node` and `node->item` should not be NULL");
|
||||
_dblListValidate(list, item_size);
|
||||
_dblListNodeValidate(list, node, item_size);
|
||||
dblListValidate(list, item_size);
|
||||
dblListNodeValidate(list, node, item_size);
|
||||
|
||||
if (index == 0) {
|
||||
_dblListPushFront(list, node, item_size);
|
||||
dblListPushFront(list, node, item_size);
|
||||
return;
|
||||
} else if (index == list->node_count) {
|
||||
_dblListPushBack(list, node, item_size);
|
||||
dblListPushBack(list, node, item_size);
|
||||
return;
|
||||
}
|
||||
|
||||
WpDblNode *dst_node = _dblListGet(list, index, item_size);
|
||||
WpDblNode *dst_node = dblListGet(list, index, item_size);
|
||||
if (!dst_node) {
|
||||
return;
|
||||
}
|
||||
|
||||
WpDblList node_list = _node_to_list(node, item_size);
|
||||
WpDblList node_list = nodeToList(node, item_size);
|
||||
|
||||
list->node_count += node_list.node_count;
|
||||
|
||||
@@ -133,9 +133,9 @@ void _dblListInsert(WpDblList *list, WpDblNode *node, u64 index, u64 item_size)
|
||||
node_list.last->header.next = dst_node;
|
||||
}
|
||||
|
||||
WpDblNode *_dblListPopFront(WpDblList *list, u64 item_size) {
|
||||
WpDblNode *dblListPopFront(WpDblList *list, u64 item_size) {
|
||||
wpDebugAssert(list != NULL, "`list` should not be NULL");
|
||||
_dblListValidate(list, item_size);
|
||||
dblListValidate(list, item_size);
|
||||
|
||||
WpDblNode *output = NULL;
|
||||
|
||||
@@ -159,9 +159,9 @@ RETURN_LIST_POP_FRONT:
|
||||
return output;
|
||||
}
|
||||
|
||||
WpDblNode *_dblListPopBack(WpDblList *list, u64 item_size) {
|
||||
WpDblNode *dblListPopBack(WpDblList *list, u64 item_size) {
|
||||
wpDebugAssert(list != NULL, "`list` should not be NULL");
|
||||
_dblListValidate(list, item_size);
|
||||
dblListValidate(list, item_size);
|
||||
|
||||
WpDblNode *output = NULL;
|
||||
|
||||
@@ -185,21 +185,21 @@ RETURN_LIST_POP_BACK:
|
||||
return output;
|
||||
}
|
||||
|
||||
WpDblNode *_dblListRemove(WpDblList *list, u64 index, u64 item_size) {
|
||||
WpDblNode *dblListRemove(WpDblList *list, u64 index, u64 item_size) {
|
||||
wpDebugAssert(list != NULL, "`list` should not be NULL");
|
||||
_dblListValidate(list, item_size);
|
||||
dblListValidate(list, item_size);
|
||||
|
||||
WpDblNode *output = NULL;
|
||||
|
||||
if (index == 0) {
|
||||
output = _dblListPopFront(list, item_size);
|
||||
output = dblListPopFront(list, item_size);
|
||||
goto RETURN_LIST_REMOVE;
|
||||
} else if (index == list->node_count) {
|
||||
output = _dblListPopBack(list, item_size);
|
||||
output = dblListPopBack(list, item_size);
|
||||
goto RETURN_LIST_REMOVE;
|
||||
}
|
||||
|
||||
output = _dblListGet(list, index, item_size);
|
||||
output = dblListGet(list, index, item_size);
|
||||
if (!output) {
|
||||
goto RETURN_LIST_REMOVE;
|
||||
}
|
||||
@@ -215,17 +215,17 @@ RETURN_LIST_REMOVE:
|
||||
return output;
|
||||
}
|
||||
|
||||
void _dblListEmpty(WpDblList *list, u64 item_size) {
|
||||
void dblListEmpty(WpDblList *list, u64 item_size) {
|
||||
wpDebugAssert(list != NULL, "`list` should not be NULL");
|
||||
_dblListValidate(list, item_size);
|
||||
dblListValidate(list, item_size);
|
||||
|
||||
u64 count = list->node_count;
|
||||
for (u64 i = 0; i < count; ++i) {
|
||||
_dblListPopBack(list, item_size);
|
||||
dblListPopBack(list, item_size);
|
||||
}
|
||||
}
|
||||
|
||||
wp_intern WpDblList _node_to_list(WpDblNode *node, u64 item_size) {
|
||||
wp_intern WpDblList nodeToList(WpDblNode *node, u64 item_size) {
|
||||
WpDblList output = {
|
||||
.magic = WP_DBL_LIST_MAGIC,
|
||||
.first = node,
|
||||
@@ -247,12 +247,12 @@ wp_intern WpDblList _node_to_list(WpDblNode *node, u64 item_size) {
|
||||
return output;
|
||||
}
|
||||
|
||||
wp_intern inline void _dblListValidate(const WpDblList *list, u64 item_size) {
|
||||
wp_intern inline void dblListValidate(const WpDblList *list, u64 item_size) {
|
||||
wpRuntimeAssert(list->magic == WP_DBL_LIST_MAGIC, "`list` isn't a valid wp list type");
|
||||
wpRuntimeAssert(list->item_size == item_size, "Invalid item provided");
|
||||
}
|
||||
|
||||
wp_intern inline void _dblListNodeValidate(const WpDblList *list, const WpDblNode *node, u64 item_size) {
|
||||
wp_intern inline void dblListNodeValidate(const WpDblList *list, const WpDblNode *node, u64 item_size) {
|
||||
wpRuntimeAssert(node->header.magic == WP_DBL_NODE_MAGIC, "`node` isn't a valid wp node type");
|
||||
wpRuntimeAssert(list->item_size == node->header.item_size, "Mismatched `list` and `node` types");
|
||||
wpRuntimeAssert(node->header.item_size == item_size, "Invalid item provided");
|
||||
|
||||
@@ -81,7 +81,7 @@ typedef WpDblNode WpStr8Node;
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
#define wpDblList(TYPE) \
|
||||
WpDblList{WP_DBL_LIST_MAGIC, 0, sizeof(TYPE), nullptr, nullptr}
|
||||
#define _dblListNode(TYPE, ITEM_PTR) ([&]() { \
|
||||
#define dblListNode(TYPE, ITEM_PTR) ([&]() { \
|
||||
wp_persist WpDblNode node = { \
|
||||
WpDblNodeHeader{WP_DBL_NODE_MAGIC, sizeof(TYPE), nullptr, nullptr}, \
|
||||
ITEM_PTR, \
|
||||
@@ -93,18 +93,18 @@ typedef WpDblNode WpStr8Node;
|
||||
#define wpDblList(TYPE) ( \
|
||||
(WpDblList){.magic = WP_DBL_LIST_MAGIC, .item_size = sizeof(TYPE)} \
|
||||
)
|
||||
#define _dblListNode(TYPE, ITEM_PTR) ( \
|
||||
#define dblListNode(TYPE, ITEM_PTR) ( \
|
||||
&((WpDblNode){.header = {.magic = WP_DBL_NODE_MAGIC, .item_size = sizeof(TYPE)}, \
|
||||
.item = ITEM_PTR}) \
|
||||
)
|
||||
#endif // !WP_PLATFORM_CPP
|
||||
|
||||
#define wpDblListAlloc(TYPE, ALLOCATOR) \
|
||||
(_dblListAlloc(ALLOCATOR, sizeof(TYPE)))
|
||||
(dblListAlloc(ALLOCATOR, sizeof(TYPE)))
|
||||
#define wpDblListGet(TYPE, LIST_PTR, ITEM_INDEX) \
|
||||
((TYPE *)(_dblListGet(LIST_PTR, ITEM_INDEX, sizeof(TYPE))->item))
|
||||
((TYPE *)(dblListGet(LIST_PTR, ITEM_INDEX, sizeof(TYPE))->item))
|
||||
#define wpDblListGetNode(TYPE, LIST_PTR, ITEM_INDEX) \
|
||||
(_dblListGet(LIST_PTR, ITEM_INDEX, sizeof(TYPE)))
|
||||
(dblListGet(LIST_PTR, ITEM_INDEX, sizeof(TYPE)))
|
||||
#define wpDblListGetNodeItem(TYPE, NODE_PTR) \
|
||||
((TYPE *)( \
|
||||
(NODE_PTR == NULL) ? \
|
||||
@@ -112,70 +112,70 @@ typedef WpDblNode WpStr8Node;
|
||||
(NODE_PTR)->item \
|
||||
))
|
||||
#define wpDblListPushFront(TYPE, LIST_PTR, ITEM_PTR) \
|
||||
(_dblListPushFront(LIST_PTR, _dblListNode(TYPE, ITEM_PTR), sizeof(TYPE)))
|
||||
(dblListPushFront(LIST_PTR, dblListNode(TYPE, ITEM_PTR), sizeof(TYPE)))
|
||||
#define wpDblListPushBack(TYPE, LIST_PTR, ITEM_PTR) \
|
||||
(_dblListPushBack(LIST_PTR, _dblListNode(TYPE, ITEM_PTR), sizeof(TYPE)))
|
||||
(dblListPushBack(LIST_PTR, dblListNode(TYPE, ITEM_PTR), sizeof(TYPE)))
|
||||
#define wpDblListInsert(TYPE, LIST_PTR, ITEM_PTR, ITEM_INDEX) \
|
||||
(_dblListInsert(LIST_PTR, _dblListNode(TYPE, ITEM_PTR), \
|
||||
(dblListInsert(LIST_PTR, dblListNode(TYPE, ITEM_PTR), \
|
||||
ITEM_INDEX, sizeof(TYPE)))
|
||||
#define wpDblListPushFrontAlloc(TYPE, ALLOCATOR, LIST_PTR, ITEM_PTR) \
|
||||
(_dblListPushFront(LIST_PTR, _dblListNodeAlloc(ALLOCATOR, ITEM_PTR, sizeof(TYPE)), \
|
||||
(dblListPushFront(LIST_PTR, dblListNodeAlloc(ALLOCATOR, ITEM_PTR, sizeof(TYPE)), \
|
||||
sizeof(TYPE)))
|
||||
#define wpDblListPushBackAlloc(TYPE, ALLOCATOR, LIST_PTR, ITEM_PTR) \
|
||||
(_dblListPushBack(LIST_PTR, _dblListNodeAlloc(ALLOCATOR, ITEM_PTR, sizeof(TYPE)), \
|
||||
(dblListPushBack(LIST_PTR, dblListNodeAlloc(ALLOCATOR, ITEM_PTR, sizeof(TYPE)), \
|
||||
sizeof(TYPE)))
|
||||
#define wpDblListInsertAlloc(TYPE, ALLOCATOR, LIST_PTR, ITEM_PTR, ITEM_INDEX) \
|
||||
(_dblListInsert(LIST_PTR, _dblListNodeAlloc(ALLOCATOR, ITEM_PTR, sizeof(TYPE)), \
|
||||
(dblListInsert(LIST_PTR, dblListNodeAlloc(ALLOCATOR, ITEM_PTR, sizeof(TYPE)), \
|
||||
ITEM_INDEX, sizeof(TYPE)))
|
||||
#define wpDblListPopFront(TYPE, LIST_PTR) \
|
||||
((TYPE *)( \
|
||||
(LIST_PTR == NULL || (LIST_PTR)->node_count == 0) ? \
|
||||
NULL : \
|
||||
_dblListPopFront(LIST_PTR, sizeof(TYPE))->item \
|
||||
dblListPopFront(LIST_PTR, sizeof(TYPE))->item \
|
||||
))
|
||||
#define wpDblListPopBack(TYPE, LIST_PTR) \
|
||||
((TYPE *)( \
|
||||
(LIST_PTR == NULL || (LIST_PTR)->node_count == 0) ? \
|
||||
NULL : \
|
||||
_dblListPopBack(LIST_PTR, sizeof(TYPE))->item \
|
||||
dblListPopBack(LIST_PTR, sizeof(TYPE))->item \
|
||||
))
|
||||
#define wpDblListRemove(TYPE, LIST_PTR, ITEM_INDEX) \
|
||||
((TYPE *)( \
|
||||
(LIST_PTR == NULL || (LIST_PTR)->node_count == 0 || ITEM_INDEX >= (LIST_PTR)->node_count) ? \
|
||||
NULL : \
|
||||
_dblListRemove(LIST_PTR, ITEM_INDEX, sizeof(TYPE))->item \
|
||||
dblListRemove(LIST_PTR, ITEM_INDEX, sizeof(TYPE))->item \
|
||||
))
|
||||
#define wpDblListPopFrontNode(TYPE, LIST_PTR) \
|
||||
( \
|
||||
(LIST_PTR == NULL || (LIST_PTR)->node_count == 0) ? \
|
||||
NULL : \
|
||||
_dblListPopFront(LIST_PTR, sizeof(TYPE)) \
|
||||
dblListPopFront(LIST_PTR, sizeof(TYPE)) \
|
||||
)
|
||||
#define wpDblListPopBackNode(TYPE, LIST_PTR) \
|
||||
( \
|
||||
(LIST_PTR == NULL || (LIST_PTR)->node_count == 0) ? \
|
||||
NULL : \
|
||||
_dblListPopBack(LIST_PTR, sizeof(TYPE)) \
|
||||
dblListPopBack(LIST_PTR, sizeof(TYPE)) \
|
||||
)
|
||||
#define wpDblListRemoveNode(TYPE, LIST_PTR, ITEM_INDEX) \
|
||||
( \
|
||||
(LIST_PTR == NULL || (LIST_PTR)->node_count == 0 || ITEM_INDEX >= (LIST_PTR)->node_count) ? \
|
||||
NULL : \
|
||||
_dblListRemove(LIST_PTR, ITEM_INDEX, sizeof(TYPE)) \
|
||||
dblListRemove(LIST_PTR, ITEM_INDEX, sizeof(TYPE)) \
|
||||
)
|
||||
#define wpDblListEmpty(TYPE, LIST_PTR) \
|
||||
(_dblListEmpty(LIST_PTR, sizeof(TYPE)))
|
||||
(dblListEmpty(LIST_PTR, sizeof(TYPE)))
|
||||
|
||||
WpDblList *_dblListAlloc(const WpAllocator *allocator, u64 item_size);
|
||||
WpDblNode *_dblListNodeAlloc(const WpAllocator *allocator, void *item, u64 item_size);
|
||||
WpDblNode *_dblListGet(const WpDblList *list, u64 index, u64 item_size);
|
||||
void _dblListPushFront(WpDblList *list, WpDblNode *node, u64 item_size);
|
||||
void _dblListPushBack(WpDblList *list, WpDblNode *node, u64 item_size);
|
||||
void _dblListInsert(WpDblList *list, WpDblNode *node, u64 index, u64 item_size);
|
||||
WpDblNode *_dblListPopFront(WpDblList *list, u64 item_size);
|
||||
WpDblNode *_dblListPopBack(WpDblList *list, u64 item_size);
|
||||
WpDblNode *_dblListRemove(WpDblList *list, u64 index, u64 item_size);
|
||||
void _dblListEmpty(WpDblList *list, u64 item_size);
|
||||
WpDblList *dblListAlloc(const WpAllocator *allocator, u64 item_size);
|
||||
WpDblNode *dblListNodeAlloc(const WpAllocator *allocator, void *item, u64 item_size);
|
||||
WpDblNode *dblListGet(const WpDblList *list, u64 index, u64 item_size);
|
||||
void dblListPushFront(WpDblList *list, WpDblNode *node, u64 item_size);
|
||||
void dblListPushBack(WpDblList *list, WpDblNode *node, u64 item_size);
|
||||
void dblListInsert(WpDblList *list, WpDblNode *node, u64 index, u64 item_size);
|
||||
WpDblNode *dblListPopFront(WpDblList *list, u64 item_size);
|
||||
WpDblNode *dblListPopBack(WpDblList *list, u64 item_size);
|
||||
WpDblNode *dblListRemove(WpDblList *list, u64 index, u64 item_size);
|
||||
void dblListEmpty(WpDblList *list, u64 item_size);
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
#include "../../../common/assert/assert.h"
|
||||
#include "../../../common/misc/misc_utils.h"
|
||||
|
||||
wp_intern inline void _validateIO(const WpMur3HasherIO *io);
|
||||
wp_intern inline u64 _fmix64(u64 k);
|
||||
wp_intern inline void validateIO(const WpMur3HasherIO *io);
|
||||
wp_intern inline u64 fmix64(u64 k);
|
||||
|
||||
void wpX64Mur3Hasher128(WpU8Stream *bytes, void *hasher_io) {
|
||||
WpMur3HasherIO *io = (WpMur3HasherIO *)hasher_io;
|
||||
_validateIO(io);
|
||||
validateIO(io);
|
||||
|
||||
const i32 nblocks = (bytes->count * bytes->item_size) / 16;
|
||||
|
||||
@@ -85,8 +85,8 @@ void wpX64Mur3Hasher128(WpU8Stream *bytes, void *hasher_io) {
|
||||
h1 += h2;
|
||||
h2 += h1;
|
||||
|
||||
h1 = _fmix64(h1);
|
||||
h2 = _fmix64(h2);
|
||||
h1 = fmix64(h1);
|
||||
h2 = fmix64(h2);
|
||||
|
||||
h1 += h2;
|
||||
h2 += h1;
|
||||
@@ -95,11 +95,11 @@ void wpX64Mur3Hasher128(WpU8Stream *bytes, void *hasher_io) {
|
||||
io->hash[1] = h2;
|
||||
}
|
||||
|
||||
wp_intern inline void _validateIO(const WpMur3HasherIO *io) {
|
||||
wp_intern inline void validateIO(const WpMur3HasherIO *io) {
|
||||
wpRuntimeAssert(io->magic == WP_MUR3_HASHER_MAGIC, "Invalid Murmur3 hash IO");
|
||||
}
|
||||
|
||||
wp_intern inline u64 _fmix64(u64 k) {
|
||||
wp_intern inline u64 fmix64(u64 k) {
|
||||
k ^= k >> 33;
|
||||
k *= wpU64Const(0xff51afd7ed558ccd);
|
||||
k ^= k >> 33;
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
#include "../../../common/assert/assert.h"
|
||||
#include "../../../common/misc/misc_utils.h"
|
||||
|
||||
wp_intern inline void _siphash(WpStream *bytes, const WpSipHasherParams *params, u8 *out, u64 outlen);
|
||||
wp_intern inline void _validate128IO(const WpSipHasher128IO *io);
|
||||
wp_intern inline void _validate64IO(const WpSipHasher64IO *io);
|
||||
wp_intern inline b8 _checkRounds(const WpSipHasherParams *params);
|
||||
wp_intern inline void siphash(WpStream *bytes, const WpSipHasherParams *params, u8 *out, u64 outlen);
|
||||
wp_intern inline void validate128IO(const WpSipHasher128IO *io);
|
||||
wp_intern inline void validate64IO(const WpSipHasher64IO *io);
|
||||
wp_intern inline b8 checkRounds(const WpSipHasherParams *params);
|
||||
|
||||
#define _u32To8LE(p, v) \
|
||||
(p)[0] = (u8)((v)); \
|
||||
@@ -46,17 +46,17 @@ wp_intern inline b8 _checkRounds(const WpSipHasherParams *params);
|
||||
|
||||
void wpSipHasher128(WpStream *bytes, void *hasher_io) {
|
||||
WpSipHasher128IO *io = (WpSipHasher128IO *)hasher_io;
|
||||
_validate128IO(io);
|
||||
_siphash(bytes, &io->params, (u8 *)&io->hash, sizeof(u64) * 2);
|
||||
validate128IO(io);
|
||||
siphash(bytes, &io->params, (u8 *)&io->hash, sizeof(u64) * 2);
|
||||
}
|
||||
|
||||
void wpSipHasher64(WpStream *bytes, void *hasher_io) {
|
||||
WpSipHasher64IO *io = (WpSipHasher64IO *)hasher_io;
|
||||
_validate64IO(io);
|
||||
_siphash(bytes, &io->params, (u8 *)&io->hash, sizeof(u64));
|
||||
validate64IO(io);
|
||||
siphash(bytes, &io->params, (u8 *)&io->hash, sizeof(u64));
|
||||
}
|
||||
|
||||
wp_intern inline void _siphash(WpStream *bytes, const WpSipHasherParams *params, u8 *out,
|
||||
wp_intern inline void siphash(WpStream *bytes, const WpSipHasherParams *params, u8 *out,
|
||||
u64 outlen) {
|
||||
const u8 *kk = (const u8 *)¶ms->key;
|
||||
u64 inlen = bytes->count * bytes->item_size;
|
||||
@@ -157,19 +157,19 @@ wp_intern inline void _siphash(WpStream *bytes, const WpSipHasherParams *params,
|
||||
_u64To8LE(out + 8, b);
|
||||
}
|
||||
|
||||
wp_intern inline void _validate128IO(const WpSipHasher128IO *io) {
|
||||
wp_intern inline void validate128IO(const WpSipHasher128IO *io) {
|
||||
b8 magic_match = io->params.magic == WP_SIP_HASHER_128_MAGIC;
|
||||
b8 rounds = _checkRounds(&io->params);
|
||||
b8 rounds = checkRounds(&io->params);
|
||||
wpRuntimeAssert(magic_match && rounds, "Invalid Siphash 128 IO");
|
||||
}
|
||||
|
||||
wp_intern inline void _validate64IO(const WpSipHasher64IO *io) {
|
||||
wp_intern inline void validate64IO(const WpSipHasher64IO *io) {
|
||||
b8 magic_match = io->params.magic == WP_SIP_HASHER_64_MAGIC;
|
||||
b8 rounds = _checkRounds(&io->params);
|
||||
b8 rounds = checkRounds(&io->params);
|
||||
wpRuntimeAssert(magic_match && rounds, "Invalid Siphash 64 IO");
|
||||
}
|
||||
|
||||
wp_intern inline b8 _checkRounds(const WpSipHasherParams *params) {
|
||||
wp_intern inline b8 checkRounds(const WpSipHasherParams *params) {
|
||||
b8 rounds24 = params->compression == 2 && params->finalisation == 4;
|
||||
b8 rounds48 = params->compression == 4 && params->finalisation == 8;
|
||||
return rounds24 || rounds48;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "../../common/misc/misc_utils.h"
|
||||
#include <string.h>
|
||||
|
||||
void _queuePush(WpQueue *queue, void *item, u64 item_size) {
|
||||
void queuePush(WpQueue *queue, void *item, u64 item_size) {
|
||||
wpDebugAssert(queue != NULL, "`queue` should not be NULL");
|
||||
wpRuntimeAssert(item_size == wpArrayItemSize(queue->items), "Invalid type");
|
||||
|
||||
@@ -14,7 +14,7 @@ void _queuePush(WpQueue *queue, void *item, u64 item_size) {
|
||||
if (queue->count >= capacity) { return; }
|
||||
|
||||
u64 index = (queue->back)++;
|
||||
_arraySet(queue->items, index, item, item_size);
|
||||
arraySet(queue->items, index, item, item_size);
|
||||
++(queue->count);
|
||||
|
||||
if (queue->back >= capacity) {
|
||||
@@ -22,7 +22,7 @@ void _queuePush(WpQueue *queue, void *item, u64 item_size) {
|
||||
}
|
||||
}
|
||||
|
||||
WpQueue *_queuePushAlloc(const WpAllocator *allocator, WpQueue *queue, void *item, u64 item_size) {
|
||||
WpQueue *queuePushAlloc(const WpAllocator *allocator, WpQueue *queue, void *item, u64 item_size) {
|
||||
wpDebugAssert(allocator != NULL && queue != NULL && item != NULL,
|
||||
"`allocator`, `queue` and `item` should not be NULL");
|
||||
wpRuntimeAssert(item_size == wpArrayItemSize(queue->items), "Invalid type");
|
||||
@@ -35,7 +35,7 @@ WpQueue *_queuePushAlloc(const WpAllocator *allocator, WpQueue *queue, void *ite
|
||||
b8 queue_full = queue->count >= capacity;
|
||||
if (queue_full) {
|
||||
u64 new_capacity = wpMiscUtilsU64RoundUpPow2(capacity * 2);
|
||||
u64 array_size = _arrayCalcAllocSize(new_capacity, item_size);
|
||||
u64 array_size = arrayCalcAllocSize(new_capacity, item_size);
|
||||
u64 alloc_size = sizeof(WpQueue) + array_size;
|
||||
void *buffer = wpMemAllocatorAlloc(allocator, alloc_size);
|
||||
if (!buffer) {
|
||||
@@ -45,7 +45,7 @@ WpQueue *_queuePushAlloc(const WpAllocator *allocator, WpQueue *queue, void *ite
|
||||
memset((void *)buffer, 0, alloc_size);
|
||||
|
||||
output = (WpQueue *)buffer;
|
||||
output->items = _arrayFromPreallocatedBuffer((void *)(output + 1), array_size, WP_ARRAY_INIT_FILLED, item_size);
|
||||
output->items = arrayFromPreallocatedBuffer((void *)(output + 1), array_size, WP_ARRAY_INIT_FILLED, item_size);
|
||||
|
||||
// NOTE (Abdelrahman): When the queue is full, the front and back indices should
|
||||
// always be the same
|
||||
@@ -84,13 +84,13 @@ WpQueue *_queuePushAlloc(const WpAllocator *allocator, WpQueue *queue, void *ite
|
||||
output->count = queue->count;
|
||||
}
|
||||
|
||||
_queuePush(output, item, item_size);
|
||||
queuePush(output, item, item_size);
|
||||
|
||||
RETURN_QUEUE_PUSH_ALLOC:
|
||||
return output;
|
||||
}
|
||||
|
||||
void *_queuePop(WpQueue *queue, u64 item_size) {
|
||||
void *queuePop(WpQueue *queue, u64 item_size) {
|
||||
wpDebugAssert(queue != NULL, "`queue` should not be NULL");
|
||||
wpRuntimeAssert(item_size == wpArrayItemSize(queue->items), "Invalid type");
|
||||
|
||||
@@ -104,5 +104,5 @@ void *_queuePop(WpQueue *queue, u64 item_size) {
|
||||
queue->front = 0;
|
||||
}
|
||||
|
||||
return _arrayGet(queue->items, index, item_size);
|
||||
return arrayGet(queue->items, index, item_size);
|
||||
}
|
||||
|
||||
@@ -80,13 +80,13 @@ typedef WpQueue WpStr8Queue;
|
||||
#define wpQueueCapacity(QUEUE_PTR) (wpArrayCapacity((QUEUE_PTR)->items))
|
||||
#define wpQueueItemSize(QUEUE_PTR) (wpArrayItemSize((QUEUE_PTR)->items))
|
||||
#define wpQueuePush(TYPE, QUEUE_PTR, VALUE_PTR) ( \
|
||||
_queuePush(QUEUE_PTR, VALUE_PTR, sizeof(TYPE)) \
|
||||
queuePush(QUEUE_PTR, VALUE_PTR, sizeof(TYPE)) \
|
||||
)
|
||||
#define wpQueuePushAlloc(TYPE, ALLOCATOR_PTR, QUEUE_PTR, VALUE_PTR) ( \
|
||||
_queuePushAlloc(ALLOCATOR_PTR, QUEUE_PTR, VALUE_PTR, sizeof(TYPE)) \
|
||||
queuePushAlloc(ALLOCATOR_PTR, QUEUE_PTR, VALUE_PTR, sizeof(TYPE)) \
|
||||
)
|
||||
#define wpQueuePop(TYPE, QUEUE_PTR) ( \
|
||||
(TYPE *)_queuePop(QUEUE_PTR, sizeof(TYPE)) \
|
||||
(TYPE *)queuePop(QUEUE_PTR, sizeof(TYPE)) \
|
||||
)
|
||||
#define wpQueueDealloc(TYPE, ALLOCATOR_PTR, QUEUE_PTR) \
|
||||
(wpArrayDealloc(TYPE, ALLOCATOR_PTR, &((QUEUE_PTR)->items)), \
|
||||
@@ -94,9 +94,9 @@ typedef WpQueue WpStr8Queue;
|
||||
(QUEUE_PTR)->back = 0, \
|
||||
(QUEUE_PTR)->count = 0)
|
||||
|
||||
void _queuePush(WpQueue *queue, void *item, u64 item_size);
|
||||
WpQueue *_queuePushAlloc(const WpAllocator *allocator, WpQueue *queue, void *item, u64 item_size);
|
||||
void *_queuePop(WpQueue *queue, u64 item_size);
|
||||
void queuePush(WpQueue *queue, void *item, u64 item_size);
|
||||
WpQueue *queuePushAlloc(const WpAllocator *allocator, WpQueue *queue, void *item, u64 item_size);
|
||||
void *queuePop(WpQueue *queue, u64 item_size);
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
|
||||
@@ -4,20 +4,20 @@
|
||||
#include "../../common/aliases/aliases.h"
|
||||
#include "../../common/assert/assert.h"
|
||||
|
||||
void _streamValidate(const WpStream *stream, u64 item_size);
|
||||
void streamValidate(const WpStream *stream, u64 item_size);
|
||||
|
||||
b8 wpStreamAtEnd(const WpStream *stream) {
|
||||
return stream->position >= stream->count;
|
||||
}
|
||||
|
||||
b8 _streamHasCount(const WpStream *stream, u64 count) {
|
||||
b8 streamHasCount(const WpStream *stream, u64 count) {
|
||||
return stream->position + count <= stream->count;
|
||||
}
|
||||
|
||||
void *_streamPeekWithOffset(const WpStream *stream, u64 offset, u64 item_size) {
|
||||
_streamValidate(stream, item_size);
|
||||
void *streamPeekWithOffset(const WpStream *stream, u64 offset, u64 item_size) {
|
||||
streamValidate(stream, item_size);
|
||||
|
||||
if (_streamHasCount(stream, offset + 1)) {
|
||||
if (streamHasCount(stream, offset + 1)) {
|
||||
u64 index = (stream->position + offset) * stream->item_size;
|
||||
return (void *)(&((u8 *)(stream->data))[index]);
|
||||
}
|
||||
@@ -25,10 +25,10 @@ void *_streamPeekWithOffset(const WpStream *stream, u64 offset, u64 item_size) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *_streamConsumeCount(WpStream *stream, u64 count, u64 item_size) {
|
||||
_streamValidate(stream, item_size);
|
||||
void *streamConsumeCount(WpStream *stream, u64 count, u64 item_size) {
|
||||
streamValidate(stream, item_size);
|
||||
|
||||
if (_streamHasCount(stream, count)) {
|
||||
if (streamHasCount(stream, count)) {
|
||||
u64 index = stream->position * stream->item_size;
|
||||
stream->position += count;
|
||||
return (void *)(&((u8 *)(stream->data))[index]);
|
||||
@@ -37,7 +37,7 @@ void *_streamConsumeCount(WpStream *stream, u64 count, u64 item_size) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void _streamValidate(const WpStream *stream, u64 item_size) {
|
||||
void streamValidate(const WpStream *stream, u64 item_size) {
|
||||
wpDebugAssert(stream != NULL, "`stream` should not be NULL");
|
||||
wpRuntimeAssert(stream->item_size == item_size, "Invalid item type provided");
|
||||
}
|
||||
|
||||
@@ -58,20 +58,20 @@ typedef WpStream WpStr8Stream;
|
||||
)
|
||||
#endif
|
||||
|
||||
#define wpStreamHasNext(STREAM) _streamHasCount(STREAM, 1)
|
||||
#define wpStreamHasCount(STREAM, COUNT) _streamHasCount(STREAM, COUNT)
|
||||
#define wpStreamPeek(TYPE, STREAM) ((TYPE *)_streamPeekWithOffset(STREAM, 0, sizeof(TYPE)))
|
||||
#define wpStreamHasNext(STREAM) streamHasCount(STREAM, 1)
|
||||
#define wpStreamHasCount(STREAM, COUNT) streamHasCount(STREAM, COUNT)
|
||||
#define wpStreamPeek(TYPE, STREAM) ((TYPE *)streamPeekWithOffset(STREAM, 0, sizeof(TYPE)))
|
||||
#define wpStreamPeekWithOffset(TYPE, STREAM, OFFSET) \
|
||||
((TYPE *)_streamPeekWithOffset(STREAM, OFFSET, sizeof(TYPE)))
|
||||
#define wpStreamConsume(TYPE, STREAM) ((TYPE *)_streamConsumeCount(STREAM, 1, sizeof(TYPE)))
|
||||
((TYPE *)streamPeekWithOffset(STREAM, OFFSET, sizeof(TYPE)))
|
||||
#define wpStreamConsume(TYPE, STREAM) ((TYPE *)streamConsumeCount(STREAM, 1, sizeof(TYPE)))
|
||||
#define wpStreamConsumeCount(TYPE, STREAM, COUNT) \
|
||||
((TYPE *)_streamConsumeCount(STREAM, COUNT, sizeof(TYPE)))
|
||||
((TYPE *)streamConsumeCount(STREAM, COUNT, sizeof(TYPE)))
|
||||
|
||||
b8 wpStreamAtEnd(const WpStream *stream);
|
||||
|
||||
b8 _streamHasCount(const WpStream *stream, u64 count);
|
||||
void *_streamPeekWithOffset(const WpStream *stream, u64 offset, u64 item_size);
|
||||
void *_streamConsumeCount(WpStream *stream, u64 count, u64 item_size);
|
||||
b8 streamHasCount(const WpStream *stream, u64 count);
|
||||
void *streamPeekWithOffset(const WpStream *stream, u64 offset, u64 item_size);
|
||||
void *streamConsumeCount(WpStream *stream, u64 count, u64 item_size);
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
|
||||
@@ -115,6 +115,11 @@ void wpStr8Set(WpStr8 *str, u64 index, c8 c) {
|
||||
str->buf[index] = c;
|
||||
}
|
||||
|
||||
void wpStr8Clear(WpStr8 *str) {
|
||||
memset(str->buf, 0, str->capacity);
|
||||
str->size = 0;
|
||||
}
|
||||
|
||||
void wpStr8PushBack(WpStr8 *str, c8 c) {
|
||||
if (!(str->size < str->capacity)) {
|
||||
return;
|
||||
|
||||
@@ -88,20 +88,21 @@ void wpStr8DeallocBuf(const WpAllocator *allocator, WpStr8 **str);
|
||||
/**
|
||||
* WpStr8 utilities
|
||||
*/
|
||||
c8 wpStr8Get(WpStr8RO *str, u64 index);
|
||||
void wpStr8Set(WpStr8 *str, u64 index, c8 c);
|
||||
void wpStr8PushBack(WpStr8 *str, c8 c);
|
||||
b8 wpStr8Equal(WpStr8RO *s1, WpStr8RO *s2);
|
||||
b8 wpStr8EqualToCount(WpStr8RO* s1, WpStr8RO* s2, u64 count);
|
||||
c8 wpStr8Get(WpStr8RO *str, u64 index);
|
||||
void wpStr8Set(WpStr8 *str, u64 index, c8 c);
|
||||
void wpStr8Clear(WpStr8 *str);
|
||||
void wpStr8PushBack(WpStr8 *str, c8 c);
|
||||
b8 wpStr8Equal(WpStr8RO *s1, WpStr8RO *s2);
|
||||
b8 wpStr8EqualToCount(WpStr8RO* s1, WpStr8RO* s2, u64 count);
|
||||
WpStr8 wpStr8Slice(WpStr8RO *str, u64 start, u64 end);
|
||||
void wpStr8ConcatCapped(WpStr8 *dst, WpStr8RO *src);
|
||||
void wpStr8CopyCstrCapped(WpStr8 *dst, const char *src);
|
||||
void wpStr8CopyStr8Capped(WpStr8 *dst, WpStr8RO *src);
|
||||
void wpStr8CopyToCstr(char *dst, WpStr8RO *src, u64 dst_capacity);
|
||||
void wpStr8Format(WpStr8 *dst, const char *format, ...);
|
||||
void wpStr8ToLower(WpStr8 *dst, WpStr8RO *src);
|
||||
void wpStr8ToUpper(WpStr8 *dst, WpStr8RO *src);
|
||||
void wpStr8FromBytes(WpStr8 *dst, const WpU8Array src);
|
||||
void wpStr8ConcatCapped(WpStr8 *dst, WpStr8RO *src);
|
||||
void wpStr8CopyCstrCapped(WpStr8 *dst, const char *src);
|
||||
void wpStr8CopyStr8Capped(WpStr8 *dst, WpStr8RO *src);
|
||||
void wpStr8CopyToCstr(char *dst, WpStr8RO *src, u64 dst_capacity);
|
||||
void wpStr8Format(WpStr8 *dst, const char *format, ...);
|
||||
void wpStr8ToLower(WpStr8 *dst, WpStr8RO *src);
|
||||
void wpStr8ToUpper(WpStr8 *dst, WpStr8RO *src);
|
||||
void wpStr8FromBytes(WpStr8 *dst, const WpU8Array src);
|
||||
|
||||
/**
|
||||
* WpStr8 find functions
|
||||
|
||||
@@ -16,7 +16,7 @@ BEGIN_C_LINKAGE
|
||||
#define wpStaticAssert(EXPR, MSG) wp_extern char ASSERTION_FAILED[EXPR ? 1 : -1]
|
||||
|
||||
#ifndef WP_NO_RUNTIME_ASSERT
|
||||
#define wpRuntimeAssert(EXPR, MSG) _runtimeAssert(EXPR, MSG)
|
||||
#define wpRuntimeAssert(EXPR, MSG) runtimeAssert(EXPR, MSG)
|
||||
#else
|
||||
#define wpRuntimeAssert(EXPR, MSG)
|
||||
#endif
|
||||
@@ -28,23 +28,23 @@ BEGIN_C_LINKAGE
|
||||
#endif
|
||||
|
||||
#ifdef WP_PLATFORM_WINDOWS
|
||||
#define _runtimeAssert(EXPR, MSG) do { \
|
||||
#define runtimeAssert(EXPR, MSG) do { \
|
||||
__pragma(warning(push)) \
|
||||
__pragma(warning(disable:4127)) \
|
||||
if (!(EXPR)) { \
|
||||
__pragma(warning(pop)) \
|
||||
_runtimeAssertFailed(EXPR, MSG); \
|
||||
runtimeAssertFailed(EXPR, MSG); \
|
||||
} \
|
||||
} while(false)
|
||||
#else
|
||||
#define _runtimeAssert(EXPR, MSG) do { \
|
||||
#define runtimeAssert(EXPR, MSG) do { \
|
||||
if (!(EXPR)) { \
|
||||
_runtimeAssertFailed(EXPR, MSG); \
|
||||
runtimeAssertFailed(EXPR, MSG); \
|
||||
} \
|
||||
} while(false)
|
||||
#endif // !WP_PLATFORM_WINDOWS
|
||||
|
||||
#define _runtimeAssertFailed(EXPR, MSG) do { \
|
||||
#define runtimeAssertFailed(EXPR, MSG) do { \
|
||||
fprintf( \
|
||||
stderr, \
|
||||
"%s:%d (In function `%s`): Assertion failed (%" PRIu32 ")\nDiagnostic: %s\n\n", \
|
||||
|
||||
+11
-11
@@ -35,8 +35,8 @@ wp_intern WpStr8RO LOG_LEVEL_STRINGS[COUNT_LOG_LEVEL] = {
|
||||
[WP_LOG_LEVEL_DEBUG] = wpStr8LitRoInitialiserList("debug "),
|
||||
};
|
||||
|
||||
wp_intern void _get_current_time_string(WpStr8 *dst);
|
||||
wp_intern void _write_log_line(WpFile *fp, const WpLogger *logger, WpStr8 msg, WpLogLevel level);
|
||||
wp_intern void getCurrentTimeString(WpStr8 *dst);
|
||||
wp_intern void writeLogLine(WpFile *fp, const WpLogger *logger, WpStr8 msg, WpLogLevel level);
|
||||
|
||||
void wpLogSetLevel(WpLogLevel level) {
|
||||
LOG_CONFIG.level = level;
|
||||
@@ -57,7 +57,7 @@ void wpLogDebug(const WpLogger *logger, WpStr8 msg) {
|
||||
if (LOG_CONFIG.level < WP_LOG_LEVEL_DEBUG) { return; }
|
||||
|
||||
WpFile *fp = LOG_CONFIG.outlog != NULL ? LOG_CONFIG.outlog : wpFileStdout();
|
||||
_write_log_line(fp, logger, msg, WP_LOG_LEVEL_DEBUG);
|
||||
writeLogLine(fp, logger, msg, WP_LOG_LEVEL_DEBUG);
|
||||
}
|
||||
|
||||
void wpLogInfo(const WpLogger *logger, WpStr8 msg) {
|
||||
@@ -65,7 +65,7 @@ void wpLogInfo(const WpLogger *logger, WpStr8 msg) {
|
||||
if (LOG_CONFIG.level < WP_LOG_LEVEL_INFO) { return; }
|
||||
|
||||
WpFile *fp = LOG_CONFIG.outlog != NULL ? LOG_CONFIG.outlog : wpFileStdout();
|
||||
_write_log_line(fp, logger, msg, WP_LOG_LEVEL_INFO);
|
||||
writeLogLine(fp, logger, msg, WP_LOG_LEVEL_INFO);
|
||||
}
|
||||
|
||||
void wpLogWarning(const WpLogger *logger, WpStr8 msg) {
|
||||
@@ -73,7 +73,7 @@ void wpLogWarning(const WpLogger *logger, WpStr8 msg) {
|
||||
if (LOG_CONFIG.level < WP_LOG_LEVEL_WARNING) { return; }
|
||||
|
||||
WpFile *fp = LOG_CONFIG.outlog != NULL ? LOG_CONFIG.outlog : wpFileStdout();
|
||||
_write_log_line(fp, logger, msg, WP_LOG_LEVEL_WARNING);
|
||||
writeLogLine(fp, logger, msg, WP_LOG_LEVEL_WARNING);
|
||||
}
|
||||
|
||||
void wpLogError(const WpLogger *logger, WpStr8 msg) {
|
||||
@@ -81,7 +81,7 @@ void wpLogError(const WpLogger *logger, WpStr8 msg) {
|
||||
if (LOG_CONFIG.level < WP_LOG_LEVEL_ERROR) { return; }
|
||||
|
||||
WpFile *fp = LOG_CONFIG.errlog != NULL ? LOG_CONFIG.errlog : wpFileStderr();
|
||||
_write_log_line(fp, logger, msg, WP_LOG_LEVEL_ERROR);
|
||||
writeLogLine(fp, logger, msg, WP_LOG_LEVEL_ERROR);
|
||||
}
|
||||
|
||||
void wpLogCritical(const WpLogger *logger, WpStr8 msg) {
|
||||
@@ -89,7 +89,7 @@ void wpLogCritical(const WpLogger *logger, WpStr8 msg) {
|
||||
if (LOG_CONFIG.level < WP_LOG_LEVEL_CRITICAL) { return; }
|
||||
|
||||
WpFile *fp = LOG_CONFIG.errlog != NULL ? LOG_CONFIG.errlog : wpFileStderr();
|
||||
_write_log_line(fp, logger, msg, WP_LOG_LEVEL_CRITICAL);
|
||||
writeLogLine(fp, logger, msg, WP_LOG_LEVEL_CRITICAL);
|
||||
}
|
||||
|
||||
void wpLogFatal(const WpLogger *logger, WpStr8 msg) {
|
||||
@@ -97,10 +97,10 @@ void wpLogFatal(const WpLogger *logger, WpStr8 msg) {
|
||||
if (LOG_CONFIG.level < WP_LOG_LEVEL_FATAL) { return; }
|
||||
|
||||
WpFile *fp = LOG_CONFIG.errlog != NULL ? LOG_CONFIG.errlog : wpFileStderr();
|
||||
_write_log_line(fp, logger, msg, WP_LOG_LEVEL_FATAL);
|
||||
writeLogLine(fp, logger, msg, WP_LOG_LEVEL_FATAL);
|
||||
}
|
||||
|
||||
wp_intern void _get_current_time_string(WpStr8 *dst) {
|
||||
wp_intern void getCurrentTimeString(WpStr8 *dst) {
|
||||
// TODO (Abdelrahman): Replace with proper date/time utilities
|
||||
char buf[TIME_BUF_CAPACITY];
|
||||
time_t now = time(NULL);
|
||||
@@ -110,13 +110,13 @@ wp_intern void _get_current_time_string(WpStr8 *dst) {
|
||||
wpStr8CopyCstrCapped(dst, buf);
|
||||
}
|
||||
|
||||
wp_intern void _write_log_line(WpFile *fp, const WpLogger *logger, WpStr8 msg, WpLogLevel level) {
|
||||
wp_intern void writeLogLine(WpFile *fp, const WpLogger *logger, WpStr8 msg, WpLogLevel level) {
|
||||
WpStr8 padding = wpStr8Buf(MIN_LOG_MSG_LENGTH);
|
||||
u32 padding_size = msg.size < MIN_LOG_MSG_LENGTH ? MIN_LOG_MSG_LENGTH - msg.size + 1 : 0;
|
||||
wpStr8Format(&padding, "%-*s", padding_size, " ");
|
||||
|
||||
WpStr8 time_str = wpStr8Buf(TIME_BUF_CAPACITY);
|
||||
_get_current_time_string(&time_str);
|
||||
getCurrentTimeString(&time_str);
|
||||
|
||||
WpStr8RO **strings = wpArray(
|
||||
WpStr8RO *,
|
||||
|
||||
+8
-8
@@ -25,15 +25,15 @@ typedef struct {
|
||||
WpStr8 name;
|
||||
} WpLogger;
|
||||
|
||||
void wpLogSetLevel(WpLogLevel level);
|
||||
void wpLogConfigure(WpFile *outlog, WpFile *errlog, WpLogLevel level);
|
||||
void wpLogSetLevel(WpLogLevel level);
|
||||
void wpLogConfigure(WpFile *outlog, WpFile *errlog, WpLogLevel level);
|
||||
WpLogger wpLogMakeLogger(WpStr8 name);
|
||||
void wpLogDebug(const WpLogger *logger, WpStr8 msg);
|
||||
void wpLogInfo(const WpLogger *logger, WpStr8 msg);
|
||||
void wpLogWarning(const WpLogger *logger, WpStr8 msg);
|
||||
void wpLogError(const WpLogger *logger, WpStr8 msg);
|
||||
void wpLogCritical(const WpLogger *logger, WpStr8 msg);
|
||||
void wpLogFatal(const WpLogger *logger, WpStr8 msg);
|
||||
void wpLogDebug(const WpLogger *logger, WpStr8 msg);
|
||||
void wpLogInfo(const WpLogger *logger, WpStr8 msg);
|
||||
void wpLogWarning(const WpLogger *logger, WpStr8 msg);
|
||||
void wpLogError(const WpLogger *logger, WpStr8 msg);
|
||||
void wpLogCritical(const WpLogger *logger, WpStr8 msg);
|
||||
void wpLogFatal(const WpLogger *logger, WpStr8 msg);
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
|
||||
+45
-27
@@ -392,6 +392,24 @@
|
||||
#define wapp_array_alloc_capacity wpArrayAllocCapacity
|
||||
#define wapp_array_from_preallcated_buffer wpArrayFromPreallcatedBuffer
|
||||
|
||||
#define _array_count arrayCount
|
||||
#define _array_capacity arrayCapacity
|
||||
#define _array_item_size arrayItemSize
|
||||
#define _array_set_count arraySetCount
|
||||
#define _array_get arrayGet
|
||||
#define _array_set arraySet
|
||||
#define _array_append_capped arrayAppendCapped
|
||||
#define _array_extend_capped arrayExtendCappend
|
||||
#define _array_copy_capped arrayCopyCapped
|
||||
#define _array_append_alloc arrayAppendAlloc
|
||||
#define _array_extend_alloc arrayExtendAlloc
|
||||
#define _array_copy_alloc arrayCopyAlloc
|
||||
#define _array_pop arrayPop
|
||||
#define _array_clear arrayClear
|
||||
#define _array_calc_alloc_size arrayCalcAllocSize
|
||||
#define _array_alloc_capacity arrayAllocCapacity
|
||||
#define _array_from_preallocated_buffer arrayFromPreallocatedBuffer
|
||||
|
||||
// --- Assert ---
|
||||
|
||||
#define wapp_static_assert wpStaticAssert
|
||||
@@ -403,7 +421,7 @@
|
||||
#define wapp_cpath_dirname wpCpathDirname
|
||||
#define wapp_cpath_dirup wpCpathDirup
|
||||
#define wapp_cpath_join_path wpCpathJoinPath
|
||||
#define dirup _dirup
|
||||
#define dirup dirUp
|
||||
|
||||
// --- DblList ---
|
||||
|
||||
@@ -426,16 +444,16 @@
|
||||
#define wapp_dbl_list_remove_node wpDblListRemoveNode
|
||||
#define wapp_dbl_list_empty wpDblListEmpty
|
||||
|
||||
#define _dbl_list_alloc _dblListAlloc
|
||||
#define _dbl_list_node_alloc _dblListNodeAlloc
|
||||
#define _dbl_list_get _dblListGet
|
||||
#define _dbl_list_push_front _dblListPushFront
|
||||
#define _dbl_list_push_back _dblListPushBack
|
||||
#define _dbl_list_insert _dblListInsert
|
||||
#define _dbl_list_pop_front _dblListPopFront
|
||||
#define _dbl_list_pop_back _dblListPopBack
|
||||
#define _dbl_list_remove _dblListRemove
|
||||
#define _dbl_list_empty _dblListEmpty
|
||||
#define _dbl_list_alloc dblListAlloc
|
||||
#define _dbl_list_node_alloc dblListNodeAlloc
|
||||
#define _dbl_list_get dblListGet
|
||||
#define _dbl_list_push_front dblListPushFront
|
||||
#define _dbl_list_push_back dblListPushBack
|
||||
#define _dbl_list_insert dblListInsert
|
||||
#define _dbl_list_pop_front dblListPopFront
|
||||
#define _dbl_list_pop_back dblListPopBack
|
||||
#define _dbl_list_remove dblListRemove
|
||||
#define _dbl_list_empty dblListEmpty
|
||||
|
||||
// --- File ---
|
||||
|
||||
@@ -457,14 +475,14 @@
|
||||
#define wapp_file_rename wpFileRename
|
||||
#define wapp_file_remove wpFileRemove
|
||||
|
||||
#define _file_open _fileOpen
|
||||
#define _file_seek _fileSeek
|
||||
#define _file_read _fileRead
|
||||
#define _file_write _fileWrite
|
||||
#define _file_flush _fileFlush
|
||||
#define _file_close _fileClose
|
||||
#define _file_rename _fileRename
|
||||
#define _file_remove _fileRemove
|
||||
#define _file_open fileOpen
|
||||
#define _file_seek fileSeek
|
||||
#define _file_read fileRead
|
||||
#define _file_write fileWrite
|
||||
#define _file_flush fileFlush
|
||||
#define _file_close fileClose
|
||||
#define _file_rename fileRename
|
||||
#define _file_remove fileRemove
|
||||
|
||||
// --- Log ---
|
||||
|
||||
@@ -491,8 +509,8 @@
|
||||
|
||||
#define wapp_os_mem_alloc wpOsMemAlloc
|
||||
#define wapp_os_mem_free wpOsMemFree
|
||||
#define os_mem_allocate _osMemAllocate
|
||||
#define os_mem_free _osMemFree
|
||||
#define os_mem_allocate osMemAllocate
|
||||
#define os_mem_free osMemFree
|
||||
|
||||
// --- Mem Utils ---
|
||||
|
||||
@@ -523,21 +541,21 @@
|
||||
#define wapp_queue_push_alloc wpQueuePushAlloc
|
||||
#define wapp_queue_pop wpQueuePop
|
||||
|
||||
#define _queue_push _queuePush
|
||||
#define _queue_push_alloc _queuePushAlloc
|
||||
#define _queue_pop _queuePop
|
||||
#define _queue_push queuePush
|
||||
#define _queue_push_alloc queuePushAlloc
|
||||
#define _queue_pop queuePop
|
||||
|
||||
// --- Shell Commander ---
|
||||
|
||||
#define CMD_NO_EXIT wpCmdNoExit
|
||||
#define wapp_shell_commander_execute wpShellCommanderExecute
|
||||
#define get_output_status _getOutputStatus
|
||||
#define get_output_status getOutputStatus
|
||||
|
||||
// --- Shell Termcolour ---
|
||||
|
||||
#define wapp_shell_termcolour_print_text wpShellTermcolourPrintText
|
||||
#define wapp_shell_termcolour_clear_colour wpShellTermcolourClearColour
|
||||
#define print_coloured_text _printColouredText
|
||||
#define print_coloured_text printColouredText
|
||||
|
||||
// --- Shell Utils ---
|
||||
|
||||
@@ -585,7 +603,7 @@
|
||||
|
||||
#define wapp_tester_result wpTesterResult
|
||||
#define wapp_tester_run wpTesterRun
|
||||
#define run_tests _runTests
|
||||
#define run_tests runTests
|
||||
|
||||
// --- UUID ---
|
||||
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
#include "../../../common/aliases/aliases.h"
|
||||
#include "../../../common/assert/assert.h"
|
||||
|
||||
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,
|
||||
wp_intern void initialiseArenaAllocator(WpAllocator *allocator);
|
||||
wp_intern void *memArenaAlloc(u64 size, void *alloc_obj);
|
||||
wp_intern void *memArenaAllocAligned(u64 size, u64 alignment, void *alloc_obj);
|
||||
wp_intern void *memArenaRealloc(void *ptr, u64 old_size, u64 new_size, void *alloc_obj);
|
||||
wp_intern void *memArenaReallocAligned(void *ptr, u64 old_size, u64 new_size, u64 alignment,
|
||||
void *alloc_obj);
|
||||
|
||||
WpAllocator wpMemArenaAllocatorInitWithBuffer(u8 *buffer, u64 buffer_size) {
|
||||
@@ -20,7 +20,7 @@ WpAllocator wpMemArenaAllocatorInitWithBuffer(u8 *buffer, u64 buffer_size) {
|
||||
return allocator;
|
||||
}
|
||||
|
||||
initialise_arena_allocator(&allocator);
|
||||
initialiseArenaAllocator(&allocator);
|
||||
|
||||
return allocator;
|
||||
}
|
||||
@@ -32,7 +32,7 @@ WpAllocator wpMemArenaAllocatorInitCustom(u64 base_capacity, WpMemAllocFlags fla
|
||||
return allocator;
|
||||
}
|
||||
|
||||
initialise_arena_allocator(&allocator);
|
||||
initialiseArenaAllocator(&allocator);
|
||||
|
||||
return allocator;
|
||||
}
|
||||
@@ -58,29 +58,29 @@ void wpMemArenaAllocatorDestroy(WpAllocator *allocator) {
|
||||
*allocator = (WpAllocator){0};
|
||||
}
|
||||
|
||||
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;
|
||||
allocator->realloc_aligned = mem_arena_realloc_aligned;
|
||||
wp_intern void initialiseArenaAllocator(WpAllocator *allocator) {
|
||||
allocator->alloc = memArenaAlloc;
|
||||
allocator->alloc_aligned = memArenaAllocAligned;
|
||||
allocator->realloc = memArenaRealloc;
|
||||
allocator->realloc_aligned = memArenaReallocAligned;
|
||||
}
|
||||
|
||||
wp_intern void *mem_arena_alloc(u64 size, void *alloc_obj) {
|
||||
wp_intern void *memArenaAlloc(u64 size, void *alloc_obj) {
|
||||
WpArena *arena = (WpArena *)alloc_obj;
|
||||
return wpMemArenaAlloc(arena, size);
|
||||
}
|
||||
|
||||
wp_intern void *mem_arena_alloc_aligned(u64 size, u64 alignment, void *alloc_obj) {
|
||||
wp_intern void *memArenaAllocAligned(u64 size, u64 alignment, void *alloc_obj) {
|
||||
WpArena *arena = (WpArena *)alloc_obj;
|
||||
return wpMemArenaAllocAligned(arena, size, alignment);
|
||||
}
|
||||
|
||||
wp_intern void *mem_arena_realloc(void *ptr, u64 old_size, u64 new_size, void *alloc_obj) {
|
||||
wp_intern void *memArenaRealloc(void *ptr, u64 old_size, u64 new_size, void *alloc_obj) {
|
||||
WpArena *arena = (WpArena *)alloc_obj;
|
||||
return wpMemArenaRealloc(arena, ptr, old_size, new_size);
|
||||
}
|
||||
|
||||
wp_intern void *mem_arena_realloc_aligned(void *ptr, u64 old_size, u64 new_size, u64 alignment,
|
||||
wp_intern void *memArenaReallocAligned(void *ptr, u64 old_size, u64 new_size, u64 alignment,
|
||||
void *alloc_obj) {
|
||||
WpArena *arena = (WpArena *)alloc_obj;
|
||||
return wpMemArenaReallocAligned(arena, ptr, old_size, new_size, alignment);
|
||||
|
||||
@@ -61,7 +61,7 @@ CPATH_JOIN_LOOP_END:
|
||||
return WP_CPATH_JOIN_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
WpStr8 *_dirup(const WpAllocator *allocator, WpStr8RO *path, u64 levels) {
|
||||
WpStr8 *dirUp(const WpAllocator *allocator, WpStr8RO *path, u64 levels) {
|
||||
WpStr8 *output = NULL;
|
||||
if (!allocator || !path) {
|
||||
goto RETURN_DIRUP;
|
||||
|
||||
@@ -25,8 +25,8 @@ BEGIN_C_LINKAGE
|
||||
#error "Unrecognised platform"
|
||||
#endif
|
||||
|
||||
#define wpCpathDirname(ALLOCATOR, PATH) _dirup(ALLOCATOR, PATH, 1)
|
||||
#define wpCpathDirup(ALLOCATOR, PATH, COUNT) _dirup(ALLOCATOR, PATH, COUNT)
|
||||
#define wpCpathDirname(ALLOCATOR, PATH) dirUp(ALLOCATOR, PATH, 1)
|
||||
#define wpCpathDirUp(ALLOCATOR, PATH, COUNT) dirUp(ALLOCATOR, PATH, COUNT)
|
||||
|
||||
typedef enum {
|
||||
WP_CPATH_JOIN_RESULT_SUCCESS = 0,
|
||||
@@ -36,7 +36,7 @@ typedef enum {
|
||||
} WpCpathJoinResult;
|
||||
|
||||
WpCpathJoinResult wpCpathJoinPath(WpStr8 *dst, const WpStr8List *parts);
|
||||
WpStr8 *_dirup(const WpAllocator *allocator, WpStr8RO *path, u64 levels);
|
||||
WpStr8 *dirUp(const WpAllocator *allocator, WpStr8RO *path, u64 levels);
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
|
||||
+13
-13
@@ -10,17 +10,17 @@
|
||||
WpFile *wpFileOpen(const WpAllocator *allocator, WpStr8RO *filepath, WpFileAccessMode mode) {
|
||||
wpDebugAssert(allocator != NULL && filepath != NULL, "`allocator` and `filepath` should not be NULL");
|
||||
wpDebugAssert(filepath->size < WP_PATH_MAX, "`filepath` exceeds max path limit.");
|
||||
return _fileOpen(allocator, filepath, mode);
|
||||
return fileOpen(allocator, filepath, mode);
|
||||
}
|
||||
|
||||
i64 wpFileGetCurrentPosition(WpFile *file) {
|
||||
wpDebugAssert(file != NULL, "`file` should not be NULL.");
|
||||
return _fileSeek(file, 0, WP_SEEK_CURRENT);
|
||||
return fileSeek(file, 0, WP_SEEK_CURRENT);
|
||||
}
|
||||
|
||||
i64 wpFileSeek(WpFile *file, i64 offset, WpFileSeekOrigin origin) {
|
||||
wpDebugAssert(file != NULL, "`file` should not be NULL.");
|
||||
return _fileSeek(file, offset, origin);
|
||||
return fileSeek(file, offset, origin);
|
||||
}
|
||||
|
||||
i64 wpFileGetLength(WpFile *file) {
|
||||
@@ -28,12 +28,12 @@ i64 wpFileGetLength(WpFile *file) {
|
||||
|
||||
i64 current = wpFileGetCurrentPosition(file);
|
||||
|
||||
_fileSeek(file, 0, WP_SEEK_END);
|
||||
fileSeek(file, 0, WP_SEEK_END);
|
||||
|
||||
i64 output = wpFileGetCurrentPosition(file);
|
||||
|
||||
// Restore position
|
||||
_fileSeek(file, current, WP_SEEK_START);
|
||||
fileSeek(file, current, WP_SEEK_START);
|
||||
|
||||
return output;
|
||||
}
|
||||
@@ -47,13 +47,13 @@ u64 wpFileRead(void *dst_buf, WpFile *file, u64 byte_count) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return _fileRead(dst_buf, byte_count, file, file_length);
|
||||
return fileRead(dst_buf, byte_count, file, file_length);
|
||||
}
|
||||
|
||||
i64 wpFileWrite(const void *src_buf, WpFile *file, u64 byte_count) {
|
||||
wpDebugAssert(src_buf != NULL && file != NULL,
|
||||
"`src_buf` and `file` should not be NULL.");
|
||||
return _fileWrite(src_buf, file, byte_count);
|
||||
return fileWrite(src_buf, file, byte_count);
|
||||
}
|
||||
|
||||
u64 wpFileReadStr8(WpStr8 *str, WpFile *file) {
|
||||
@@ -87,7 +87,7 @@ u64 wpFileReadArray(WpArray dst_buf, WpFile *file, u64 item_count) {
|
||||
copy_byte_count = file_length <= dst_byte_capacity ? file_length : dst_byte_capacity;
|
||||
}
|
||||
|
||||
u64 byte_count = _fileRead(dst_buf, copy_byte_count, file, file_length);
|
||||
u64 byte_count = fileRead(dst_buf, copy_byte_count, file, file_length);
|
||||
if (byte_count == 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -106,7 +106,7 @@ i64 wpFileWriteArray(const WpArray src_buf, WpFile *file, u64 item_count) {
|
||||
u64 req_byte_count = item_count * item_size;
|
||||
u64 to_copy = req_byte_count <= src_byte_count ? req_byte_count : src_byte_count;
|
||||
|
||||
i64 bytes_written = _fileWrite(src_buf, file, to_copy);
|
||||
i64 bytes_written = fileWrite(src_buf, file, to_copy);
|
||||
if (bytes_written < 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -116,12 +116,12 @@ i64 wpFileWriteArray(const WpArray src_buf, WpFile *file, u64 item_count) {
|
||||
|
||||
i32 wpFileFlush(WpFile *file) {
|
||||
wpDebugAssert(file != NULL, "`file` should not be NULL.");
|
||||
return _fileFlush(file);
|
||||
return fileFlush(file);
|
||||
}
|
||||
|
||||
i32 wpFileClose(WpFile *file) {
|
||||
wpDebugAssert(file != NULL, "`file` should not be NULL.");
|
||||
return _fileClose(file);
|
||||
return fileClose(file);
|
||||
}
|
||||
|
||||
i32 wpFileRename(WpStr8RO *old_filepath, WpStr8RO *new_filepath) {
|
||||
@@ -129,11 +129,11 @@ i32 wpFileRename(WpStr8RO *old_filepath, WpStr8RO *new_filepath) {
|
||||
"`old_filepath` and `new_filepath` should not be NULL");
|
||||
wpDebugAssert(old_filepath->size < WP_PATH_MAX, "`old_filepath` exceeds max path limit.");
|
||||
wpDebugAssert(new_filepath->size < WP_PATH_MAX, "`new_filepath` exceeds max path limit.");
|
||||
return _fileRename(old_filepath, new_filepath);
|
||||
return fileRename(old_filepath, new_filepath);
|
||||
}
|
||||
|
||||
i32 wpFileRemove(WpStr8RO *filepath) {
|
||||
wpDebugAssert(filepath != NULL, "`filepath` should not be NULL");
|
||||
wpDebugAssert(filepath->size < WP_PATH_MAX, "`filepath` exceeds max path limit.");
|
||||
return _fileRemove(filepath);
|
||||
return fileRemove(filepath);
|
||||
}
|
||||
|
||||
+8
-8
@@ -61,14 +61,14 @@ i32 wpFileClose(WpFile *file);
|
||||
i32 wpFileRename(WpStr8RO *old_filepath, WpStr8RO *new_filepath);
|
||||
i32 wpFileRemove(WpStr8RO *filepath);
|
||||
|
||||
wp_extern WpFile *_fileOpen(const WpAllocator *allocator, WpStr8RO *filepath, WpFileAccessMode mode);
|
||||
wp_extern i64 _fileSeek(WpFile *file, i64 offset, WpFileSeekOrigin origin);
|
||||
wp_extern u64 _fileRead(void *dst_buf, u64 byte_count, WpFile *file, u64 file_length);
|
||||
wp_extern i64 _fileWrite(const void *src_buf, WpFile *file, u64 byte_count);
|
||||
wp_extern i32 _fileFlush(WpFile *file);
|
||||
wp_extern i32 _fileClose(WpFile *file);
|
||||
wp_extern i32 _fileRename(WpStr8RO *old_filepath, WpStr8RO *new_filepath);
|
||||
wp_extern i32 _fileRemove(WpStr8RO *filepath);
|
||||
wp_extern WpFile *fileOpen(const WpAllocator *allocator, WpStr8RO *filepath, WpFileAccessMode mode);
|
||||
wp_extern i64 fileSeek(WpFile *file, i64 offset, WpFileSeekOrigin origin);
|
||||
wp_extern u64 fileRead(void *dst_buf, u64 byte_count, WpFile *file, u64 file_length);
|
||||
wp_extern i64 fileWrite(const void *src_buf, WpFile *file, u64 byte_count);
|
||||
wp_extern i32 fileFlush(WpFile *file);
|
||||
wp_extern i32 fileClose(WpFile *file);
|
||||
wp_extern i32 fileRename(WpStr8RO *old_filepath, WpStr8RO *new_filepath);
|
||||
wp_extern i32 fileRemove(WpStr8RO *filepath);
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
|
||||
@@ -64,7 +64,7 @@ WpFile *wpFileStderr(void) {
|
||||
return &_stderr;
|
||||
}
|
||||
|
||||
WpFile *_fileOpen(const WpAllocator *allocator, WpStr8RO *filepath, WpFileAccessMode mode) {
|
||||
WpFile *fileOpen(const WpAllocator *allocator, WpStr8RO *filepath, WpFileAccessMode mode) {
|
||||
wp_persist c8 tmp[WP_PATH_MAX] = {0};
|
||||
memset(tmp, 0, WP_PATH_MAX);
|
||||
memcpy(tmp, filepath->buf, filepath->size);
|
||||
@@ -82,11 +82,11 @@ WpFile *_fileOpen(const WpAllocator *allocator, WpStr8RO *filepath, WpFileAccess
|
||||
return output;
|
||||
}
|
||||
|
||||
i64 _fileSeek(WpFile *file, i64 offset, WpFileSeekOrigin origin) {
|
||||
i64 fileSeek(WpFile *file, i64 offset, WpFileSeekOrigin origin) {
|
||||
return lseek64(file->fd, offset, file_seek_origins[origin]);
|
||||
}
|
||||
|
||||
u64 _fileRead(void *dst_buf, u64 byte_count, WpFile *file, u64 file_length) {
|
||||
u64 fileRead(void *dst_buf, u64 byte_count, WpFile *file, u64 file_length) {
|
||||
u64 copy_byte_count = file_length <= byte_count ? file_length : byte_count;
|
||||
|
||||
i64 count = read(file->fd, dst_buf, copy_byte_count);
|
||||
@@ -95,19 +95,19 @@ u64 _fileRead(void *dst_buf, u64 byte_count, WpFile *file, u64 file_length) {
|
||||
return count;
|
||||
}
|
||||
|
||||
i64 _fileWrite(const void *src_buf, WpFile *file, u64 byte_count) {
|
||||
i64 fileWrite(const void *src_buf, WpFile *file, u64 byte_count) {
|
||||
return write(file->fd, src_buf, byte_count);
|
||||
}
|
||||
|
||||
i32 _fileFlush(WpFile *file) {
|
||||
i32 fileFlush(WpFile *file) {
|
||||
return fsync(file->fd);
|
||||
}
|
||||
|
||||
i32 _fileClose(WpFile *file) {
|
||||
i32 fileClose(WpFile *file) {
|
||||
return close(file->fd);
|
||||
}
|
||||
|
||||
i32 _fileRename(WpStr8RO *old_filepath, WpStr8RO *new_filepath) {
|
||||
i32 fileRename(WpStr8RO *old_filepath, WpStr8RO *new_filepath) {
|
||||
wp_persist c8 old_tmp[WP_PATH_MAX] = {0};
|
||||
wp_persist c8 new_tmp[WP_PATH_MAX] = {0};
|
||||
memset(old_tmp, 0, WP_PATH_MAX);
|
||||
@@ -117,13 +117,13 @@ i32 _fileRename(WpStr8RO *old_filepath, WpStr8RO *new_filepath) {
|
||||
|
||||
i32 link_result = link((const char *)old_tmp, (const char *)new_tmp);
|
||||
if (link_result == 0) {
|
||||
_fileRemove(old_filepath);
|
||||
fileRemove(old_filepath);
|
||||
}
|
||||
|
||||
return link_result;
|
||||
}
|
||||
|
||||
i32 _fileRemove(WpStr8RO *filepath) {
|
||||
i32 fileRemove(WpStr8RO *filepath) {
|
||||
wp_persist c8 tmp[WP_PATH_MAX] = {0};
|
||||
memset(tmp, 0, WP_PATH_MAX);
|
||||
memcpy(tmp, filepath->buf, filepath->size);
|
||||
|
||||
@@ -72,7 +72,7 @@ WpFile *wpFileStderr(void) {
|
||||
return &_stderr;
|
||||
}
|
||||
|
||||
WpFile *_fileOpen(const WpAllocator *allocator, WpStr8RO *filepath, WpFileAccessMode mode) {
|
||||
WpFile *fileOpen(const WpAllocator *allocator, WpStr8RO *filepath, WpFileAccessMode mode) {
|
||||
wp_persist c8 tmp[WP_PATH_MAX] = {0};
|
||||
memset(tmp, 0, WP_PATH_MAX);
|
||||
memcpy(tmp, filepath->buf, filepath->size);
|
||||
@@ -96,7 +96,7 @@ WpFile *_fileOpen(const WpAllocator *allocator, WpStr8RO *filepath, WpFileAccess
|
||||
return output;
|
||||
}
|
||||
|
||||
i64 _fileSeek(WpFile *file, i64 offset, WpFileSeekOrigin origin) {
|
||||
i64 fileSeek(WpFile *file, i64 offset, WpFileSeekOrigin origin) {
|
||||
LARGE_INTEGER distance = {0};
|
||||
LARGE_INTEGER output = {0};
|
||||
|
||||
@@ -109,7 +109,7 @@ i64 _fileSeek(WpFile *file, i64 offset, WpFileSeekOrigin origin) {
|
||||
return output.QuadPart;
|
||||
}
|
||||
|
||||
u64 _fileRead(void* dst_buf, u64 byte_count, WpFile* file, u64 file_length) {
|
||||
u64 fileRead(void* dst_buf, u64 byte_count, WpFile* file, u64 file_length) {
|
||||
u64 copy_byte_count = file_length <= byte_count ? file_length : byte_count;
|
||||
wpDebugAssert(copy_byte_count <= DWORD_MAX, "Attempting to read large number of bytes at once");
|
||||
|
||||
@@ -121,7 +121,7 @@ u64 _fileRead(void* dst_buf, u64 byte_count, WpFile* file, u64 file_length) {
|
||||
return (u64)read_count;
|
||||
}
|
||||
|
||||
i64 _fileWrite(const void *src_buf, WpFile *file, u64 byte_count) {
|
||||
i64 fileWrite(const void *src_buf, WpFile *file, u64 byte_count) {
|
||||
wpDebugAssert(byte_count <= DWORD_MAX, "Attempting to write large number of bytes at once");
|
||||
|
||||
DWORD write_count = 0;
|
||||
@@ -131,7 +131,7 @@ i64 _fileWrite(const void *src_buf, WpFile *file, u64 byte_count) {
|
||||
return (i64)write_count;
|
||||
}
|
||||
|
||||
i32 _fileFlush(WpFile *file) {
|
||||
i32 fileFlush(WpFile *file) {
|
||||
if (!FlushFileBuffers(file->fh)) {
|
||||
return -1;
|
||||
}
|
||||
@@ -139,7 +139,7 @@ i32 _fileFlush(WpFile *file) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
i32 _fileClose(WpFile *file) {
|
||||
i32 fileClose(WpFile *file) {
|
||||
if (!CloseHandle(file->fh)) {
|
||||
return -1;
|
||||
}
|
||||
@@ -147,7 +147,7 @@ i32 _fileClose(WpFile *file) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
i32 _fileRename(WpStr8RO *old_filepath, WpStr8RO *new_filepath) {
|
||||
i32 fileRename(WpStr8RO *old_filepath, WpStr8RO *new_filepath) {
|
||||
wp_persist c8 old_tmp[WP_PATH_MAX] = {0};
|
||||
wp_persist c8 new_tmp[WP_PATH_MAX] = {0};
|
||||
memset(old_tmp, 0, WP_PATH_MAX);
|
||||
@@ -162,7 +162,7 @@ i32 _fileRename(WpStr8RO *old_filepath, WpStr8RO *new_filepath) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
i32 _fileRemove(WpStr8RO *filepath) {
|
||||
i32 fileRemove(WpStr8RO *filepath) {
|
||||
wp_persist c8 tmp[WP_PATH_MAX] = {0};
|
||||
memset(tmp, 0, WP_PATH_MAX);
|
||||
memcpy(tmp, filepath->buf, filepath->size);
|
||||
|
||||
+2
-2
@@ -16,7 +16,7 @@
|
||||
#endif
|
||||
|
||||
void *wpOsMemAlloc(void *addr, u64 size, WpMemAccess access, WpMemAllocFlags flags, WpMemInitType type) {
|
||||
void *output = _osMemAllocate(addr, size, access, flags, type);
|
||||
void *output = osMemAllocate(addr, size, access, flags, type);
|
||||
|
||||
if (type == WP_MEM_INIT_INITIALISED) {
|
||||
memset(output, 0, size);
|
||||
@@ -26,5 +26,5 @@ void *wpOsMemAlloc(void *addr, u64 size, WpMemAccess access, WpMemAllocFlags fla
|
||||
}
|
||||
|
||||
void wpOsMemFree(void *ptr, u64 size) {
|
||||
_osMemFree(ptr, size);
|
||||
osMemFree(ptr, size);
|
||||
}
|
||||
|
||||
+2
-2
@@ -23,8 +23,8 @@ BEGIN_C_LINKAGE
|
||||
void *wpOsMemAlloc(void *addr, u64 size, WpMemAccess access, WpMemAllocFlags flags, WpMemInitType type);
|
||||
void wpOsMemFree(void *ptr, u64 size);
|
||||
|
||||
wp_extern void *_osMemAllocate(void *addr, u64 size, WpMemAccess access, WpMemAllocFlags flags, WpMemInitType type);
|
||||
wp_extern void _osMemFree(void *ptr, u64 size);
|
||||
wp_extern void *osMemAllocate(void *addr, u64 size, WpMemAccess access, WpMemAllocFlags flags, WpMemInitType type);
|
||||
wp_extern void osMemFree(void *ptr, u64 size);
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
|
||||
@@ -18,7 +18,7 @@ wp_intern const i32 access_types[] = {
|
||||
[WP_MEM_ACCESS_READ_WRITE_EXEC] = PROT_READ | PROT_WRITE | PROT_EXEC,
|
||||
};
|
||||
|
||||
void *_osMemAllocate(void *addr, u64 size, WpMemAccess access, WpMemAllocFlags flags, WpMemInitType type) {
|
||||
void *osMemAllocate(void *addr, u64 size, WpMemAccess access, WpMemAllocFlags flags, WpMemInitType type) {
|
||||
(void)type;
|
||||
i32 alloc_flags = flags | MAP_ANON | MAP_PRIVATE;
|
||||
|
||||
@@ -29,7 +29,7 @@ void *_osMemAllocate(void *addr, u64 size, WpMemAccess access, WpMemAllocFlags f
|
||||
return mmap(addr, size, access_types[access], alloc_flags, -1, 0);
|
||||
}
|
||||
|
||||
void _osMemFree(void *ptr, u64 size) {
|
||||
void osMemFree(void *ptr, u64 size) {
|
||||
munmap(ptr, size);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ wp_intern const i32 access_types[] = {
|
||||
[WP_MEM_ACCESS_READ_WRITE_EXEC] = PAGE_EXECUTE_READWRITE,
|
||||
};
|
||||
|
||||
void *_osMemAllocate(void *addr, u64 size, WpMemAccess access, WpMemAllocFlags flags, WpMemInitType type) {
|
||||
void *osMemAllocate(void *addr, u64 size, WpMemAccess access, WpMemAllocFlags flags, WpMemInitType type) {
|
||||
// Ensure memory is committed if it's meant to be initialised
|
||||
if (type == WP_MEM_INIT_INITIALISED) {
|
||||
flags |= WP_MEM_ALLOC_COMMIT;
|
||||
@@ -30,7 +30,7 @@ void *_osMemAllocate(void *addr, u64 size, WpMemAccess access, WpMemAllocFlags f
|
||||
return VirtualAlloc(addr, (SIZE_T)size, flags, access_types[access]);
|
||||
}
|
||||
|
||||
void _osMemFree(void *ptr, u64 size) {
|
||||
void osMemFree(void *ptr, u64 size) {
|
||||
VirtualFree(ptr, size, MEM_RELEASE);
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ wp_intern WpCmdResult executeCommand(WpStr8RO *cmd, WpCmdOutHandling out_handlin
|
||||
}
|
||||
|
||||
i32 st = EXIT_SUCCESS;
|
||||
err = _getOutputStatus(fp, &st);
|
||||
err = getOutputStatus(fp, &st);
|
||||
if (err > WP_SHELL_ERR_NO_ERROR) {
|
||||
output = wpCmdNoExit(err);
|
||||
goto executeCommand_CLOSE;
|
||||
|
||||
@@ -20,7 +20,7 @@ BEGIN_C_LINKAGE
|
||||
|
||||
WpCmdResult wpShellCommanderExecute(WpCmdOutHandling out_handling, WpStr8 *out_buf, const WpStr8List *cmd);
|
||||
|
||||
wp_extern WpCmdError _getOutputStatus(FILE *fp, i32 *status_out);
|
||||
wp_extern WpCmdError getOutputStatus(FILE *fp, i32 *status_out);
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
WpCmdError _getOutputStatus(FILE *fp, i32 *status_out) {
|
||||
WpCmdError getOutputStatus(FILE *fp, i32 *status_out) {
|
||||
*status_out = wpShellUtilsPclose(fp);
|
||||
|
||||
if (!WIFEXITED(*status_out)) {
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "../../utils/shell_utils.h"
|
||||
#include <stdio.h>
|
||||
|
||||
WpCmdError _getOutputStatus(FILE *fp, i32 *status_out) {
|
||||
WpCmdError getOutputStatus(FILE *fp, i32 *status_out) {
|
||||
if (!feof(fp)) {
|
||||
// Ensure process is closed on failure
|
||||
wpShellUtilsPclose(fp);
|
||||
|
||||
@@ -29,7 +29,7 @@ wp_intern WpStr8RO colours[COUNT_TERM_COLOUR] = {
|
||||
[WP_TERM_COLOUR_CLEAR] = wpStr8LitRoInitialiserList("\033[0m"),
|
||||
};
|
||||
|
||||
void _printColouredText(WpStr8RO *text, WpTerminalColour colour) {
|
||||
void printColouredText(WpStr8RO *text, WpTerminalColour colour) {
|
||||
printf(WP_STR8_SPEC WP_STR8_SPEC, wpStr8Varg(colours[colour]), wpStr8Varg((*text)));
|
||||
}
|
||||
|
||||
|
||||
@@ -9,10 +9,10 @@ void wpShellTermcolourPrintText(WpStr8RO *text, WpTerminalColour colour) {
|
||||
return;
|
||||
}
|
||||
|
||||
_printColouredText(text, colour);
|
||||
printColouredText(text, colour);
|
||||
}
|
||||
|
||||
void wpShellTermcolourClearColour(void) {
|
||||
WpStr8RO empty = wpStr8LitRo("");
|
||||
_printColouredText(&empty, WP_TERM_COLOUR_CLEAR);
|
||||
printColouredText(&empty, WP_TERM_COLOUR_CLEAR);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ BEGIN_C_LINKAGE
|
||||
void wpShellTermcolourPrintText(WpStr8RO *text, WpTerminalColour colour);
|
||||
void wpShellTermcolourClearColour(void);
|
||||
|
||||
wp_extern void _printColouredText(WpStr8RO *text, WpTerminalColour colour);
|
||||
wp_extern void printColouredText(WpStr8RO *text, WpTerminalColour colour);
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
|
||||
@@ -22,7 +22,7 @@ struct TermcolourData {
|
||||
wpMiscUtilsReservePadding(sizeof(HANDLE) + sizeof(WORD) + sizeof(WORD));
|
||||
};
|
||||
|
||||
wp_intern void init_data(TermcolourData *data);
|
||||
wp_intern void initData(TermcolourData *data);
|
||||
|
||||
wp_intern WORD colours[COUNT_TERM_COLOUR] = {
|
||||
[WP_TERM_COLOUR_FG_BLACK] = 0,
|
||||
@@ -43,10 +43,10 @@ wp_intern WORD colours[COUNT_TERM_COLOUR] = {
|
||||
[WP_TERM_COLOUR_FG_BR_WHITE] = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY,
|
||||
};
|
||||
|
||||
void _printColouredText(WpStr8RO *text, WpTerminalColour colour) {
|
||||
void printColouredText(WpStr8RO *text, WpTerminalColour colour) {
|
||||
wp_persist TermcolourData data = {0};
|
||||
if (data.handle == 0) {
|
||||
init_data(&data);
|
||||
initData(&data);
|
||||
}
|
||||
|
||||
if (colour == WP_TERM_COLOUR_CLEAR) {
|
||||
@@ -59,7 +59,7 @@ void _printColouredText(WpStr8RO *text, WpTerminalColour colour) {
|
||||
printf(WP_STR8_SPEC, wpStr8Varg((*text)));
|
||||
}
|
||||
|
||||
wp_intern void init_data(TermcolourData *data) {
|
||||
wp_intern void initData(TermcolourData *data) {
|
||||
// create handle
|
||||
data->handle = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@ struct SplitMix64State {
|
||||
u64 seed;
|
||||
};
|
||||
|
||||
wp_intern u64 split_mix_64(SplitMix64State *state);
|
||||
wp_intern void seed_os_generator(u64 seed);
|
||||
wp_intern u64 generate_random_number(void);
|
||||
wp_intern u64 splitMix64(SplitMix64State *state);
|
||||
wp_intern void seedOsGenerator(u64 seed);
|
||||
wp_intern u64 genRandomNumber(void);
|
||||
|
||||
WpXor256State wpPrngXorshiftInit(void) {
|
||||
return wpPrngXorshiftInitWithSeed(0);
|
||||
@@ -25,16 +25,16 @@ WpXor256State wpPrngXorshiftInitWithSeed(u64 seed) {
|
||||
wp_persist b8 seeded = false;
|
||||
if (!seeded) {
|
||||
seeded = true;
|
||||
seed_os_generator(seed);
|
||||
seedOsGenerator(seed);
|
||||
}
|
||||
|
||||
SplitMix64State sm64 = {.seed = generate_random_number()};
|
||||
SplitMix64State sm64 = {.seed = genRandomNumber()};
|
||||
|
||||
return (WpXor256State){
|
||||
.x = split_mix_64(&sm64),
|
||||
.y = split_mix_64(&sm64),
|
||||
.z = split_mix_64(&sm64),
|
||||
.w = split_mix_64(&sm64),
|
||||
.x = splitMix64(&sm64),
|
||||
.y = splitMix64(&sm64),
|
||||
.z = splitMix64(&sm64),
|
||||
.w = splitMix64(&sm64),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ u64 wpPrngXorshift256pChoice(WpXor256State *state, u64 available_choices) {
|
||||
return wpPrngXorshift256p(state) % available_choices;
|
||||
}
|
||||
|
||||
wp_intern u64 split_mix_64(SplitMix64State *state) {
|
||||
wp_intern u64 splitMix64(SplitMix64State *state) {
|
||||
state->seed += 0x9E3779B97f4A7C15;
|
||||
|
||||
u64 result = state->seed;
|
||||
@@ -115,7 +115,7 @@ wp_intern u64 split_mix_64(SplitMix64State *state) {
|
||||
|
||||
#if defined(WP_PLATFORM_C) && WP_PLATFORM_C_VERSION >= WP_PLATFORM_C11_VERSION
|
||||
#ifdef WP_PLATFORM_POSIX
|
||||
wp_intern void seed_os_generator(u64 seed) {
|
||||
wp_intern void seedOsGenerator(u64 seed) {
|
||||
if (seed == 0) {
|
||||
struct timespec ts = {0};
|
||||
int result = clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
|
||||
@@ -126,11 +126,11 @@ wp_intern void seed_os_generator(u64 seed) {
|
||||
srand48(seed);
|
||||
}
|
||||
|
||||
wp_intern u64 generate_random_number(void) {
|
||||
wp_intern u64 genRandomNumber(void) {
|
||||
return lrand48();
|
||||
}
|
||||
#else
|
||||
wp_intern void seed_os_generator(u64 seed) {
|
||||
wp_intern void seedOsGenerator(u64 seed) {
|
||||
if (seed == 0) {
|
||||
struct timespec ts = {0};
|
||||
int result = timespec_get(&ts, TIME_UTC);
|
||||
@@ -141,7 +141,7 @@ wp_intern void seed_os_generator(u64 seed) {
|
||||
srand(seed);
|
||||
}
|
||||
|
||||
wp_intern u64 generate_random_number(void) {
|
||||
wp_intern u64 genRandomNumber(void) {
|
||||
i32 n1 = rand();
|
||||
i32 n2 = rand();
|
||||
|
||||
@@ -149,7 +149,7 @@ wp_intern u64 generate_random_number(void) {
|
||||
}
|
||||
#endif // !WP_PLATFORM_POSIX
|
||||
#else
|
||||
wp_intern void seed_os_generator(u64 seed) {
|
||||
wp_intern void seedOsGenerator(u64 seed) {
|
||||
if (seed == 0) {
|
||||
time_t result = time(NULL);
|
||||
wpRuntimeAssert(result != (time_t)(-1), "Invalid seed value");
|
||||
@@ -159,7 +159,7 @@ wp_intern void seed_os_generator(u64 seed) {
|
||||
srand(seed);
|
||||
}
|
||||
|
||||
wp_intern u64 generate_random_number(void) {
|
||||
wp_intern u64 genRandomNumber(void) {
|
||||
i32 n1 = rand();
|
||||
i32 n2 = rand();
|
||||
|
||||
|
||||
@@ -20,15 +20,15 @@ struct WpXor256State {
|
||||
|
||||
WpXor256State wpPrngXorshiftInit(void);
|
||||
WpXor256State wpPrngXorshiftInitWithSeed(u64 seed);
|
||||
u64 wpPrngXorshift256(WpXor256State *state);
|
||||
u64 wpPrngXorshift256ss(WpXor256State *state);
|
||||
u64 wpPrngXorshift256p(WpXor256State *state);
|
||||
u64 wpPrngXorshift256InRange(WpXor256State *state, u64 start, u64 end);
|
||||
u64 wpPrngXorshift256ssInRange(WpXor256State *state, u64 start, u64 end);
|
||||
u64 wpPrngXorshift256pInRange(WpXor256State *state, u64 start, u64 end);
|
||||
u64 wpPrngXorshift256Choice(WpXor256State *state, u64 available_choices);
|
||||
u64 wpPrngXorshift256ssChoice(WpXor256State *state, u64 available_choices);
|
||||
u64 wpPrngXorshift256pChoice(WpXor256State *state, u64 available_choices);
|
||||
u64 wpPrngXorshift256(WpXor256State *state);
|
||||
u64 wpPrngXorshift256ss(WpXor256State *state);
|
||||
u64 wpPrngXorshift256p(WpXor256State *state);
|
||||
u64 wpPrngXorshift256InRange(WpXor256State *state, u64 start, u64 end);
|
||||
u64 wpPrngXorshift256ssInRange(WpXor256State *state, u64 start, u64 end);
|
||||
u64 wpPrngXorshift256pInRange(WpXor256State *state, u64 start, u64 end);
|
||||
u64 wpPrngXorshift256Choice(WpXor256State *state, u64 available_choices);
|
||||
u64 wpPrngXorshift256ssChoice(WpXor256State *state, u64 available_choices);
|
||||
u64 wpPrngXorshift256pChoice(WpXor256State *state, u64 available_choices);
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
wp_intern void handleTestResult(WpTestFuncResult result);
|
||||
|
||||
void _runTests(WpTestFunc *func1, ...) {
|
||||
void runTests(WpTestFunc *func1, ...) {
|
||||
printf("\n");
|
||||
|
||||
handleTestResult(func1());
|
||||
|
||||
@@ -15,7 +15,7 @@ BEGIN_C_LINKAGE
|
||||
#define wpTesterResult(PASSED) ((WpTestFuncResult){.name = wpStr8LitRo(__func__), .passed = PASSED})
|
||||
#endif // !WP_PLATFORM_CPP
|
||||
|
||||
#define wpTesterRun(...) _runTests(__VA_ARGS__, NULL)
|
||||
#define wpTesterRun(...) runTests(__VA_ARGS__, NULL)
|
||||
|
||||
typedef struct WpTestFuncResult WpTestFuncResult;
|
||||
struct WpTestFuncResult {
|
||||
@@ -27,7 +27,7 @@ struct WpTestFuncResult {
|
||||
|
||||
typedef WpTestFuncResult(WpTestFunc)(void);
|
||||
|
||||
void _runTests(WpTestFunc *func1, ...);
|
||||
void runTests(WpTestFunc *func1, ...);
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
|
||||
+6
-6
@@ -15,19 +15,19 @@ struct UUID4 {
|
||||
u64 low;
|
||||
};
|
||||
|
||||
wp_intern UUID4 generate_uuid4(void);
|
||||
wp_intern void uuid4_to_uuid(const UUID4* uuid4, WpUuid *uuid);
|
||||
wp_intern UUID4 genUuid4(void);
|
||||
wp_intern void uuid4ToUuid(const UUID4* uuid4, WpUuid *uuid);
|
||||
|
||||
WpUuid *wpUuidInitUuid4(WpUuid *uuid) {
|
||||
wpDebugAssert(uuid != NULL, "`uuid` should not be NULL");
|
||||
|
||||
UUID4 uuid4 = generate_uuid4();
|
||||
uuid4_to_uuid(&uuid4, uuid);
|
||||
UUID4 uuid4 = genUuid4();
|
||||
uuid4ToUuid(&uuid4, uuid);
|
||||
|
||||
return uuid;
|
||||
}
|
||||
|
||||
wp_intern UUID4 generate_uuid4(void) {
|
||||
wp_intern UUID4 genUuid4(void) {
|
||||
wp_persist WpXor256State state = {0};
|
||||
wp_persist b8 initialised = false;
|
||||
|
||||
@@ -47,7 +47,7 @@ wp_intern UUID4 generate_uuid4(void) {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
wp_intern void uuid4_to_uuid(const UUID4* uuid4, WpUuid *uuid) {
|
||||
wp_intern void uuid4ToUuid(const UUID4* uuid4, WpUuid *uuid) {
|
||||
u64 group1 = uuid4->high >> 32;
|
||||
u64 group2 = (uuid4->high << 32) >> 48;
|
||||
u64 group3 = (uuid4->high << 48) >> 48;
|
||||
|
||||
@@ -144,35 +144,35 @@ WpTestFuncResult test_cpath_dirup(void) {
|
||||
wpStr8Format(&tmp, "%c", WP_PATH_SEP);
|
||||
wpStr8Format(&expected, "%c", WP_PATH_SEP);
|
||||
|
||||
output = wpCpathDirup(&arena, &tmp, 3);
|
||||
output = wpCpathDirUp(&arena, &tmp, 3);
|
||||
result = output != NULL && wpStr8Equal(output, &expected);
|
||||
|
||||
// CASE 2
|
||||
wpStr8Format(&tmp, "%chome%cabdelrahman%cDocuments", WP_PATH_SEP, WP_PATH_SEP, WP_PATH_SEP);
|
||||
wpStr8Format(&expected, "%c", WP_PATH_SEP);
|
||||
|
||||
output = wpCpathDirup(&arena, &tmp, 3);
|
||||
output = wpCpathDirUp(&arena, &tmp, 3);
|
||||
result = result && output != NULL && wpStr8Equal(output, &expected);
|
||||
|
||||
// CASE 3
|
||||
wpStr8Format(&tmp, "home%cabdelrahman%cDocuments", WP_PATH_SEP, WP_PATH_SEP);
|
||||
wpStr8CopyCstrCapped(&expected, ".");
|
||||
|
||||
output = wpCpathDirup(&arena, &tmp, 3);
|
||||
output = wpCpathDirUp(&arena, &tmp, 3);
|
||||
result = result && output != NULL && wpStr8Equal(output, &expected);
|
||||
|
||||
// CASE 4
|
||||
wpStr8Format(&tmp, "%chome%cabdelrahman%cDocuments", WP_PATH_SEP, WP_PATH_SEP, WP_PATH_SEP);
|
||||
wpStr8Format(&expected, "%chome", WP_PATH_SEP);
|
||||
|
||||
output = wpCpathDirup(&arena, &tmp, 2);
|
||||
output = wpCpathDirUp(&arena, &tmp, 2);
|
||||
result = result && output != NULL && wpStr8Equal(output, &expected);
|
||||
|
||||
// CASE 5
|
||||
wpStr8Format(&tmp, "home%cabdelrahman%cDocuments", WP_PATH_SEP, WP_PATH_SEP);
|
||||
wpStr8CopyCstrCapped(&expected, "home");
|
||||
|
||||
output = wpCpathDirup(&arena, &tmp, 2);
|
||||
output = wpCpathDirUp(&arena, &tmp, 2);
|
||||
result = result && output != NULL && wpStr8Equal(output, &expected);
|
||||
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
@@ -164,35 +164,35 @@ WpTestFuncResult test_cpath_dirup(void) {
|
||||
wpStr8Format(&tmp, "%c", WP_PATH_SEP);
|
||||
wpStr8Format(&expected, "%c", WP_PATH_SEP);
|
||||
|
||||
output = wpCpathDirup(&arena, &tmp, 3);
|
||||
output = wpCpathDirUp(&arena, &tmp, 3);
|
||||
result = output != nullptr && wpStr8Equal(output, &expected);
|
||||
|
||||
// CASE 2
|
||||
wpStr8Format(&tmp, "%chome%cabdelrahman%cDocuments", WP_PATH_SEP, WP_PATH_SEP, WP_PATH_SEP);
|
||||
wpStr8Format(&expected, "%c", WP_PATH_SEP);
|
||||
|
||||
output = wpCpathDirup(&arena, &tmp, 3);
|
||||
output = wpCpathDirUp(&arena, &tmp, 3);
|
||||
result = result && output != nullptr && wpStr8Equal(output, &expected);
|
||||
|
||||
// CASE 3
|
||||
wpStr8Format(&tmp, "home%cabdelrahman%cDocuments", WP_PATH_SEP, WP_PATH_SEP);
|
||||
wpStr8CopyCstrCapped(&expected, ".");
|
||||
|
||||
output = wpCpathDirup(&arena, &tmp, 3);
|
||||
output = wpCpathDirUp(&arena, &tmp, 3);
|
||||
result = result && output != nullptr && wpStr8Equal(output, &expected);
|
||||
|
||||
// CASE 4
|
||||
wpStr8Format(&tmp, "%chome%cabdelrahman%cDocuments", WP_PATH_SEP, WP_PATH_SEP, WP_PATH_SEP);
|
||||
wpStr8Format(&expected, "%chome", WP_PATH_SEP);
|
||||
|
||||
output = wpCpathDirup(&arena, &tmp, 2);
|
||||
output = wpCpathDirUp(&arena, &tmp, 2);
|
||||
result = result && output != nullptr && wpStr8Equal(output, &expected);
|
||||
|
||||
// CASE 5
|
||||
wpStr8Format(&tmp, "home%cabdelrahman%cDocuments", WP_PATH_SEP, WP_PATH_SEP);
|
||||
wpStr8CopyCstrCapped(&expected, "home");
|
||||
|
||||
output = wpCpathDirup(&arena, &tmp, 2);
|
||||
output = wpCpathDirUp(&arena, &tmp, 2);
|
||||
result = result && output != nullptr && wpStr8Equal(output, &expected);
|
||||
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
Reference in New Issue
Block a user