Add static, runtime and debug assert utilities
This commit is contained in:
parent
75be2316e0
commit
b8c548ee4b
2
Makefile
2
Makefile
@ -12,7 +12,7 @@ LIB_OUT = $(BUILD_DIR)/libwapp.so
|
||||
TEST_OUT = $(BUILD_DIR)/wapptest
|
||||
|
||||
ifeq ($(BUILD_TYPE),debug)
|
||||
CFLAGS += -g -fsanitize=address,undefined
|
||||
CFLAGS += -g -fsanitize=address,undefined -DWAPP_DEBUG_ASSERT
|
||||
else ifeq ($(BUILD_TYPE),release)
|
||||
CFLAGS += -O3
|
||||
else
|
||||
|
@ -46,7 +46,10 @@ def make_array(user_datatypes: Dict[CDataType, ArrayData] = {}):
|
||||
out_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
common_includes: List[CInclude] = [
|
||||
CInclude(header="stdbool.h"),
|
||||
CInclude(
|
||||
header=str(convert_to_relative(WAPP_SRC_ROOT / "common" / "aliases" / "aliases.h", out_dir)).replace("\\", "/"),
|
||||
local=True,
|
||||
),
|
||||
CInclude(
|
||||
header=str(convert_to_relative(WAPP_SRC_ROOT / "primitives" / "mem_allocator" / "mem_allocator.h", out_dir)).replace("\\", "/"),
|
||||
local=True,
|
||||
@ -103,7 +106,10 @@ def make_array(user_datatypes: Dict[CDataType, ArrayData] = {}):
|
||||
includes=[
|
||||
CInclude(header, local=True, same_dir=True),
|
||||
CInclude(header="stddef.h"),
|
||||
CInclude(header="assert.h"),
|
||||
CInclude(
|
||||
header=str(convert_to_relative(WAPP_SRC_ROOT / "common" / "assert" / "assert.h", out_dir)).replace("\\", "/"),
|
||||
local=True
|
||||
),
|
||||
],
|
||||
internal_funcs=[],
|
||||
funcs=header.funcs
|
||||
|
@ -1,4 +1,4 @@
|
||||
assert(allocator != NULL);
|
||||
wapp_debug_assert(allocator != NULL, "`array` should not be NULL");
|
||||
|
||||
u64 allocation_size = sizeof({ArrayType}) + item_size * capacity;
|
||||
{ArrayType} *array = wapp_mem_allocator_alloc(allocator, allocation_size);
|
||||
|
@ -1,4 +1,4 @@
|
||||
assert(allocator != NULL && array != NULL);
|
||||
wapp_debug_assert(allocator != NULL && array != NULL, "`allocator` and `array` should not be NULL");
|
||||
|
||||
{ArrayType} *output = array;
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
assert(array != NULL && array->count < array->capacity);
|
||||
wapp_debug_assert(array != NULL, "`array` should not be NULL");
|
||||
wapp_runtime_assert(array->count < array->capacity, "`array` is full");
|
||||
|
||||
u64 index = (array->count)++;
|
||||
wapp_{Tlower}_array_set(array, index, item);
|
||||
|
@ -1,4 +1,5 @@
|
||||
assert(array != NULL && index < array->count);
|
||||
wapp_debug_assert(array != NULL, "`array` should not be NULL");
|
||||
wapp_runtime_assert(index < array->count, "`index` is out of bounds");
|
||||
|
||||
u8 *ptr = (u8 *)(array->items) + (array->item_size * index);
|
||||
return ({T} *)ptr;
|
||||
|
@ -1,2 +1,2 @@
|
||||
assert(array != NULL);
|
||||
wapp_debug_assert(array != NULL, "`array` should not be NULL");
|
||||
array->count = 0;
|
||||
|
@ -1,4 +1,4 @@
|
||||
assert(allocator != NULL && src != NULL && dst != NULL);
|
||||
wapp_debug_assert(allocator != NULL && src != NULL && dst != NULL, "`allocator`, `src` and `dst` should not be NULL");
|
||||
|
||||
{ArrayType} *output = dst;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
assert(src != NULL && dst != NULL);
|
||||
wapp_debug_assert(src != NULL && dst != NULL, "`src` and `dst` should not be NULL");
|
||||
|
||||
wapp_{Tlower}_array_clear(dst);
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
assert(allocator != NULL && array != NULL && other != NULL);
|
||||
wapp_debug_assert(allocator != NULL && array != NULL && other != NULL, "`allocator`, `array` and `other` should not be NULL");
|
||||
|
||||
{ArrayType} *output = array;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
assert(array != NULL && other != NULL);
|
||||
wapp_debug_assert(array != NULL && other != NULL, "`array` and `other` should not be NULL");
|
||||
|
||||
u64 remaining_capacity = array->capacity - array->count;
|
||||
assert(other->count < remaining_capacity);
|
||||
wapp_runtime_assert(other->count < remaining_capacity, "`array` does not have enough capacity");
|
||||
|
||||
{T} *item;
|
||||
|
||||
|
@ -2,7 +2,7 @@ from pathlib import Path
|
||||
from dataclasses import dataclass, field
|
||||
from typing import List, Dict
|
||||
from codegen.constants import WAPP_SRC_ROOT
|
||||
from codegen.utils import load_func_body_from_file
|
||||
from codegen.utils import load_func_body_from_file, convert_to_relative
|
||||
from codegen.datatypes import (
|
||||
CDataType,
|
||||
CMacro,
|
||||
@ -49,7 +49,10 @@ def make_dbl_list(user_datatypes: Dict[CDataType, DblListData] = {}):
|
||||
out_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
common_includes: List[CInclude] = [
|
||||
CInclude(header="stdbool.h")
|
||||
CInclude(
|
||||
header=str(convert_to_relative(WAPP_SRC_ROOT / "common" / "aliases" / "aliases.h", out_dir)).replace("\\", "/"),
|
||||
local=True,
|
||||
)
|
||||
]
|
||||
|
||||
common_decl_types: List[CStruct] = []
|
||||
@ -95,6 +98,10 @@ def make_dbl_list(user_datatypes: Dict[CDataType, DblListData] = {}):
|
||||
decl_types=[*common_decl_types],
|
||||
includes=[
|
||||
CInclude(header, local=True, same_dir=True),
|
||||
CInclude(
|
||||
header=str(convert_to_relative(WAPP_SRC_ROOT / "common" / "assert" / "assert.h", out_dir)).replace("\\", "/"),
|
||||
local=True
|
||||
),
|
||||
CInclude(header="stddef.h"),
|
||||
CInclude(header="assert.h"),
|
||||
],
|
||||
|
@ -1,4 +1,4 @@
|
||||
assert(list != NULL);
|
||||
wapp_debug_assert(list != NULL, "`list` should not be NULL");
|
||||
|
||||
u64 count = list->node_count;
|
||||
for (u64 i = 0; i < count; ++i) {{
|
||||
|
@ -1,4 +1,4 @@
|
||||
assert(index < list->node_count);
|
||||
wapp_runtime_assert(index < list->node_count, "`index` is out of bounds");
|
||||
|
||||
{NodeType} *output = NULL;
|
||||
{NodeType} *current = list->first;
|
||||
|
@ -1,4 +1,4 @@
|
||||
assert(list != NULL && node != NULL && (node->item) != NULL);
|
||||
wapp_debug_assert(list != NULL && node != NULL && (node->item) != NULL, "`list`, `node` and `node->item` should not be NULL");
|
||||
|
||||
if (index == 0) {{
|
||||
wapp_{Tlower}_list_push_front(list, node);
|
||||
|
@ -1,4 +1,4 @@
|
||||
assert(list != NULL);
|
||||
wapp_debug_assert(list != NULL, "`list` should not be NULL");
|
||||
|
||||
{NodeType} *output = NULL;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
assert(list != NULL);
|
||||
wapp_debug_assert(list != NULL, "`list` should not be NULL");
|
||||
|
||||
{NodeType} *output = NULL;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
assert(list != NULL && node != NULL && (node->item) != NULL);
|
||||
wapp_debug_assert(list != NULL && node != NULL && (node->item) != NULL, "`list`, `node` and `node->item` should not be NULL");
|
||||
|
||||
{ListType} node_list = {Tlower}_node_to_list(node);
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
assert(list != NULL && node != NULL && (node->item) != NULL);
|
||||
wapp_debug_assert(list != NULL && node != NULL && (node->item) != NULL, "`list`, `node` and `node->item` should not be NULL");
|
||||
|
||||
{ListType} node_list = {Tlower}_node_to_list(node);
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
assert(list != NULL);
|
||||
wapp_debug_assert(list != NULL, "`list` should not be NULL");
|
||||
|
||||
{NodeType} *output = NULL;
|
||||
|
||||
|
27
src/common/assert/assert.h
Normal file
27
src/common/assert/assert.h
Normal file
@ -0,0 +1,27 @@
|
||||
// vim:fileencoding=utf-8:foldmethod=marker
|
||||
|
||||
#include "../aliases/aliases.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#define wapp_static_assert(EXPR, MSG) extern char ASSERTION_FAILED[EXPR ? 1 : -1]
|
||||
#define wapp_runtime_assert(EXPR, MSG) __wapp_runtime_assert(EXPR, MSG)
|
||||
|
||||
#ifdef WAPP_DEBUG_ASSERT
|
||||
#define wapp_debug_assert(EXPR, MSG) wapp_runtime_assert(EXPR, MSG)
|
||||
#else
|
||||
#define wapp_debug_assert(EXPR, MSG)
|
||||
#endif
|
||||
|
||||
#define __wapp_runtime_assert(EXPR, MSG) do { \
|
||||
if (!(EXPR)) { \
|
||||
fprintf( \
|
||||
stderr, \
|
||||
"%s:%d (In function `%s`): Assertion failed (%" PRIu32 ")\nDiagnostic: %s\n\n", \
|
||||
__FILE__, __LINE__, __func__, \
|
||||
EXPR, MSG \
|
||||
); \
|
||||
abort(); \
|
||||
} \
|
||||
} while(false)
|
@ -4,6 +4,7 @@
|
||||
#define WAPP_COMMON_H
|
||||
|
||||
#include "aliases/aliases.h"
|
||||
#include "assert/assert.h"
|
||||
#include "misc/misc_utils.h"
|
||||
#include "platform/platform.h"
|
||||
|
||||
|
@ -3,12 +3,12 @@
|
||||
#include "mem_arena.h"
|
||||
#include "../utils/mem_utils.h"
|
||||
#include "../../../common/aliases/aliases.h"
|
||||
#include "../../../common/assert/assert.h"
|
||||
#include "../../../common/misc/misc_utils.h"
|
||||
#include "../../os/mem/mem_os.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#ifndef DEFAULT_ALIGNMENT
|
||||
// Why 2 * sizeof(void *) instead of sizeof(void *)
|
||||
@ -66,7 +66,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);
|
||||
wapp_debug_assert(arena != NULL, "`arena` should not be NULL");
|
||||
|
||||
u8 *alloc_start = arena->offset;
|
||||
|
||||
@ -125,14 +125,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);
|
||||
wapp_debug_assert(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) {
|
||||
assert(arena != NULL && (*arena) != NULL);
|
||||
wapp_debug_assert(arena != NULL && (*arena) != NULL, "`arena` double pointer is not valid");
|
||||
|
||||
Arena *arena_ptr = *arena;
|
||||
if (arena_ptr->buf) {
|
||||
|
@ -2,15 +2,15 @@
|
||||
|
||||
#include "mem_utils.h"
|
||||
#include "../../../common/aliases/aliases.h"
|
||||
#include "../../../common/assert/assert.h"
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <assert.h>
|
||||
|
||||
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);
|
||||
assert(is_power_of_two(alignment));
|
||||
wapp_debug_assert(ptr != NULL, "`ptr` should not be NULL");
|
||||
wapp_runtime_assert(is_power_of_two(alignment), "`alignment` value is not a power of two");
|
||||
|
||||
uptr p = (uptr)ptr;
|
||||
uptr align = (uptr)alignment;
|
||||
|
@ -3,6 +3,7 @@
|
||||
*/
|
||||
|
||||
#include "./dbl_list.h"
|
||||
#include "../../common/assert/assert.h"
|
||||
#include "../../common/aliases/aliases.h"
|
||||
#include "../../common/platform/platform.h"
|
||||
#include <stddef.h>
|
||||
|
@ -2,27 +2,27 @@
|
||||
|
||||
#include "mem_allocator.h"
|
||||
#include "../../common/aliases/aliases.h"
|
||||
#include "../../common/assert/assert.h"
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
void *wapp_mem_allocator_alloc(const Allocator *allocator, u64 size) {
|
||||
assert(allocator != NULL && (allocator->alloc) != NULL);
|
||||
wapp_debug_assert(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) {
|
||||
assert(allocator != NULL && (allocator->alloc_aligned) != NULL);
|
||||
wapp_debug_assert(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) {
|
||||
assert(allocator != NULL && (allocator->realloc) != NULL);
|
||||
wapp_debug_assert(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) {
|
||||
assert(allocator != NULL && (allocator->realloc_aligned) != NULL);
|
||||
wapp_debug_assert(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,18 +2,18 @@
|
||||
|
||||
#include "str8.h"
|
||||
#include "../../../common/aliases/aliases.h"
|
||||
#include "../../../common/assert/assert.h"
|
||||
#include "../../mem_allocator/mem_allocator.h"
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define STR8_BUF_ALLOC_SIZE(CAPACITY) (sizeof(Str8) + sizeof(c8) * CAPACITY)
|
||||
|
||||
Str8 *wapp_str8_alloc_buf(const Allocator *allocator, u64 capacity) {
|
||||
assert(allocator != NULL);
|
||||
wapp_debug_assert(allocator != NULL, "`allocator` should not be NULL");
|
||||
|
||||
Str8 *str = wapp_mem_allocator_alloc(allocator, STR8_BUF_ALLOC_SIZE(capacity));
|
||||
if (!str) {
|
||||
@ -29,7 +29,7 @@ RETURN_STR8:
|
||||
}
|
||||
|
||||
Str8 *wapp_str8_alloc_cstr(const Allocator *allocator, const char *str) {
|
||||
assert(allocator != NULL && str != NULL);
|
||||
wapp_debug_assert(allocator != NULL && str != NULL, "`allocator` and `str` should not be NULL");
|
||||
|
||||
u64 length = strlen(str);
|
||||
Str8 *output = wapp_str8_alloc_buf(allocator, length * 2);
|
||||
@ -45,7 +45,7 @@ RETURN_ALLOC_CSTR:
|
||||
}
|
||||
|
||||
Str8 *wapp_str8_alloc_str8(const Allocator *allocator, Str8RO *str) {
|
||||
assert(allocator != NULL && str != NULL);
|
||||
wapp_debug_assert(allocator != NULL && str != NULL, "`allocator` and `str` should not be NULL");
|
||||
|
||||
Str8 *output = wapp_str8_alloc_buf(allocator, str->capacity);
|
||||
if (!output) {
|
||||
@ -60,7 +60,7 @@ RETURN_ALLOC_STR8:
|
||||
}
|
||||
|
||||
Str8 *wapp_str8_alloc_substr(const Allocator *allocator, Str8RO *str, u64 start, u64 end) {
|
||||
assert(allocator != NULL && str != NULL);
|
||||
wapp_debug_assert(allocator != NULL && str != NULL, "`allocator` and `str` should not be NULL");
|
||||
|
||||
Str8 *output = NULL;
|
||||
|
||||
@ -85,7 +85,7 @@ RETURN_ALLOC_SUBSTR:
|
||||
}
|
||||
|
||||
void wapp_str8_dealloc_buf(const Allocator *allocator, Str8 **str) {
|
||||
assert(allocator != NULL && str != NULL && (*str) != NULL);
|
||||
wapp_debug_assert(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));
|
||||
}
|
||||
|
||||
@ -148,7 +148,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);
|
||||
wapp_debug_assert(allocator != NULL && dst != NULL && src != NULL, "`allocator`, `dst` and `src` should not be NULL");
|
||||
|
||||
Str8 *output = NULL;
|
||||
u64 remaining = dst->capacity - dst->size;
|
||||
@ -174,7 +174,7 @@ RETURN_STR8_CONCAT:
|
||||
}
|
||||
|
||||
void wapp_str8_concat_capped(Str8 *dst, Str8RO *src) {
|
||||
assert(dst != NULL && src != NULL);
|
||||
wapp_debug_assert(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;
|
||||
@ -184,7 +184,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);
|
||||
wapp_debug_assert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL");
|
||||
|
||||
u64 length = strlen(src);
|
||||
u64 to_copy = length <= dst->capacity ? length : dst->capacity;
|
||||
@ -195,7 +195,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);
|
||||
wapp_debug_assert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL");
|
||||
|
||||
u64 to_copy = src->size <= dst->capacity ? src->size : dst->capacity;
|
||||
|
||||
@ -205,7 +205,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);
|
||||
wapp_debug_assert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL");
|
||||
|
||||
u64 to_copy = src->size < dst_capacity ? src->size : dst_capacity - 1;
|
||||
|
||||
@ -214,7 +214,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);
|
||||
wapp_debug_assert(dst != NULL && format != NULL, "`dst` and `format` should not be NULL");
|
||||
|
||||
va_list args1;
|
||||
va_list args2;
|
||||
@ -276,7 +276,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);
|
||||
wapp_debug_assert(allocator != NULL && str != NULL && delimiter != NULL, "`allocator`, `str` and `delimiter` should not be NULL");
|
||||
|
||||
Str8List *output = wapp_mem_allocator_alloc(allocator, sizeof(Str8List));
|
||||
|
||||
@ -329,7 +329,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);
|
||||
wapp_debug_assert(allocator != NULL && str != NULL && delimiter != NULL, "`allocator`, `str` and `delimiter` should not be NULL");
|
||||
|
||||
Str8List *output = wapp_mem_allocator_alloc(allocator, sizeof(Str8List));
|
||||
|
||||
@ -379,7 +379,7 @@ RETURN_STR8_SPLIT:
|
||||
}
|
||||
|
||||
Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8RO *delimiter) {
|
||||
assert(allocator != NULL && list != NULL && delimiter != NULL);
|
||||
wapp_debug_assert(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);
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
#include "xorshift.h"
|
||||
#include "../../common/aliases/aliases.h"
|
||||
#include "../../common/assert/assert.h"
|
||||
#include "../../common/platform/platform.h"
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
@ -95,7 +95,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);
|
||||
wapp_runtime_assert(result == 0, "Invalid seed value");
|
||||
|
||||
srand48(ts.tv_nsec);
|
||||
}
|
||||
@ -107,7 +107,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);
|
||||
wapp_runtime_assert(result != 0, "Invalid seed value");
|
||||
|
||||
srand(ts.tv_nsec);
|
||||
}
|
||||
@ -122,7 +122,7 @@ internal u64 generate_random_number(void) {
|
||||
#else
|
||||
internal void seed_os_generator(void) {
|
||||
time_t result = time(NULL);
|
||||
assert(result != (time_t)(-1));
|
||||
wapp_runtime_assert(result != (time_t)(-1), "Invalid seed value");
|
||||
|
||||
srand(result);
|
||||
}
|
||||
|
@ -2,11 +2,11 @@
|
||||
|
||||
#include "uuid.h"
|
||||
#include "../common/aliases/aliases.h"
|
||||
#include "../common/assert/assert.h"
|
||||
#include "../primitives/strings/str8/str8.h"
|
||||
#include "../prng/xorshift/xorshift.h"
|
||||
#include <stdbool.h>
|
||||
#include <inttypes.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define UUID_STR_FORMAT ("%.8" PRIx64 "-%.4" PRIx64 "-%.4" PRIx64 "-%.4" PRIx64 "-%.12" PRIx64)
|
||||
|
||||
@ -20,7 +20,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);
|
||||
wapp_debug_assert(uuid != NULL, "`uuid` should not be NULL");
|
||||
|
||||
UUID4 uuid4 = generate_uuid4();
|
||||
uuid4_to_uuid(&uuid4, uuid);
|
||||
|
Loading…
x
Reference in New Issue
Block a user