Rename asserts

This commit is contained in:
2026-06-26 15:32:23 +01:00
parent 61c1ec99e5
commit 65d99db738
15 changed files with 126 additions and 126 deletions
+3 -3
View File
@@ -34,9 +34,9 @@ override HEADER_INSTALL_CMD := scripts/header_install.sh
ifeq ($(origin BUILD_FLAGS), undefined)
ifeq ($(BUILD_TYPE),Debug)
BUILD_FLAGS += -g -fsanitize=address,undefined -DWAPP_DEBUG_ASSERT
BUILD_FLAGS += -g -fsanitize=address,undefined -DWP_DEBUG_ASSERT
else ifeq ($(BUILD_TYPE),RelWithDebInfo)
BUILD_FLAGS += -g -O2 -fsanitize=address,undefined -DWAPP_DEBUG_ASSERT
BUILD_FLAGS += -g -O2 -fsanitize=address,undefined -DWP_DEBUG_ASSERT
else ifeq ($(BUILD_TYPE),Release)
BUILD_FLAGS += -O3
else
@@ -46,7 +46,7 @@ endif
# Disable runtime asserts
ifeq ($(RUNTIME_ASSERT), false)
override BUILD_FLAGS += -DWAPP_NO_RUNTIME_ASSERT
override BUILD_FLAGS += -DWP_NO_RUNTIME_ASSERT
endif
ifeq ($(CC),gcc)
+22 -22
View File
@@ -12,47 +12,47 @@
wp_persist inline void _array_validate(const GenericArray array, u64 item_size);
u64 _array_count(GenericArray array) {
wapp_debug_assert(array != NULL, "`array` should not be NULL");
wpDebugAssert(array != NULL, "`array` should not be NULL");
ArrayHeader *header = _array_header(array);
wapp_runtime_assert(WAPP_ARRAY_MAGIC == header->magic, "`array` is not a valid wapp array");
wpRuntimeAssert(WAPP_ARRAY_MAGIC == header->magic, "`array` is not a valid wapp array");
return header->count;
}
u64 _array_capacity(GenericArray array) {
wapp_debug_assert(array != NULL, "`array` should not be NULL");
wpDebugAssert(array != NULL, "`array` should not be NULL");
ArrayHeader *header = _array_header(array);
wapp_runtime_assert(WAPP_ARRAY_MAGIC == header->magic, "`array` is not a valid wapp array");
wpRuntimeAssert(WAPP_ARRAY_MAGIC == header->magic, "`array` is not a valid wapp array");
return header->capacity;
}
u64 _array_item_size(GenericArray array) {
wapp_debug_assert(array != NULL, "`array` should not be NULL");
wpDebugAssert(array != NULL, "`array` should not be NULL");
ArrayHeader *header = _array_header(array);
wapp_runtime_assert(WAPP_ARRAY_MAGIC == header->magic, "`array` is not a valid wapp array");
wpRuntimeAssert(WAPP_ARRAY_MAGIC == header->magic, "`array` is not a valid wapp array");
return header->item_size;
}
void _array_set_count(GenericArray array, u64 count) {
wapp_debug_assert(array != NULL, "`array` should not be NULL");
wpDebugAssert(array != NULL, "`array` should not be NULL");
ArrayHeader *header = _array_header(array);
wapp_runtime_assert(WAPP_ARRAY_MAGIC == header->magic, "`array` is not a valid wapp array");
wpRuntimeAssert(WAPP_ARRAY_MAGIC == header->magic, "`array` is not a valid wapp array");
header->count = count;
}
void *_array_get(GenericArray array, u64 index, u64 item_size) {
wapp_runtime_assert(array != NULL, "`array` should not be NULL");
wpRuntimeAssert(array != NULL, "`array` should not be NULL");
_array_validate(array, item_size);
ArrayHeader *header = _array_header(array);
wapp_runtime_assert(index < header->count, "`index` is out of bounds");
wpRuntimeAssert(index < header->count, "`index` is out of bounds");
return wapp_pointer_offset(array, header->item_size * index);
}
@@ -65,7 +65,7 @@ void _array_set(GenericArray array, u64 index, void *value, u64 item_size) {
}
void _array_append_capped(GenericArray array, void *value, u64 item_size) {
wapp_runtime_assert(array != NULL, "`array` should not be NULL");
wpRuntimeAssert(array != NULL, "`array` should not be NULL");
_array_validate(array, item_size);
ArrayHeader *header = _array_header(array);
@@ -76,7 +76,7 @@ void _array_append_capped(GenericArray array, void *value, u64 item_size) {
}
void _array_extend_capped(GenericArray dst, const GenericArray src, u64 item_size) {
wapp_runtime_assert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL");
wpRuntimeAssert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL");
_array_validate(dst, item_size);
_array_validate(src, item_size);
@@ -91,7 +91,7 @@ void _array_extend_capped(GenericArray dst, const GenericArray src, u64 item_siz
}
void _array_copy_capped(GenericArray dst, const GenericArray src, u64 item_size) {
wapp_runtime_assert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL");
wpRuntimeAssert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL");
_array_validate(dst, item_size);
_array_validate(src, item_size);
@@ -106,7 +106,7 @@ void _array_copy_capped(GenericArray dst, const GenericArray src, u64 item_size)
GenericArray _array_append_alloc(const Allocator *allocator, GenericArray array, void *value,
ArrayInitFlags flags, u64 item_size) {
wapp_runtime_assert(allocator != NULL && array != NULL, "`allocator` and `array` should not be NULL");
wpRuntimeAssert(allocator != NULL && array != NULL, "`allocator` and `array` should not be NULL");
_array_validate(array, item_size);
GenericArray output = array;
@@ -135,7 +135,7 @@ RETURN_ARRAY_APPEND_ALLOC:
GenericArray _array_extend_alloc(const Allocator *allocator, GenericArray dst, const GenericArray src,
ArrayInitFlags flags, u64 item_size) {
wapp_runtime_assert(allocator != NULL && dst != NULL && src != NULL, "`allocator`, `dst` and `src` should not be NULL");
wpRuntimeAssert(allocator != NULL && dst != NULL && src != NULL, "`allocator`, `dst` and `src` should not be NULL");
_array_validate(dst, item_size);
_array_validate(src, item_size);
@@ -167,7 +167,7 @@ RETURN_ARRAY_EXTEND_ALLOC:
GenericArray _array_copy_alloc(const Allocator *allocator, GenericArray dst, const GenericArray src,
ArrayInitFlags flags, u64 item_size) {
wapp_runtime_assert(allocator != NULL && dst != NULL && src != NULL, "`allocator`, `dst` and `src` should not be NULL");
wpRuntimeAssert(allocator != NULL && dst != NULL && src != NULL, "`allocator`, `dst` and `src` should not be NULL");
_array_validate(dst, item_size);
_array_validate(src, item_size);
@@ -196,7 +196,7 @@ RETURN_ARRAY_COPY_ALLOC:
}
void *_array_pop(GenericArray array, u64 item_size) {
wapp_runtime_assert(array != NULL, "`array` should not be NULL");
wpRuntimeAssert(array != NULL, "`array` should not be NULL");
_array_validate(array, item_size);
ArrayHeader *header = _array_header(array);
@@ -209,7 +209,7 @@ void *_array_pop(GenericArray array, u64 item_size) {
}
void _array_clear(GenericArray array, u64 item_size) {
wapp_runtime_assert(array != NULL, "`array` should not be NULL");
wpRuntimeAssert(array != NULL, "`array` should not be NULL");
_array_validate(array, item_size);
ArrayHeader *header = _array_header(array);
@@ -222,7 +222,7 @@ u64 _array_calc_alloc_size(u64 capacity, u64 item_size) {
GenericArray _array_alloc_capacity(const Allocator *allocator, u64 capacity, ArrayInitFlags flags,
u64 item_size) {
wapp_runtime_assert(allocator != NULL, "`allocator` should not be NULL");
wpRuntimeAssert(allocator != NULL, "`allocator` should not be NULL");
GenericArray output = NULL;
@@ -241,7 +241,7 @@ RETURN_ARRAY_ALLOC:
GenericArray _array_from_preallocated_buffer(void *buffer, u64 buffer_size, ArrayInitFlags flags,
u64 item_size) {
wapp_runtime_assert(buffer != NULL, "`buffer` should not be NULL");
wpRuntimeAssert(buffer != NULL, "`buffer` should not be NULL");
i64 data_buffer_size = (i64)buffer_size - (i64)(sizeof(ArrayHeader));
if (data_buffer_size <= 0) {
@@ -261,6 +261,6 @@ GenericArray _array_from_preallocated_buffer(void *buffer, u64 buffer_size, Arra
wp_persist inline void _array_validate(const GenericArray array, u64 item_size) {
ArrayHeader *header = _array_header(array);
wapp_runtime_assert(WAPP_ARRAY_MAGIC == header->magic, "`array` is not a valid wapp array");
wapp_runtime_assert(item_size == header->item_size, "Invalid item type provided");
wpRuntimeAssert(WAPP_ARRAY_MAGIC == header->magic, "`array` is not a valid wapp array");
wpRuntimeAssert(item_size == header->item_size, "Invalid item type provided");
}
+16 -16
View File
@@ -12,7 +12,7 @@ wp_intern inline void _dbl_list_validate(const GenericList *list, u64 item_size)
wp_intern inline void _dbl_list_node_validate(const GenericList *list, const GenericNode *node, u64 item_size);
GenericList *_dbl_list_alloc(const Allocator *allocator, u64 item_size) {
wapp_debug_assert(allocator != NULL, "`allocator` should not be NULL");
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
GenericList *list = wapp_mem_allocator_alloc(allocator, sizeof(GenericList));
if (!list) { goto DBL_LIST_ALLOC_RETURN; }
@@ -26,7 +26,7 @@ DBL_LIST_ALLOC_RETURN:
}
GenericNode *_dbl_list_node_alloc(const Allocator *allocator, void *item, u64 item_size) {
wapp_debug_assert(allocator != NULL, "`allocator` should not be NULL");
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
GenericNode *node = wapp_mem_allocator_alloc(allocator, sizeof(GenericNode));
if (!node) { goto DBL_LIST_NODE_ALLOC_RETURN; }
@@ -41,9 +41,9 @@ DBL_LIST_NODE_ALLOC_RETURN:
}
GenericNode *_dbl_list_get(const GenericList *list, u64 index, u64 item_size) {
wapp_debug_assert(list != NULL, "`list` should not be NULL");
wpDebugAssert(list != NULL, "`list` should not be NULL");
_dbl_list_validate(list, item_size);
wapp_runtime_assert(index < list->node_count, "`index` is out of bounds");
wpRuntimeAssert(index < list->node_count, "`index` is out of bounds");
GenericNode *output = NULL;
GenericNode *current = list->first;
@@ -57,7 +57,7 @@ GenericNode *_dbl_list_get(const GenericList *list, u64 index, u64 item_size) {
}
void _dbl_list_push_front(GenericList *list, GenericNode *node, u64 item_size) {
wapp_debug_assert(list != NULL && node != NULL && (node->item) != NULL, "`list`, `node` and `node->item` should not be NULL");
wpDebugAssert(list != NULL && node != NULL && (node->item) != NULL, "`list`, `node` and `node->item` should not be NULL");
_dbl_list_validate(list, item_size);
_dbl_list_node_validate(list, node, item_size);
@@ -80,7 +80,7 @@ void _dbl_list_push_front(GenericList *list, GenericNode *node, u64 item_size) {
}
void _dbl_list_push_back(GenericList *list, GenericNode *node, u64 item_size) {
wapp_debug_assert(list != NULL && node != NULL && (node->item) != NULL, "`list`, `node` and `node->item` should not be NULL");
wpDebugAssert(list != NULL && node != NULL && (node->item) != NULL, "`list`, `node` and `node->item` should not be NULL");
_dbl_list_validate(list, item_size);
_dbl_list_node_validate(list, node, item_size);
@@ -103,7 +103,7 @@ void _dbl_list_push_back(GenericList *list, GenericNode *node, u64 item_size) {
}
void _dbl_list_insert(GenericList *list, GenericNode *node, u64 index, u64 item_size) {
wapp_debug_assert(list != NULL && node != NULL && (node->item) != NULL, "`list`, `node` and `node->item` should not be NULL");
wpDebugAssert(list != NULL && node != NULL && (node->item) != NULL, "`list`, `node` and `node->item` should not be NULL");
_dbl_list_validate(list, item_size);
_dbl_list_node_validate(list, node, item_size);
@@ -134,7 +134,7 @@ void _dbl_list_insert(GenericList *list, GenericNode *node, u64 index, u64 item_
}
GenericNode *_dbl_list_pop_front(GenericList *list, u64 item_size) {
wapp_debug_assert(list != NULL, "`list` should not be NULL");
wpDebugAssert(list != NULL, "`list` should not be NULL");
_dbl_list_validate(list, item_size);
GenericNode *output = NULL;
@@ -160,7 +160,7 @@ RETURN_LIST_POP_FRONT:
}
GenericNode *_dbl_list_pop_back(GenericList *list, u64 item_size) {
wapp_debug_assert(list != NULL, "`list` should not be NULL");
wpDebugAssert(list != NULL, "`list` should not be NULL");
_dbl_list_validate(list, item_size);
GenericNode *output = NULL;
@@ -186,7 +186,7 @@ RETURN_LIST_POP_BACK:
}
GenericNode *_dbl_list_remove(GenericList *list, u64 index, u64 item_size) {
wapp_debug_assert(list != NULL, "`list` should not be NULL");
wpDebugAssert(list != NULL, "`list` should not be NULL");
_dbl_list_validate(list, item_size);
GenericNode *output = NULL;
@@ -216,7 +216,7 @@ RETURN_LIST_REMOVE:
}
void _dbl_list_empty(GenericList *list, u64 item_size) {
wapp_debug_assert(list != NULL, "`list` should not be NULL");
wpDebugAssert(list != NULL, "`list` should not be NULL");
_dbl_list_validate(list, item_size);
u64 count = list->node_count;
@@ -248,12 +248,12 @@ wp_intern GenericList _node_to_list(GenericNode *node, u64 item_size) {
}
wp_intern inline void _dbl_list_validate(const GenericList *list, u64 item_size) {
wapp_runtime_assert(list->magic == WAPP_DBL_LIST_MAGIC, "`list` isn't a valid wapp list type");
wapp_runtime_assert(list->item_size == item_size, "Invalid item provided");
wpRuntimeAssert(list->magic == WAPP_DBL_LIST_MAGIC, "`list` isn't a valid wapp list type");
wpRuntimeAssert(list->item_size == item_size, "Invalid item provided");
}
wp_intern inline void _dbl_list_node_validate(const GenericList *list, const GenericNode *node, u64 item_size) {
wapp_runtime_assert(node->header.magic == WAPP_DBL_NODE_MAGIC, "`node` isn't a valid wapp node type");
wapp_runtime_assert(list->item_size == node->header.item_size, "Mismatched `list` and `node` types");
wapp_runtime_assert(node->header.item_size == item_size, "Invalid item provided");
wpRuntimeAssert(node->header.magic == WAPP_DBL_NODE_MAGIC, "`node` isn't a valid wapp 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");
}
+4 -4
View File
@@ -6,23 +6,23 @@
#include <stdlib.h>
void *wapp_mem_allocator_alloc(const Allocator *allocator, u64 size) {
wapp_debug_assert(allocator != NULL && (allocator->alloc) != NULL, "`allocator` and `allocator->alloc` should not be NULL");
wpDebugAssert(allocator != NULL && (allocator->alloc) != NULL, "`allocator` and `allocator->alloc` should not be NULL");
return allocator->alloc(size, allocator->obj);
}
void *wapp_mem_allocator_alloc_aligned(const Allocator *allocator, u64 size, u64 alignment) {
wapp_debug_assert(allocator != NULL && (allocator->alloc_aligned) != NULL, "`allocator` and `allocator->alloc_aligned` should not be NULL");
wpDebugAssert(allocator != NULL && (allocator->alloc_aligned) != NULL, "`allocator` and `allocator->alloc_aligned` should not be NULL");
return allocator->alloc_aligned(size, alignment, allocator->obj);
}
void *wapp_mem_allocator_realloc(const Allocator *allocator, void *ptr, u64 old_size, u64 new_size) {
wapp_debug_assert(allocator != NULL && (allocator->realloc) != NULL, "`allocator` and `allocator->realloc` should not be NULL");
wpDebugAssert(allocator != NULL && (allocator->realloc) != NULL, "`allocator` and `allocator->realloc` should not be NULL");
return allocator->realloc(ptr, old_size, new_size, allocator->obj);
}
void *wapp_mem_allocator_realloc_aligned(const Allocator *allocator, void *ptr, u64 old_size,
u64 new_size, u64 alignment) {
wapp_debug_assert(allocator != NULL && (allocator->realloc_aligned) != NULL, "`allocator` and `allocator->realloc_aligned` should not be NULL");
wpDebugAssert(allocator != NULL && (allocator->realloc_aligned) != NULL, "`allocator` and `allocator->realloc_aligned` should not be NULL");
return allocator->realloc_aligned(ptr, old_size, new_size, alignment, allocator->obj);
}
+2 -2
View File
@@ -7,8 +7,8 @@
#include <stddef.h>
void *wapp_mem_util_align_forward(void *ptr, u64 alignment) {
wapp_debug_assert(ptr != NULL, "`ptr` should not be NULL");
wapp_runtime_assert(wapp_is_power_of_two(alignment), "`alignment` value is not a power of two");
wpDebugAssert(ptr != NULL, "`ptr` should not be NULL");
wpRuntimeAssert(wapp_is_power_of_two(alignment), "`alignment` value is not a power of two");
uptr p = (uptr)ptr;
uptr align = (uptr)alignment;
+6 -6
View File
@@ -7,8 +7,8 @@
#include <string.h>
void _queue_push(GenericQueue *queue, void *item, u64 item_size) {
wapp_debug_assert(queue != NULL, "`queue` should not be NULL");
wapp_runtime_assert(item_size == wapp_array_item_size(queue->items), "Invalid type");
wpDebugAssert(queue != NULL, "`queue` should not be NULL");
wpRuntimeAssert(item_size == wapp_array_item_size(queue->items), "Invalid type");
u64 capacity = wapp_array_capacity(queue->items);
if (queue->count >= capacity) { return; }
@@ -23,9 +23,9 @@ void _queue_push(GenericQueue *queue, void *item, u64 item_size) {
}
GenericQueue *_queue_push_alloc(const Allocator *allocator, GenericQueue *queue, void *item, u64 item_size) {
wapp_debug_assert(allocator != NULL && queue != NULL && item != NULL,
wpDebugAssert(allocator != NULL && queue != NULL && item != NULL,
"`allocator`, `queue` and `item` should not be NULL");
wapp_runtime_assert(item_size == wapp_array_item_size(queue->items), "Invalid type");
wpRuntimeAssert(item_size == wapp_array_item_size(queue->items), "Invalid type");
GenericQueue *output = queue;
@@ -91,8 +91,8 @@ RETURN_QUEUE_PUSH_ALLOC:
}
void *_queue_pop(GenericQueue *queue, u64 item_size) {
wapp_debug_assert(queue != NULL, "`queue` should not be NULL");
wapp_runtime_assert(item_size == wapp_array_item_size(queue->items), "Invalid type");
wpDebugAssert(queue != NULL, "`queue` should not be NULL");
wpRuntimeAssert(item_size == wapp_array_item_size(queue->items), "Invalid type");
if (queue->count == 0) { return NULL; }
+20 -20
View File
@@ -14,7 +14,7 @@
#define STR8_BUF_ALLOC_SIZE(CAPACITY) (sizeof(Str8) + sizeof(c8) * CAPACITY)
Str8 *wapp_str8_alloc_buf(const Allocator *allocator, u64 capacity) {
wapp_debug_assert(allocator != NULL, "`allocator` should not be NULL");
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
Str8 *str = wapp_mem_allocator_alloc(allocator, STR8_BUF_ALLOC_SIZE(capacity));
if (!str) {
@@ -39,7 +39,7 @@ Str8 *wapp_str8_alloc_and_fill_buf(const Allocator *allocator, u64 capacity) {
}
Str8 *wapp_str8_alloc_cstr(const Allocator *allocator, const char *str) {
wapp_debug_assert(allocator != NULL && str != NULL, "`allocator` and `str` should not be NULL");
wpDebugAssert(allocator != NULL && str != NULL, "`allocator` and `str` should not be NULL");
u64 length = strlen(str);
Str8 *output = wapp_str8_alloc_buf(allocator, length * 2);
@@ -55,7 +55,7 @@ RETURN_ALLOC_CSTR:
}
Str8 *wapp_str8_alloc_str8(const Allocator *allocator, Str8RO *str) {
wapp_debug_assert(allocator != NULL && str != NULL, "`allocator` and `str` should not be NULL");
wpDebugAssert(allocator != NULL && str != NULL, "`allocator` and `str` should not be NULL");
Str8 *output = wapp_str8_alloc_buf(allocator, str->capacity);
if (!output) {
@@ -70,7 +70,7 @@ RETURN_ALLOC_STR8:
}
Str8 *wapp_str8_alloc_substr(const Allocator *allocator, Str8RO *str, u64 start, u64 end) {
wapp_debug_assert(allocator != NULL && str != NULL, "`allocator` and `str` should not be NULL");
wpDebugAssert(allocator != NULL && str != NULL, "`allocator` and `str` should not be NULL");
Str8 *output = NULL;
@@ -95,7 +95,7 @@ RETURN_ALLOC_SUBSTR:
}
void wapp_str8_dealloc_buf(const Allocator *allocator, Str8 **str) {
wapp_debug_assert(allocator != NULL && str != NULL && (*str) != NULL, "Either `allocator` is NULL or `str` is an invalid double pointer");
wpDebugAssert(allocator != NULL && str != NULL && (*str) != NULL, "Either `allocator` is NULL or `str` is an invalid double pointer");
wapp_mem_allocator_free(allocator, (void **)str, STR8_BUF_ALLOC_SIZE((*str)->capacity));
}
@@ -158,7 +158,7 @@ Str8 wapp_str8_slice(Str8RO *str, u64 start, u64 end) {
}
Str8 *wapp_str8_alloc_concat(const Allocator *allocator, Str8 *dst, Str8RO *src) {
wapp_debug_assert(allocator != NULL && dst != NULL && src != NULL, "`allocator`, `dst` and `src` should not be NULL");
wpDebugAssert(allocator != NULL && dst != NULL && src != NULL, "`allocator`, `dst` and `src` should not be NULL");
Str8 *output = NULL;
u64 remaining = dst->capacity - dst->size;
@@ -184,7 +184,7 @@ RETURN_STR8_CONCAT:
}
void wapp_str8_concat_capped(Str8 *dst, Str8RO *src) {
wapp_debug_assert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL");
wpDebugAssert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL");
u64 remaining = dst->capacity - dst->size;
u64 to_copy = remaining < src->size ? remaining : src->size;
@@ -194,7 +194,7 @@ void wapp_str8_concat_capped(Str8 *dst, Str8RO *src) {
}
void wapp_str8_copy_cstr_capped(Str8 *dst, const char *src) {
wapp_debug_assert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL");
wpDebugAssert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL");
u64 length = strlen(src);
u64 to_copy = length <= dst->capacity ? length : dst->capacity;
@@ -205,7 +205,7 @@ void wapp_str8_copy_cstr_capped(Str8 *dst, const char *src) {
}
void wapp_str8_copy_str8_capped(Str8 *dst, Str8RO *src) {
wapp_debug_assert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL");
wpDebugAssert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL");
u64 to_copy = src->size <= dst->capacity ? src->size : dst->capacity;
@@ -215,7 +215,7 @@ void wapp_str8_copy_str8_capped(Str8 *dst, Str8RO *src) {
}
void wapp_str8_copy_to_cstr(char *dst, Str8RO *src, u64 dst_capacity) {
wapp_debug_assert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL");
wpDebugAssert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL");
u64 to_copy = src->size < dst_capacity ? src->size : dst_capacity - 1;
@@ -224,7 +224,7 @@ void wapp_str8_copy_to_cstr(char *dst, Str8RO *src, u64 dst_capacity) {
}
void wapp_str8_format(Str8 *dst, const char *format, ...) {
wapp_debug_assert(dst != NULL && format != NULL, "`dst` and `format` should not be NULL");
wpDebugAssert(dst != NULL && format != NULL, "`dst` and `format` should not be NULL");
va_list args1;
va_list args2;
@@ -242,8 +242,8 @@ void wapp_str8_format(Str8 *dst, const char *format, ...) {
}
void wapp_str8_to_lower(Str8 *dst, Str8RO *src) {
wapp_debug_assert(src != NULL && dst != NULL, "`dst` and `src` should not be NULL");
wapp_debug_assert(dst->capacity >= src->capacity, "`dst` does not have enough capacity");
wpDebugAssert(src != NULL && dst != NULL, "`dst` and `src` should not be NULL");
wpDebugAssert(dst->capacity >= src->capacity, "`dst` does not have enough capacity");
dst->size = src->size;
@@ -259,8 +259,8 @@ void wapp_str8_to_lower(Str8 *dst, Str8RO *src) {
}
void wapp_str8_to_upper(Str8 *dst, Str8RO *src) {
wapp_debug_assert(src != NULL && dst != NULL, "`dst` and `src` should not be NULL");
wapp_debug_assert(dst->capacity >= src->capacity, "`dst` does not have enough capacity");
wpDebugAssert(src != NULL && dst != NULL, "`dst` and `src` should not be NULL");
wpDebugAssert(dst->capacity >= src->capacity, "`dst` does not have enough capacity");
dst->size = src->size;
@@ -276,11 +276,11 @@ void wapp_str8_to_upper(Str8 *dst, Str8RO *src) {
}
void wapp_str8_from_bytes(Str8 *dst, const U8Array src) {
wapp_debug_assert(src != NULL && dst != NULL, "`dst` and `src` should not be NULL");
wpDebugAssert(src != NULL && dst != NULL, "`dst` and `src` should not be NULL");
u64 size = wapp_array_count(src) * wapp_array_item_size(src);
wapp_debug_assert(dst->capacity >= size, "`dst` does not have enough capacity");
wpDebugAssert(dst->capacity >= size, "`dst` does not have enough capacity");
dst->size = size;
memcpy(dst->buf, src, size);
@@ -331,7 +331,7 @@ i64 wapp_str8_rfind(Str8RO *str, Str8RO substr) {
}
Str8List *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits) {
wapp_debug_assert(allocator != NULL && str != NULL && delimiter != NULL, "`allocator`, `str` and `delimiter` should not be NULL");
wpDebugAssert(allocator != NULL && str != NULL && delimiter != NULL, "`allocator`, `str` and `delimiter` should not be NULL");
Str8List *output = wapp_dbl_list_alloc(Str8, allocator);
@@ -378,7 +378,7 @@ RETURN_STR8_SPLIT:
}
Str8List *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits) {
wapp_debug_assert(allocator != NULL && str != NULL && delimiter != NULL, "`allocator`, `str` and `delimiter` should not be NULL");
wpDebugAssert(allocator != NULL && str != NULL && delimiter != NULL, "`allocator`, `str` and `delimiter` should not be NULL");
Str8List *output = wapp_dbl_list_alloc(Str8, allocator);
@@ -422,7 +422,7 @@ RETURN_STR8_SPLIT:
}
Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8RO *delimiter) {
wapp_debug_assert(allocator != NULL && list != NULL && delimiter != NULL, "`allocator`, `list` and `delimiter` should not be NULL");
wpDebugAssert(allocator != NULL && list != NULL && delimiter != NULL, "`allocator`, `list` and `delimiter` should not be NULL");
u64 capacity = wapp_str8_list_total_size(list) + (delimiter->size * (list->node_count - 1));
Str8 *output = wapp_str8_alloc_buf(allocator, capacity * 2);
+12 -12
View File
@@ -13,38 +13,38 @@
BEGIN_C_LINKAGE
#endif // !WP_PLATFORM_CPP
#define wapp_static_assert(EXPR, MSG) wp_extern char ASSERTION_FAILED[EXPR ? 1 : -1]
#define wpStaticAssert(EXPR, MSG) wp_extern char ASSERTION_FAILED[EXPR ? 1 : -1]
#ifndef WAPP_NO_RUNTIME_ASSERT
#define wapp_runtime_assert(EXPR, MSG) __wapp_runtime_assert(EXPR, MSG)
#ifndef WP_NO_RUNTIME_ASSERT
#define wpRuntimeAssert(EXPR, MSG) _runtimeAssert(EXPR, MSG)
#else
#define wapp_runtime_assert(EXPR, MSG)
#define wpRuntimeAssert(EXPR, MSG)
#endif
#ifdef WAPP_DEBUG_ASSERT
#define wapp_debug_assert(EXPR, MSG) wapp_runtime_assert(EXPR, MSG)
#ifdef WP_DEBUG_ASSERT
#define wpDebugAssert(EXPR, MSG) wpRuntimeAssert(EXPR, MSG)
#else
#define wapp_debug_assert(EXPR, MSG)
#define wpDebugAssert(EXPR, MSG)
#endif
#ifdef WP_PLATFORM_WINDOWS
#define __wapp_runtime_assert(EXPR, MSG) do { \
#define _runtimeAssert(EXPR, MSG) do { \
__pragma(warning(push)) \
__pragma(warning(disable:4127)) \
if (!(EXPR)) { \
__pragma(warning(pop)) \
__runtime_assert_failed(EXPR, MSG); \
_runtimeAssertFailed(EXPR, MSG); \
} \
} while(false)
#else
#define __wapp_runtime_assert(EXPR, MSG) do { \
#define _runtimeAssert(EXPR, MSG) do { \
if (!(EXPR)) { \
__runtime_assert_failed(EXPR, MSG); \
_runtimeAssertFailed(EXPR, MSG); \
} \
} while(false)
#endif // !WP_PLATFORM_WINDOWS
#define __runtime_assert_failed(EXPR, MSG) do { \
#define _runtimeAssertFailed(EXPR, MSG) do { \
fprintf( \
stderr, \
"%s:%d (In function `%s`): Assertion failed (%" PRIu32 ")\nDiagnostic: %s\n\n", \
+6 -6
View File
@@ -53,7 +53,7 @@ Logger wapp_log_make_logger(Str8 name) {
}
void wapp_log_debug(const Logger *logger, Str8 msg) {
wapp_debug_assert(logger != NULL, "`logger` should not be NULL");
wpDebugAssert(logger != NULL, "`logger` should not be NULL");
if (LOG_CONFIG.level < WAPP_LOG_DEBUG) { return; }
WFile *fp = LOG_CONFIG.outlog != NULL ? LOG_CONFIG.outlog : wapp_file_stdout();
@@ -61,7 +61,7 @@ void wapp_log_debug(const Logger *logger, Str8 msg) {
}
void wapp_log_info(const Logger *logger, Str8 msg) {
wapp_debug_assert(logger != NULL, "`logger` should not be NULL");
wpDebugAssert(logger != NULL, "`logger` should not be NULL");
if (LOG_CONFIG.level < WAPP_LOG_INFO) { return; }
WFile *fp = LOG_CONFIG.outlog != NULL ? LOG_CONFIG.outlog : wapp_file_stdout();
@@ -69,7 +69,7 @@ void wapp_log_info(const Logger *logger, Str8 msg) {
}
void wapp_log_warning(const Logger *logger, Str8 msg) {
wapp_debug_assert(logger != NULL, "`logger` should not be NULL");
wpDebugAssert(logger != NULL, "`logger` should not be NULL");
if (LOG_CONFIG.level < WAPP_LOG_WARNING) { return; }
WFile *fp = LOG_CONFIG.outlog != NULL ? LOG_CONFIG.outlog : wapp_file_stdout();
@@ -77,7 +77,7 @@ void wapp_log_warning(const Logger *logger, Str8 msg) {
}
void wapp_log_error(const Logger *logger, Str8 msg) {
wapp_debug_assert(logger != NULL, "`logger` should not be NULL");
wpDebugAssert(logger != NULL, "`logger` should not be NULL");
if (LOG_CONFIG.level < WAPP_LOG_ERROR) { return; }
WFile *fp = LOG_CONFIG.errlog != NULL ? LOG_CONFIG.errlog : wapp_file_stderr();
@@ -85,7 +85,7 @@ void wapp_log_error(const Logger *logger, Str8 msg) {
}
void wapp_log_critical(const Logger *logger, Str8 msg) {
wapp_debug_assert(logger != NULL, "`logger` should not be NULL");
wpDebugAssert(logger != NULL, "`logger` should not be NULL");
if (LOG_CONFIG.level < WAPP_LOG_CRITICAL) { return; }
WFile *fp = LOG_CONFIG.errlog != NULL ? LOG_CONFIG.errlog : wapp_file_stderr();
@@ -93,7 +93,7 @@ void wapp_log_critical(const Logger *logger, Str8 msg) {
}
void wapp_log_fatal(const Logger *logger, Str8 msg) {
wapp_debug_assert(logger != NULL, "`logger` should not be NULL");
wpDebugAssert(logger != NULL, "`logger` should not be NULL");
if (LOG_CONFIG.level < WAPP_LOG_FATAL) { return; }
WFile *fp = LOG_CONFIG.errlog != NULL ? LOG_CONFIG.errlog : wapp_file_stderr();
+7 -7
View File
@@ -89,7 +89,7 @@ void *wapp_mem_arena_alloc(Arena *arena, u64 size) {
}
void *wapp_mem_arena_alloc_aligned(Arena *arena, u64 size, u64 alignment) {
wapp_debug_assert(arena != NULL, "`arena` should not be NULL");
wpDebugAssert(arena != NULL, "`arena` should not be NULL");
u8 *alloc_start = arena->offset;
@@ -114,7 +114,7 @@ void *wapp_mem_arena_alloc_aligned(Arena *arena, u64 size, u64 alignment) {
}
void *wapp_mem_arena_realloc(Arena *arena, void *ptr, u64 old_size, u64 new_size) {
wapp_debug_assert(arena != NULL, "`arena` should not be NULL");
wpDebugAssert(arena != NULL, "`arena` should not be NULL");
if ((u8*)ptr < arena->buf || (u8*)ptr > arena->offset ||
arena->offset + new_size >= arena->buf + arena->capacity) {
@@ -133,7 +133,7 @@ void *wapp_mem_arena_realloc(Arena *arena, void *ptr, u64 old_size, u64 new_size
}
void *wapp_mem_arena_realloc_aligned(Arena *arena, void *ptr, u64 old_size, u64 new_size, u64 alignment) {
wapp_debug_assert(arena != NULL, "`arena` should not be NULL");
wpDebugAssert(arena != NULL, "`arena` should not be NULL");
if ((u8*)ptr < arena->buf || (u8*)ptr > arena->offset ||
arena->offset + new_size >= arena->buf + arena->capacity) {
@@ -152,7 +152,7 @@ void *wapp_mem_arena_realloc_aligned(Arena *arena, void *ptr, u64 old_size, u64
}
void wapp_mem_arena_temp_begin(Arena *arena) {
wapp_debug_assert(arena != NULL, "`arena` should not be NULL");
wpDebugAssert(arena != NULL, "`arena` should not be NULL");
if (arena->prev_offset != NULL) {
return;
@@ -162,7 +162,7 @@ void wapp_mem_arena_temp_begin(Arena *arena) {
}
void wapp_mem_arena_temp_end(Arena *arena) {
wapp_debug_assert(arena != NULL, "`arena` should not be NULL");
wpDebugAssert(arena != NULL, "`arena` should not be NULL");
if (arena->prev_offset == NULL) {
return;
@@ -173,14 +173,14 @@ void wapp_mem_arena_temp_end(Arena *arena) {
}
void wapp_mem_arena_clear(Arena *arena) {
wapp_debug_assert(arena != NULL, "`arena` should not be NULL");
wpDebugAssert(arena != NULL, "`arena` should not be NULL");
memset(arena->buf, 0, arena->offset - arena->buf);
arena->offset = arena->buf;
}
void wapp_mem_arena_destroy(Arena **arena) {
wapp_debug_assert(arena != NULL && (*arena) != NULL, "`arena` double pointer is not valid");
wpDebugAssert(arena != NULL && (*arena) != NULL, "`arena` double pointer is not valid");
Arena *arena_ptr = *arena;
@@ -38,22 +38,22 @@ Allocator wapp_mem_arena_allocator_init_custom(u64 base_capacity, MemAllocFlags
}
void wapp_mem_arena_allocator_temp_begin(const Allocator *allocator) {
wapp_debug_assert(allocator != NULL, "`allocator` should not be NULL");
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
wapp_mem_arena_temp_begin((Arena *)(allocator->obj));
}
void wapp_mem_arena_allocator_temp_end(const Allocator *allocator) {
wapp_debug_assert(allocator != NULL, "`allocator` should not be NULL");
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
wapp_mem_arena_temp_end((Arena *)(allocator->obj));
}
void wapp_mem_arena_allocator_clear(Allocator *allocator) {
wapp_debug_assert(allocator != NULL, "`allocator` should not be NULL");
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
wapp_mem_arena_clear((Arena *)(allocator->obj));
}
void wapp_mem_arena_allocator_destroy(Allocator *allocator) {
wapp_debug_assert(allocator != NULL, "`allocator` should not be NULL");
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
wapp_mem_arena_destroy((Arena **)(&(allocator->obj)));
*allocator = (Allocator){0};
}
+18 -18
View File
@@ -8,23 +8,23 @@
#include "../../base/strings/str8/str8.h"
WFile *wapp_file_open(const Allocator *allocator, Str8RO *filepath, FileAccessMode mode) {
wapp_debug_assert(allocator != NULL && filepath != NULL, "`allocator` and `filepath` should not be NULL");
wapp_debug_assert(filepath->size < WAPP_PATH_MAX, "`filepath` exceeds max path limit.");
wpDebugAssert(allocator != NULL && filepath != NULL, "`allocator` and `filepath` should not be NULL");
wpDebugAssert(filepath->size < WAPP_PATH_MAX, "`filepath` exceeds max path limit.");
return _file_open(allocator, filepath, mode);
}
i64 wapp_file_get_current_position(WFile *file) {
wapp_debug_assert(file != NULL, "`file` should not be NULL.");
wpDebugAssert(file != NULL, "`file` should not be NULL.");
return _file_seek(file, 0, WAPP_SEEK_CURRENT);
}
i64 wapp_file_seek(WFile *file, i64 offset, FileSeekOrigin origin) {
wapp_debug_assert(file != NULL, "`file` should not be NULL.");
wpDebugAssert(file != NULL, "`file` should not be NULL.");
return _file_seek(file, offset, origin);
}
i64 wapp_file_get_length(WFile *file) {
wapp_debug_assert(file != NULL, "`file` should not be NULL.");
wpDebugAssert(file != NULL, "`file` should not be NULL.");
i64 current = wapp_file_get_current_position(file);
@@ -39,7 +39,7 @@ i64 wapp_file_get_length(WFile *file) {
}
u64 wapp_file_read(void *dst_buf, WFile *file, u64 byte_count) {
wapp_debug_assert(dst_buf != NULL && file != NULL,
wpDebugAssert(dst_buf != NULL && file != NULL,
"`dst_buf` and `file` should not be NULL.");
i64 file_length = wapp_file_get_length(file);
@@ -51,23 +51,23 @@ u64 wapp_file_read(void *dst_buf, WFile *file, u64 byte_count) {
}
i64 wapp_file_write(const void *src_buf, WFile *file, u64 byte_count) {
wapp_debug_assert(src_buf != NULL && file != NULL,
wpDebugAssert(src_buf != NULL && file != NULL,
"`src_buf` and `file` should not be NULL.");
return _file_write(src_buf, file, byte_count);
}
u64 wapp_file_read_str8(Str8 *str, WFile *file) {
wapp_debug_assert(str != NULL, "`str` should not be NULL.");
wpDebugAssert(str != NULL, "`str` should not be NULL.");
return wapp_file_read((void *)(str->buf), file, str->size);
}
i64 wapp_file_write_str8(Str8RO *str, WFile *file) {
wapp_debug_assert(str != NULL, "`str` should not be NULL.");
wpDebugAssert(str != NULL, "`str` should not be NULL.");
return wapp_file_write((void *)(str->buf), file, str->size);
}
u64 wapp_file_read_array(GenericArray dst_buf, WFile *file, u64 item_count) {
wapp_debug_assert(dst_buf != NULL && file != NULL,
wpDebugAssert(dst_buf != NULL && file != NULL,
"`dst_buf` and `file` should not be NULL.");
i64 _file_length = wapp_file_get_length(file);
@@ -98,7 +98,7 @@ u64 wapp_file_read_array(GenericArray dst_buf, WFile *file, u64 item_count) {
}
i64 wapp_file_write_array(const GenericArray src_buf, WFile *file, u64 item_count) {
wapp_debug_assert(src_buf != NULL && file != NULL,
wpDebugAssert(src_buf != NULL && file != NULL,
"`src_buf` and `file` should not be NULL.");
u64 item_size = wapp_array_item_size(src_buf);
@@ -115,25 +115,25 @@ i64 wapp_file_write_array(const GenericArray src_buf, WFile *file, u64 item_coun
}
i32 wapp_file_flush(WFile *file) {
wapp_debug_assert(file != NULL, "`file` should not be NULL.");
wpDebugAssert(file != NULL, "`file` should not be NULL.");
return _file_flush(file);
}
i32 wapp_file_close(WFile *file) {
wapp_debug_assert(file != NULL, "`file` should not be NULL.");
wpDebugAssert(file != NULL, "`file` should not be NULL.");
return _file_close(file);
}
i32 wapp_file_rename(Str8RO *old_filepath, Str8RO *new_filepath) {
wapp_debug_assert(old_filepath != NULL && new_filepath != NULL,
wpDebugAssert(old_filepath != NULL && new_filepath != NULL,
"`old_filepath` and `new_filepath` should not be NULL");
wapp_debug_assert(old_filepath->size < WAPP_PATH_MAX, "`old_filepath` exceeds max path limit.");
wapp_debug_assert(new_filepath->size < WAPP_PATH_MAX, "`new_filepath` exceeds max path limit.");
wpDebugAssert(old_filepath->size < WAPP_PATH_MAX, "`old_filepath` exceeds max path limit.");
wpDebugAssert(new_filepath->size < WAPP_PATH_MAX, "`new_filepath` exceeds max path limit.");
return _file_rename(old_filepath, new_filepath);
}
i32 wapp_file_remove(Str8RO *filepath) {
wapp_debug_assert(filepath != NULL, "`filepath` should not be NULL");
wapp_debug_assert(filepath->size < WAPP_PATH_MAX, "`filepath` exceeds max path limit.");
wpDebugAssert(filepath != NULL, "`filepath` should not be NULL");
wpDebugAssert(filepath->size < WAPP_PATH_MAX, "`filepath` exceeds max path limit.");
return _file_remove(filepath);
}
+2 -2
View File
@@ -111,7 +111,7 @@ i64 _file_seek(WFile *file, i64 offset, FileSeekOrigin origin) {
u64 _file_read(void* dst_buf, u64 byte_count, WFile* file, u64 file_length) {
u64 copy_byte_count = file_length <= byte_count ? file_length : byte_count;
wapp_debug_assert(copy_byte_count <= DWORD_MAX, "Attempting to read large number of bytes at once");
wpDebugAssert(copy_byte_count <= DWORD_MAX, "Attempting to read large number of bytes at once");
DWORD read_count = 0;
if (!ReadFile(file->fh, dst_buf, (DWORD)copy_byte_count, &read_count, NULL)) {
@@ -122,7 +122,7 @@ u64 _file_read(void* dst_buf, u64 byte_count, WFile* file, u64 file_length) {
}
i64 _file_write(const void *src_buf, WFile *file, u64 byte_count) {
wapp_debug_assert(byte_count <= DWORD_MAX, "Attempting to write large number of bytes at once");
wpDebugAssert(byte_count <= DWORD_MAX, "Attempting to write large number of bytes at once");
DWORD write_count = 0;
if (!WriteFile(file->fh, src_buf, (DWORD)byte_count, &write_count, NULL)) {
+3 -3
View File
@@ -94,7 +94,7 @@ wp_intern u64 split_mix_64(SplitMix64State *state) {
wp_intern void seed_os_generator(void) {
struct timespec ts = {0};
int result = clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
wapp_runtime_assert(result == 0, "Invalid seed value");
wpRuntimeAssert(result == 0, "Invalid seed value");
srand48(ts.tv_nsec);
}
@@ -106,7 +106,7 @@ wp_intern u64 generate_random_number(void) {
wp_intern void seed_os_generator(void) {
struct timespec ts = {0};
int result = timespec_get(&ts, TIME_UTC);
wapp_runtime_assert(result != 0, "Invalid seed value");
wpRuntimeAssert(result != 0, "Invalid seed value");
srand(ts.tv_nsec);
}
@@ -121,7 +121,7 @@ wp_intern u64 generate_random_number(void) {
#else
wp_intern void seed_os_generator(void) {
time_t result = time(NULL);
wapp_runtime_assert(result != (time_t)(-1), "Invalid seed value");
wpRuntimeAssert(result != (time_t)(-1), "Invalid seed value");
srand(result);
}
+1 -1
View File
@@ -19,7 +19,7 @@ wp_intern UUID4 generate_uuid4(void);
wp_intern void uuid4_to_uuid(const UUID4* uuid4, WUUID *uuid);
WUUID *wapp_uuid_init_uuid4(WUUID *uuid) {
wapp_debug_assert(uuid != NULL, "`uuid` should not be NULL");
wpDebugAssert(uuid != NULL, "`uuid` should not be NULL");
UUID4 uuid4 = generate_uuid4();
uuid4_to_uuid(&uuid4, uuid);