From 175f627f93fcfaec767f88e3653e9a56c815fca4 Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Mon, 5 May 2025 19:29:44 +0100 Subject: [PATCH] Remove text from asserts --- src/core/mem/arena/mem_arena.c | 6 ++--- src/core/mem/utils/mem_utils.c | 4 +-- src/primitives/mem_allocator/mem_allocator.c | 8 +++--- src/primitives/strings/str8/str8.c | 28 ++++++++++---------- src/prng/xorshift/xorshift.c | 6 ++--- src/uuid/uuid.c | 2 +- src/uuid/uuid.h | 2 +- src/uuid/wapp_uuid.c | 2 +- src/uuid/wapp_uuid.h | 2 +- 9 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/core/mem/arena/mem_arena.c b/src/core/mem/arena/mem_arena.c index 6313432..5e15981 100644 --- a/src/core/mem/arena/mem_arena.c +++ b/src/core/mem/arena/mem_arena.c @@ -64,7 +64,7 @@ void *wapp_mem_arena_alloc(Arena *arena, u64 size) { } void *wapp_mem_arena_alloc_aligned(Arena *arena, u64 size, u64 alignment) { - assert(arena != NULL && "arena argument shouldn't be NULL"); + assert(arena != NULL); u8 *alloc_start = arena->offset; @@ -123,14 +123,14 @@ void *wapp_mem_arena_realloc_aligned(Arena *arena, void *ptr, u64 old_size, u64 } void wapp_mem_arena_clear(Arena *arena) { - assert(arena != NULL && "arena argument shouldn't be NULL"); + assert(arena != NULL); memset(arena->buf, 0, arena->offset - arena->buf); arena->offset = arena->buf; } void wapp_mem_arena_destroy(Arena **arena) { - assert(arena != NULL && (*arena) != NULL && "arena argument shouldn't be NULL"); + assert(arena != NULL && (*arena) != NULL); Arena *arena_ptr = *arena; if (arena_ptr->buf) { diff --git a/src/core/mem/utils/mem_utils.c b/src/core/mem/utils/mem_utils.c index 40ebac3..c95f50f 100644 --- a/src/core/mem/utils/mem_utils.c +++ b/src/core/mem/utils/mem_utils.c @@ -7,8 +7,8 @@ internal bool is_power_of_two(u64 num) { return (num & (num - 1)) == 0; } void *wapp_mem_util_align_forward(void *ptr, u64 alignment) { - assert(ptr != NULL && "ptr argument shouldn't be NULL"); - assert(is_power_of_two(alignment) && "Alignment isn't a power of 2"); + assert(ptr != NULL); + assert(is_power_of_two(alignment)); uptr p = (uptr)ptr; uptr align = (uptr)alignment; diff --git a/src/primitives/mem_allocator/mem_allocator.c b/src/primitives/mem_allocator/mem_allocator.c index 762a07b..6d195d0 100644 --- a/src/primitives/mem_allocator/mem_allocator.c +++ b/src/primitives/mem_allocator/mem_allocator.c @@ -4,23 +4,23 @@ #include void *wapp_mem_allocator_alloc(const Allocator *allocator, u64 size) { - assert(allocator != NULL && (allocator->alloc) != NULL && "allocator argument shouldn't be NULL"); + assert(allocator != NULL && (allocator->alloc) != NULL); return allocator->alloc(size, allocator->obj); } void *wapp_mem_allocator_alloc_aligned(const Allocator *allocator, u64 size, u64 alignment) { - assert(allocator != NULL && (allocator->alloc_aligned) != NULL && "allocator argument shouldn't be NULL"); + assert(allocator != NULL && (allocator->alloc_aligned) != 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) { - assert(allocator != NULL && (allocator->realloc) != NULL && "allocator argument shouldn't be NULL"); + assert(allocator != NULL && (allocator->realloc) != 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) { - assert(allocator != NULL && (allocator->realloc_aligned) != NULL && "allocator argument shouldn't be NULL"); + assert(allocator != NULL && (allocator->realloc_aligned) != NULL); return allocator->realloc_aligned(ptr, old_size, new_size, alignment, allocator->obj); } diff --git a/src/primitives/strings/str8/str8.c b/src/primitives/strings/str8/str8.c index f940cd4..e5216f3 100644 --- a/src/primitives/strings/str8/str8.c +++ b/src/primitives/strings/str8/str8.c @@ -11,7 +11,7 @@ #define STR8_BUF_ALLOC_SIZE(CAPACITY) (sizeof(Str8) + sizeof(c8) * CAPACITY) Str8 *wapp_str8_alloc_buf(const Allocator *allocator, u64 capacity) { - assert(allocator != NULL && "allocator argument shouldn't be NULL"); + assert(allocator != NULL); Str8 *str = wapp_mem_allocator_alloc(allocator, STR8_BUF_ALLOC_SIZE(capacity)); if (!str) { @@ -27,7 +27,7 @@ RETURN_STR8: } Str8 *wapp_str8_alloc_cstr(const Allocator *allocator, const char *str) { - assert(allocator != NULL && str != NULL && "Arguments passed shouldn't be NULL"); + assert(allocator != NULL && str != NULL); u64 length = strlen(str); Str8 *output = wapp_str8_alloc_buf(allocator, length * 2); @@ -43,7 +43,7 @@ RETURN_ALLOC_CSTR: } Str8 *wapp_str8_alloc_str8(const Allocator *allocator, Str8RO *str) { - assert(allocator != NULL && str != NULL && "Arguments passed shouldn't be NULL"); + assert(allocator != NULL && str != NULL); Str8 *output = wapp_str8_alloc_buf(allocator, str->capacity); if (!output) { @@ -58,7 +58,7 @@ RETURN_ALLOC_STR8: } Str8 *wapp_str8_alloc_substr(const Allocator *allocator, Str8RO *str, u64 start, u64 end) { - assert(allocator != NULL && str != NULL && "Arguments passed shouldn't be NULL"); + assert(allocator != NULL && str != NULL); Str8 *output = NULL; @@ -83,7 +83,7 @@ RETURN_ALLOC_SUBSTR: } void wapp_str8_dealloc_buf(const Allocator *allocator, Str8 **str) { - assert(allocator != NULL && str != NULL && (*str) != NULL && "Arguments passed shouldn't be NULL"); + assert(allocator != NULL && str != NULL && (*str) != NULL); wapp_mem_allocator_free(allocator, (void **)str, STR8_BUF_ALLOC_SIZE((*str)->capacity)); } @@ -146,7 +146,7 @@ Str8 wapp_str8_slice(Str8RO *str, u64 start, u64 end) { } Str8 *wapp_str8_alloc_concat(const Allocator *allocator, Str8 *dst, Str8RO *src) { - assert(allocator != NULL && dst != NULL && src != NULL && "Arguments passed shouldn't be NULL"); + assert(allocator != NULL && dst != NULL && src != NULL); Str8 *output = NULL; u64 remaining = dst->capacity - dst->size; @@ -172,7 +172,7 @@ RETURN_STR8_CONCAT: } void wapp_str8_concat_capped(Str8 *dst, Str8RO *src) { - assert(dst != NULL && src != NULL && "Arguments passed shouldn't be NULL"); + assert(dst != NULL && src != NULL); u64 remaining = dst->capacity - dst->size; u64 to_copy = remaining < src->size ? remaining : src->size; @@ -182,7 +182,7 @@ void wapp_str8_concat_capped(Str8 *dst, Str8RO *src) { } void wapp_str8_copy_cstr_capped(Str8 *dst, const char *src) { - assert(dst != NULL && src != NULL && "Arguments passed shouldn't be NULL"); + assert(dst != NULL && src != NULL); u64 length = strlen(src); u64 to_copy = length <= dst->capacity ? length : dst->capacity; @@ -193,7 +193,7 @@ void wapp_str8_copy_cstr_capped(Str8 *dst, const char *src) { } void wapp_str8_copy_str8_capped(Str8 *dst, Str8RO *src) { - assert(dst != NULL && src != NULL && "Arguments passed shouldn't be NULL"); + assert(dst != NULL && src != NULL); u64 to_copy = src->size <= dst->capacity ? src->size : dst->capacity; @@ -203,7 +203,7 @@ void wapp_str8_copy_str8_capped(Str8 *dst, Str8RO *src) { } void wapp_str8_copy_to_cstr(char *dst, Str8RO *src, u64 dst_capacity) { - assert(dst != NULL && src != NULL && "Arguments passed shouldn't be NULL"); + assert(dst != NULL && src != NULL); u64 to_copy = src->size < dst_capacity ? src->size : dst_capacity - 1; @@ -212,7 +212,7 @@ void wapp_str8_copy_to_cstr(char *dst, Str8RO *src, u64 dst_capacity) { } void wapp_str8_format(Str8 *dst, const char *format, ...) { - assert(dst != NULL && format != NULL && "Arguments passed shouldn't be NULL"); + assert(dst != NULL && format != NULL); va_list args1; va_list args2; @@ -274,7 +274,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) { - assert(allocator != NULL && str != NULL && delimiter != NULL && "Arguments passed shouldn't be NULL"); + assert(allocator != NULL && str != NULL && delimiter != NULL); Str8List *output = wapp_mem_allocator_alloc(allocator, sizeof(Str8List)); @@ -327,7 +327,7 @@ RETURN_STR8_SPLIT: } Str8List *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits) { - assert(allocator != NULL && str != NULL && delimiter != NULL && "Arguments passed shouldn't be NULL"); + assert(allocator != NULL && str != NULL && delimiter != NULL); Str8List *output = wapp_mem_allocator_alloc(allocator, sizeof(Str8List)); @@ -377,7 +377,7 @@ RETURN_STR8_SPLIT: } Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8RO *delimiter) { - assert(allocator != NULL && list != NULL && delimiter != NULL && "Arguments passed shouldn't be NULL"); + assert(allocator != NULL && list != NULL && delimiter != NULL); u64 capacity = wapp_str8_list_total_size(list) + (delimiter->size * (list->node_count - 1)); Str8 *output = wapp_str8_alloc_buf(allocator, capacity * 2); diff --git a/src/prng/xorshift/xorshift.c b/src/prng/xorshift/xorshift.c index 38c4eaf..8574dd7 100644 --- a/src/prng/xorshift/xorshift.c +++ b/src/prng/xorshift/xorshift.c @@ -93,7 +93,7 @@ internal u64 split_mix_64(SplitMix64State *state) { internal void seed_os_generator(void) { struct timespec ts = {0}; int result = clock_gettime(CLOCK_MONOTONIC_RAW, &ts); - assert(result == 0 && "Failed to get time"); + assert(result == 0); srand48(ts.tv_nsec); } @@ -105,7 +105,7 @@ internal u64 generate_random_number(void) { internal void seed_os_generator(void) { struct timespec ts = {0}; int result = timespec_get(&ts, TIME_UTC); - assert(result != 0 && "Failed to get time"); + assert(result != 0); srand(ts.tv_nsec); } @@ -120,7 +120,7 @@ internal u64 generate_random_number(void) { #else internal void seed_os_generator(void) { time_t result = time(NULL); - assert(result != (time_t)(-1) && "Failed to get time"); + assert(result != (time_t)(-1)); srand(result); } diff --git a/src/uuid/uuid.c b/src/uuid/uuid.c index 0752024..781c0e6 100644 --- a/src/uuid/uuid.c +++ b/src/uuid/uuid.c @@ -18,7 +18,7 @@ internal UUID4 generate_uuid4(void); internal void uuid4_to_uuid(const UUID4* uuid4, UUID *uuid); UUID *wapp_uuid_init_uuid4(UUID *uuid) { - assert(uuid != NULL && "uuid argument shouldn't be NULL"); + assert(uuid != NULL); UUID4 uuid4 = generate_uuid4(); uuid4_to_uuid(&uuid4, uuid); diff --git a/src/uuid/uuid.h b/src/uuid/uuid.h index e2662eb..fafb632 100644 --- a/src/uuid/uuid.h +++ b/src/uuid/uuid.h @@ -21,7 +21,7 @@ struct uuid { #define wapp_uuid_create() ((UUID){.uuid = wapp_str8_buf(UUID_BUF_LENGTH)}) // Just returns the same pointer that was passed in with the UUID initialised. -// If the pointer is NULL, it skips initialisation. +// Fails when passed a NULL pointer. UUID *wapp_uuid_init_uuid4(UUID *uuid); #endif // !UUID_H diff --git a/src/uuid/wapp_uuid.c b/src/uuid/wapp_uuid.c index 7fa7ed4..f68dea3 100644 --- a/src/uuid/wapp_uuid.c +++ b/src/uuid/wapp_uuid.c @@ -2,7 +2,7 @@ #define WAPP_UUID_C #include "uuid.c" -#include "../core/wapp_core.c" +#include "../primitives/wapp_primitives.c" #include "../prng/wapp_prng.c" #endif // !WAPP_UUID_C diff --git a/src/uuid/wapp_uuid.h b/src/uuid/wapp_uuid.h index 094ccd2..86aabcf 100644 --- a/src/uuid/wapp_uuid.h +++ b/src/uuid/wapp_uuid.h @@ -3,7 +3,7 @@ #include "uuid.h" #include "../common/wapp_common.h" -#include "../core/wapp_core.h" +#include "../primitives/wapp_primitives.h" #include "../prng/wapp_prng.h" #endif // !WAPP_UUID_H