Compare commits

..

No commits in common. "main" and "preserve_cpp" have entirely different histories.

66 changed files with 2496 additions and 1407 deletions

View File

@ -51,6 +51,10 @@ def make_array(user_datatypes: Dict[CDataType, ArrayData] = {}):
header=str(convert_to_relative(WAPP_SRC_ROOT / "primitives" / "mem_allocator" / "mem_allocator.h", out_dir)).replace("\\", "/"),
local=True,
),
CInclude(
header=str(convert_to_relative(WAPP_SRC_ROOT / "primitives" / "strings" / "str8" / "str8.h", out_dir)).replace("\\", "/"),
local=True,
),
CInclude(
header=str(convert_to_relative(WAPP_SRC_ROOT / "common" / "misc" / "misc_utils.h", out_dir)).replace("\\", "/"),
local=True,
@ -62,9 +66,6 @@ def make_array(user_datatypes: Dict[CDataType, ArrayData] = {}):
datatypes: dict[CDataType, ArrayData] = {
"Str8": ArrayData(
array_typename="Str8Array",
hdr_decl_types=[
CStruct(name="str8", cargs=[], typedef_name="Str8"),
],
),
}
@ -100,11 +101,7 @@ def make_array(user_datatypes: Dict[CDataType, ArrayData] = {}):
source = CSource(
name=header.name,
decl_types=[*common_decl_types],
includes=[
CInclude(header, local=True, same_dir=True),
CInclude(header="stddef.h"),
CInclude(header="assert.h"),
],
includes=[CInclude(header, local=True, same_dir=True), CInclude(header="stddef.h")],
internal_funcs=[],
funcs=header.funcs
)
@ -114,8 +111,6 @@ def make_array(user_datatypes: Dict[CDataType, ArrayData] = {}):
source.includes.extend(common_includes)
generic_funcs = []
for _type, array_data in datatypes.items():
type_string = get_datatype_string(_type)
clean_type_string = type_string.replace(" ", "").replace("*", "_ptr")
@ -128,29 +123,8 @@ def make_array(user_datatypes: Dict[CDataType, ArrayData] = {}):
CArg(name="items", _type=type_string, pointer=CPointer(_type=CPointerType.SINGLE)),
CArg(name="count", _type=CType.U64),
CArg(name="capacity", _type=CType.U64),
CArg(name="item_size", _type=CType.U64),
],
)
if isinstance(_type, str) and _type == "void *":
alloc_capacity_func = CFunc(
name=f"_array_alloc_capacity",
ret_type=array,
args=[
CArg(name="allocator", _type="Allocator", pointer=CPointer(CPointerType.SINGLE), qualifier=CQualifier.CONST),
CArg(name="capacity", _type=CType.U64),
CArg(name="item_size", _type=CType.U64),
],
body=__format_func_body(
filename=snippets_dir / "alloc_capacity",
type_string=type_string,
type_string_upper=type_string_upper,
type_string_lower=type_string_lower,
array_typename=array_data.array_typename,
),
pointer=CPointer(CPointerType.SINGLE),
)
generic_funcs.append(alloc_capacity_func)
stack_array_macro = CMacro(
name=f"wapp_{type_string_lower}_array(...)",
@ -174,28 +148,6 @@ def make_array(user_datatypes: Dict[CDataType, ArrayData] = {}):
),
)
alloc_capacity_array_macro = CMacro(
name=f"wapp_{type_string_lower}_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY)",
value=__format_func_body(
filename=snippets_dir / "alloc_capacity_macro",
type_string=type_string,
type_string_upper=type_string_upper,
type_string_lower=type_string_lower,
array_typename=array_data.array_typename,
),
)
array_pop_macro = CMacro(
name=f"wapp_{type_string_lower}_array_pop(ARRAY_PTR)",
value=__format_func_body(
filename=snippets_dir / "array_pop_macro",
type_string=type_string,
type_string_upper=type_string_upper,
type_string_lower=type_string_lower,
array_typename=array_data.array_typename,
),
)
get_func = CFunc(
name=f"wapp_{type_string_lower}_array_get",
ret_type=type_string,
@ -219,7 +171,7 @@ def make_array(user_datatypes: Dict[CDataType, ArrayData] = {}):
args=[
CArg(name="array", _type=array, pointer=CPointer(CPointerType.SINGLE)),
CArg(name="index", _type=CType.U64),
CArg(name="item", _type=type_string, pointer=CPointer(CPointerType.SINGLE)),
CArg(name="item", _type=type_string),
],
body=__format_func_body(
filename=snippets_dir / "array_set",
@ -235,7 +187,7 @@ def make_array(user_datatypes: Dict[CDataType, ArrayData] = {}):
ret_type=CType.VOID,
args=[
CArg(name="array", _type=array, pointer=CPointer(CPointerType.SINGLE)),
CArg(name="item", _type=type_string, pointer=CPointer(CPointerType.SINGLE)),
CArg(name="item", _type=type_string),
],
body=__format_func_body(
filename=snippets_dir / "append_capped",
@ -277,6 +229,21 @@ def make_array(user_datatypes: Dict[CDataType, ArrayData] = {}):
),
)
pop_func = CFunc(
name=f"wapp_{type_string_lower}_array_pop",
ret_type=type_string,
args=[
CArg(name="array", _type=array, pointer=CPointer(CPointerType.SINGLE)),
],
body=__format_func_body(
filename=snippets_dir / "array_pop",
type_string=type_string,
type_string_upper=type_string_upper,
type_string_lower=type_string_lower,
array_typename=array_data.array_typename,
),
)
copy_capped_func = CFunc(
name=f"wapp_{type_string_lower}_array_copy_capped",
ret_type=CType.VOID,
@ -293,13 +260,30 @@ def make_array(user_datatypes: Dict[CDataType, ArrayData] = {}):
),
)
alloc_capacity_func = CFunc(
name=f"wapp_{type_string_lower}_array_alloc_capacity",
ret_type=array,
args=[
CArg(name="allocator", _type="Allocator", pointer=CPointer(CPointerType.SINGLE), qualifier=CQualifier.CONST),
CArg(name="capacity", _type=CType.U64),
],
body=__format_func_body(
filename=snippets_dir / "alloc_capacity",
type_string=type_string,
type_string_upper=type_string_upper,
type_string_lower=type_string_lower,
array_typename=array_data.array_typename,
),
pointer=CPointer(CPointerType.SINGLE),
)
append_alloc_func = CFunc(
name=f"wapp_{type_string_lower}_array_append_alloc",
ret_type=array,
args=[
CArg(name="allocator", _type="Allocator", pointer=CPointer(CPointerType.SINGLE), qualifier=CQualifier.CONST),
CArg(name="array", _type=array, pointer=CPointer(CPointerType.SINGLE)),
CArg(name="item", _type=type_string, pointer=CPointer(CPointerType.SINGLE)),
CArg(name="item", _type=type_string),
],
body=__format_func_body(
filename=snippets_dir / "append_alloc",
@ -347,29 +331,8 @@ def make_array(user_datatypes: Dict[CDataType, ArrayData] = {}):
pointer=CPointer(CPointerType.SINGLE),
)
pop_func = CFunc(
name=f"_{type_string_lower}_array_pop",
ret_type=type_string,
args=[
CArg(name="array", _type=array, pointer=CPointer(CPointerType.SINGLE)),
],
body=__format_func_body(
filename=snippets_dir / "array_pop",
type_string=type_string,
type_string_upper=type_string_upper,
type_string_lower=type_string_lower,
array_typename=array_data.array_typename,
),
pointer=CPointer(CPointerType.SINGLE),
)
header.decl_types.extend(array_data.hdr_decl_types)
header.macros.extend([
stack_array_macro,
stack_capacity_array_macro,
alloc_capacity_array_macro,
array_pop_macro,
])
header.macros.extend([stack_array_macro, stack_capacity_array_macro])
header.types.extend([array])
header.funcs.extend([
get_func,
@ -377,17 +340,16 @@ def make_array(user_datatypes: Dict[CDataType, ArrayData] = {}):
append_capped_func,
extend_capped_func,
clear_func,
pop_func,
copy_capped_func,
alloc_capacity_func,
append_alloc_func,
extend_alloc_func,
copy_alloc_func,
pop_func,
])
source.decl_types.extend(array_data.src_decl_types)
source.funcs = header.funcs
header.funcs.extend(generic_funcs)
header.save(out_dir)
source.save(out_dir)

View File

@ -1,15 +1,18 @@
assert(allocator != NULL);
u64 allocation_size = sizeof({ArrayType}) + sizeof({T}) * capacity;
{ArrayType} *array = NULL;
u64 allocation_size = sizeof({ArrayType}) + item_size * capacity;
{ArrayType} *array = wapp_mem_allocator_alloc(allocator, allocation_size);
if (!array) {{
goto RETURN_GENERIC_ARRAY_ALLOC;
if (!allocator) {{
goto RETURN_{Tupper}_ARRAY_ALLOC;
}}
array->items = ({T} *)((u8 *)array + sizeof({ArrayType}));
array->count = 0;
array->capacity = capacity;
array->item_size = item_size;
array = wapp_mem_allocator_alloc(allocator, allocation_size);
if (!array) {{
goto RETURN_{Tupper}_ARRAY_ALLOC;
}}
RETURN_GENERIC_ARRAY_ALLOC:
array->items = ({T} *)((u8 *)array + sizeof({ArrayType}));
array->count = 0;
array->capacity = capacity;
RETURN_{Tupper}_ARRAY_ALLOC:
return array;

View File

@ -1 +0,0 @@
(({ArrayType} *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof({T})))

View File

@ -1,10 +1,12 @@
assert(allocator != NULL && array != NULL);
{ArrayType} *output = array;
if (!allocator || !array) {{
goto RETURN_{Tupper}_ARRAY_APPEND_ALLOC;
}}
if (array->count >= array->capacity) {{
u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2);
output = ({ArrayType} *)_array_alloc_capacity(allocator, new_capacity, array->item_size);
output = wapp_{Tlower}_array_alloc_capacity(allocator, new_capacity);
if (!output) {{
output = array;
goto RETURN_{Tupper}_ARRAY_APPEND_ALLOC;

View File

@ -1,4 +1,5 @@
assert(array != NULL && array->count < array->capacity);
if (!array || array->count >= array->capacity) {{
return;
}}
u64 index = (array->count)++;
wapp_{Tlower}_array_set(array, index, item);
array->items[(array->count)++] = item;

View File

@ -1,4 +1,5 @@
assert(array != NULL && index < array->count);
if (!array || index >= array->count) {{
return NULL;
}}
u8 *ptr = (u8 *)(array->items) + (array->item_size * index);
return ({T} *)ptr;
return &(array->items[index]);

View File

@ -1,4 +1,5 @@
u64 index = array->count - 1;
{T} *out = wapp_{Tlower}_array_get(array, index);
--(array->count);
return out;
if (!array || array->count == 0) {{
return ({T}){{0}};
}}
return array->items[--(array->count)];

View File

@ -1,4 +0,0 @@
(ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
*_{Tlower}_array_pop(ARRAY_PTR) : \
({T}){{0}} \
)

View File

@ -1,3 +1,5 @@
{T} *ptr = wapp_{Tlower}_array_get(array, index);
if (!array || index >= array->count) {{
return;
}}
memcpy((void *)ptr, (void *)item, array->item_size);
array->items[index] = item;

View File

@ -1,2 +1,5 @@
assert(array != NULL);
if (!array) {{
return;
}}
array->count = 0;

View File

@ -1,10 +1,12 @@
assert(allocator != NULL && src != NULL && dst != NULL);
{ArrayType} *output = dst;
if (!allocator || !src || !dst) {{
goto RETURN_{Tupper}_ARRAY_COPY_ALLOC;
}}
if (src->count >= dst->capacity) {{
u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2);
output = ({ArrayType} *)_array_alloc_capacity(allocator, new_capacity, src->item_size);
output = wapp_{Tlower}_array_alloc_capacity(allocator, new_capacity);
if (!output) {{
output = dst;
goto RETURN_{Tupper}_ARRAY_COPY_ALLOC;

View File

@ -1,4 +1,6 @@
assert(src != NULL && dst != NULL);
if (!src || !dst) {{
return;
}}
wapp_{Tlower}_array_clear(dst);
@ -18,5 +20,5 @@
continue;
}}
wapp_{Tlower}_array_append_capped(dst, item);
wapp_{Tlower}_array_append_capped(dst, *item);
}}

View File

@ -1,11 +1,13 @@
assert(allocator != NULL && array != NULL && other != NULL);
{ArrayType} *output = array;
if (!allocator || !array || !other) {{
goto RETURN_{Tupper}_ARRAY_EXTEND_ALLOC;
}}
u64 remaining_capacity = array->capacity - array->count;
if (other->count >= remaining_capacity) {{
u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2);
output = ({ArrayType} *)_array_alloc_capacity(allocator, new_capacity, array->item_size);
output = wapp_{Tlower}_array_alloc_capacity(allocator, new_capacity);
if (!output) {{
output = array;
goto RETURN_{Tupper}_ARRAY_EXTEND_ALLOC;

View File

@ -1,7 +1,11 @@
assert(array != NULL && other != NULL);
if (!array || !other) {{
return;
}}
u64 remaining_capacity = array->capacity - array->count;
assert(other->count < remaining_capacity);
if (other->count >= remaining_capacity) {{
return;
}}
{T} *item;
@ -19,5 +23,5 @@
continue;
}}
wapp_{Tlower}_array_append_capped(array, item);
}}
wapp_{Tlower}_array_append_capped(array, *item);
}}

View File

@ -1,6 +1,5 @@
(({ArrayType}){{ \
.items = ({T}[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count({T}, __VA_ARGS__) * 2)]){{__VA_ARGS__}}, \
.count = wapp_misc_utils_va_args_count({T}, __VA_ARGS__), \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count({T}, __VA_ARGS__) * 2), \
.item_size = sizeof({T}) \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count({T}, __VA_ARGS__) * 2) \
}})

View File

@ -1 +1 @@
(({ArrayType}){{.items = ({T}[CAPACITY]){{0}}, .count = 0, .capacity = CAPACITY, .item_size = sizeof({T})}})
(({ArrayType}){{.items = ({T}[CAPACITY]){{0}}, .count = 0, .capacity = CAPACITY}})

View File

@ -246,7 +246,10 @@ class CHeader(CFile):
name_upper = self.name.upper()
header_guard_name = f"{name_upper}_H"
header_guard_open = f"#ifndef {header_guard_name}\n#define {header_guard_name}\n\n"
header_guard_close = f"\n#endif // !{header_guard_name}\n"
header_guard_close = f"#endif // !{header_guard_name}\n"
c_linkage_open = "#ifdef WAPP_PLATFORM_CPP\nBEGIN_C_LINKAGE\n#endif // !WAPP_PLATFORM_CPP\n\n"
c_linkage_close = "\n#ifdef WAPP_PLATFORM_CPP\nEND_C_LINKAGE\n#endif // !WAPP_PLATFORM_CPP\n\n"
includes = _get_includes_string(self.includes)
@ -274,10 +277,12 @@ class CHeader(CFile):
super().__str__() +
header_guard_open +
includes +
c_linkage_open +
macros +
forward_declarations +
types +
funcs +
c_linkage_close +
header_guard_close
)

View File

@ -93,11 +93,7 @@ def make_dbl_list(user_datatypes: Dict[CDataType, DblListData] = {}):
source = CSource(
name=header.name,
decl_types=[*common_decl_types],
includes=[
CInclude(header, local=True, same_dir=True),
CInclude(header="stddef.h"),
CInclude(header="assert.h"),
],
includes=[CInclude(header, local=True, same_dir=True), CInclude(header="stddef.h")],
internal_funcs=[],
funcs=header.funcs
)

View File

@ -1,4 +1,6 @@
assert(list != NULL);
if (!list) {{
return;
}}
u64 count = list->node_count;
for (u64 i = 0; i < count; ++i) {{

View File

@ -1,4 +1,6 @@
assert(index < list->node_count);
if (index >= list->node_count) {{
return NULL;
}}
{NodeType} *output = NULL;
{NodeType} *current = list->first;

View File

@ -1,4 +1,6 @@
assert(list != NULL && node != NULL && (node->item) != NULL);
if (!list || !node || !(node->item)) {{
return;
}}
if (index == 0) {{
wapp_{Tlower}_list_push_front(list, node);

View File

@ -1,8 +1,6 @@
assert(list != NULL);
{NodeType} *output = NULL;
if (list->node_count == 0) {{
if (!list || list->node_count == 0) {{
goto RETURN_{Tupper}_LIST_POP_BACK;
}}

View File

@ -1,8 +1,6 @@
assert(list != NULL);
{NodeType} *output = NULL;
if (list->node_count == 0) {{
if (!list || list->node_count == 0) {{
goto RETURN_{Tupper}_LIST_POP_FRONT;
}}

View File

@ -1,4 +1,6 @@
assert(list != NULL && node != NULL && (node->item) != NULL);
if (!list || !node || !(node->item)) {{
return;
}}
{ListType} node_list = {Tlower}_node_to_list(node);

View File

@ -1,4 +1,6 @@
assert(list != NULL && node != NULL && (node->item) != NULL);
if (!list || !node || !(node->item)) {{
return;
}}
{ListType} node_list = {Tlower}_node_to_list(node);

View File

@ -1,6 +1,7 @@
assert(list != NULL);
{NodeType} *output = NULL;
if (!list) {{
goto RETURN_{Tupper}_LIST_REMOVE;
}}
if (index == 0) {{
output = wapp_{Tlower}_list_pop_front(list);

View File

@ -4,22 +4,9 @@
#include "../platform/platform.h"
#include <stdint.h>
#if WAPP_PLATFORM_C_VERSION >= WAPP_PLATFORM_C11_VERSION && !defined(WAPP_PLATFORM_APPLE)
#include <uchar.h>
#if WAPP_PLATFORM_C_VERSION >= WAPP_PLATFORM_C23_VERSION
#define c8 char8_t
#else
#define c8 uint8_t
#endif // !WAPP_PLATFORM_C23_VERSION
#define c16 char16_t
#define c32 char32_t
#else
#define c8 uint8_t
#define c16 uint16_t
#define c32 uint32_t
#endif // !WAPP_PLATFORM_C11_VERSION
#define c8 uint8_t
#define c16 uint16_t
#define c32 uint32_t
#define u8 uint8_t
#define u16 uint16_t
@ -42,4 +29,10 @@
#define internal static
#define persistent static
#ifdef WAPP_PLATFORM_CPP
#define class_mem static
#define BEGIN_C_LINKAGE extern "C" {
#define END_C_LINKAGE }
#endif // WAPP_PLATFORM_CPP
#endif // !ALIASES_H

View File

@ -59,7 +59,30 @@
#endif
#ifdef __cplusplus
#error "WAPP is a C only library"
#define WAPP_PLATFORM_CPP
#define WAPP_PLATFORM_CPP_VERSION __cplusplus
#define WAPP_PLATFORM_CPP98_VERSION 199711L
#define WAPP_PLATFORM_CPP11_VERSION 201103L
#define WAPP_PLATFORM_CPP14_VERSION 201402L
#define WAPP_PLATFORM_CPP17_VERSION 201703L
#define WAPP_PLATFORM_CPP20_VERSION 202002L
#define WAPP_PLATFORM_CPP23_VERSION 202302L
#if WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP98_VERSION
#define WAPP_PLATFORM_CPP98
#elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP11_VERSION
#define WAPP_PLATFORM_CPP11
#elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP14_VERSION
#define WAPP_PLATFORM_CPP14
#elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP17_VERSION
#define WAPP_PLATFORM_CPP17
#elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP20_VERSION
#define WAPP_PLATFORM_CPP20
#elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP23_VERSION
#define WAPP_PLATFORM_CPP23
#else
#error "Unrecognised C++ version"
#endif
#else
#define WAPP_PLATFORM_C

View File

@ -1,12 +1,10 @@
#include "mem_arena.h"
#include "../utils/mem_utils.h"
#include "../../../common/aliases/aliases.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 *)
@ -64,7 +62,9 @@ void *wapp_mem_arena_alloc(Arena *arena, u64 size) {
}
void *wapp_mem_arena_alloc_aligned(Arena *arena, u64 size, u64 alignment) {
assert(arena != NULL);
if (!arena) {
return NULL;
}
u8 *alloc_start = arena->offset;
@ -123,14 +123,18 @@ void *wapp_mem_arena_realloc_aligned(Arena *arena, void *ptr, u64 old_size, u64
}
void wapp_mem_arena_clear(Arena *arena) {
assert(arena != NULL);
if (!arena) {
return;
}
memset(arena->buf, 0, arena->offset - arena->buf);
arena->offset = arena->buf;
}
void wapp_mem_arena_destroy(Arena **arena) {
assert(arena != NULL && (*arena) != NULL);
if (!arena) {
return;
}
Arena *arena_ptr = *arena;
if (arena_ptr->buf) {

View File

@ -6,6 +6,10 @@
#include "../../os/mem/mem_os.h"
#include <stdbool.h>
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
typedef struct arena Arena;
#define wapp_mem_arena_init(arena_dptr, base_capacity) \
@ -30,4 +34,8 @@ void *wapp_mem_arena_realloc_aligned(Arena *arena, void *ptr, u64 old_size, u64
void wapp_mem_arena_clear(Arena *arena);
void wapp_mem_arena_destroy(Arena **arena);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !MEM_ARENA_H

View File

@ -7,6 +7,10 @@
#include "../../os/mem/mem_os.h"
#include <stdbool.h>
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#define wapp_mem_arena_allocator_init(base_capacity) \
(wapp_mem_arena_allocator_init_custom(base_capacity, WAPP_MEM_ALLOC_RESERVE, false))
#define wapp_mem_arena_allocator_init_commit(base_capacity) \
@ -31,4 +35,8 @@ Allocator wapp_mem_arena_allocator_init_custom(u64 base_capacity, MemAllocFlags
void wapp_mem_arena_allocator_clear(Allocator *allocator);
void wapp_mem_arena_allocator_destroy(Allocator *allocator);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !MEM_ARENA_ALLOCATOR_H

View File

@ -7,7 +7,10 @@
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);
if (!ptr) {
return NULL;
}
assert(is_power_of_two(alignment));
uptr p = (uptr)ptr;

View File

@ -4,6 +4,14 @@
#include "../../../common/aliases/aliases.h"
#include "../../../common/platform/platform.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
void *wapp_mem_util_align_forward(void *ptr, u64 alignment);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !MEM_UTILS_H

View File

@ -35,7 +35,7 @@ u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts) {
// MSVC Spectre mitigation warnings
const Str8Node *node = first_node;
u64 node_index = 1;
bool running = node_index < parts->node_count;
bool running = true;
while (running && node->next) {
node = node->next;
if (node->item->size == 0) {

View File

@ -6,6 +6,10 @@
#include "../../../primitives/mem_allocator/mem_allocator.h"
#include "../../../primitives/strings/str8/str8.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#ifdef WAPP_PLATFORM_POSIX
#define PATH_SEP '/'
#elif defined(WAPP_PLATFORM_WINDOWS)
@ -27,4 +31,8 @@ enum {
u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts);
Str8 *dirup(const Allocator *allocator, Str8RO *path, u64 levels);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !CPATH_H

View File

@ -4,6 +4,10 @@
#include "../../../common/aliases/aliases.h"
#include "../../../common/platform/platform.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#include "mem_os_ops.h"
#if defined(WAPP_PLATFORM_WINDOWS)
@ -14,10 +18,15 @@
#error "Unrecognised platform"
#endif
void *wapp_mem_util_align_forward(void *ptr, u64 alignment);
void *wapp_mem_util_alloc(void *addr, u64 size, MemAccess access, MemAllocFlags flags, MemInitType type);
void wapp_mem_util_free(void *ptr, u64 size);
external void *mem_util_allocate(void *addr, u64 size, MemAccess access, MemAllocFlags flags, MemInitType type);
external void mem_util_free(void *ptr, u64 size);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !MEM_OS_H

View File

@ -3,6 +3,10 @@
#include "../../../common/platform/platform.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
typedef enum mem_access {
WAPP_MEM_ACCESS_NONE,
WAPP_MEM_ACCESS_READ_ONLY,
@ -17,4 +21,8 @@ typedef enum mem_init_type {
WAPP_MEM_INIT_INITIALISED,
} MemInitType;
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !MEM_OS_OPS_H

View File

@ -3,6 +3,10 @@
#include "../../../../common/platform/platform.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // !WAPP_PLATFORM_CPP
#ifdef WAPP_PLATFORM_POSIX
#include <sys/mman.h>
@ -22,4 +26,8 @@ typedef enum mem_alloc_flags {
#endif // !WAPP_PLATFORM_POSIX
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // !WAPP_PLATFORM_CPP
#endif // !MEM_OS_POSIX_H

View File

@ -3,6 +3,10 @@
#include "../../../../common/platform/platform.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // !WAPP_PLATFORM_CPP
#ifdef WAPP_PLATFORM_WINDOWS
#define WIN32_LEAN_AND_MEAN
@ -16,4 +20,8 @@ typedef enum mem_alloc_flags {
#endif // !WAPP_PLATFORM_WINDOWS
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // !WAPP_PLATFORM_CPP
#endif // !MEM_OS_WIN_H

View File

@ -9,10 +9,18 @@
#include <stdio.h>
#include <stdlib.h>
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#define CMD_NO_EXIT(ERR) ((CMDResult){.exited = false, .exit_code = EXIT_FAILURE, .error = ERR})
CMDResult wapp_shell_commander_execute(CMDOutHandling out_handling, Str8 *out_buf, const Str8List *cmd);
external CMDError get_output_status(FILE *fp, i32 *status_out);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !COMMANDER_H

View File

@ -5,6 +5,10 @@
#include "../../../../common/platform/platform.h"
#include <stdbool.h>
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
typedef enum {
SHELL_OUTPUT_DISCARD,
SHELL_OUTPUT_PRINT,
@ -32,4 +36,8 @@ struct commander_result {
#endif // !WAPP_PLATFORM_WINDOWS
};
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !COMMANDER_OUTPUT_H

View File

@ -6,9 +6,17 @@
#include "../../../../common/platform/platform.h"
#include "../../../../primitives/strings/str8/str8.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
void wapp_shell_termcolour_print_text(Str8RO *text, TerminalColour colour);
void wapp_shell_termcolour_clear_colour(void);
external void print_coloured_text(Str8RO *text, TerminalColour colour);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !TERM_COLOUR_H

View File

@ -3,6 +3,10 @@
#include "../../../../common/platform/platform.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
typedef enum {
WAPP_TERM_COLOUR_FG_BLACK,
WAPP_TERM_COLOUR_FG_RED,
@ -25,4 +29,8 @@ typedef enum {
COUNT_TERM_COLOUR,
} TerminalColour;
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !TERMINAL_COLOURS_H

File diff suppressed because it is too large Load Diff

View File

@ -6,260 +6,142 @@
#define ARRAY_H
#include "../mem_allocator/mem_allocator.h"
#include "../strings/str8/str8.h"
#include "../../common/misc/misc_utils.h"
#include "../../common/aliases/aliases.h"
#include "../../common/platform/platform.h"
#include <stdbool.h>
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // !WAPP_PLATFORM_CPP
#define wapp_str8_array(...) ((Str8Array){ \
.items = (Str8[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(Str8, __VA_ARGS__) * 2)]){__VA_ARGS__}, \
.count = wapp_misc_utils_va_args_count(Str8, __VA_ARGS__), \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(Str8, __VA_ARGS__) * 2), \
.item_size = sizeof(Str8) \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(Str8, __VA_ARGS__) * 2) \
})
#define wapp_str8_array_with_capacity(CAPACITY) ((Str8Array){.items = (Str8[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(Str8)})
#define wapp_str8_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((Str8Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(Str8)))
#define wapp_str8_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
*_str8_array_pop(ARRAY_PTR) : \
(Str8){0} \
)
#define wapp_str8_array_with_capacity(CAPACITY) ((Str8Array){.items = (Str8[CAPACITY]){0}, .count = 0, .capacity = CAPACITY})
#define wapp_void_ptr_array(...) ((VoidPArray){ \
.items = (void *[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(void *, __VA_ARGS__) * 2)]){__VA_ARGS__}, \
.count = wapp_misc_utils_va_args_count(void *, __VA_ARGS__), \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(void *, __VA_ARGS__) * 2), \
.item_size = sizeof(void *) \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(void *, __VA_ARGS__) * 2) \
})
#define wapp_void_ptr_array_with_capacity(CAPACITY) ((VoidPArray){.items = (void *[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(void *)})
#define wapp_void_ptr_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((VoidPArray *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(void *)))
#define wapp_void_ptr_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
*_void_ptr_array_pop(ARRAY_PTR) : \
(void *){0} \
)
#define wapp_void_ptr_array_with_capacity(CAPACITY) ((VoidPArray){.items = (void *[CAPACITY]){0}, .count = 0, .capacity = CAPACITY})
#define wapp_bool_array(...) ((BoolArray){ \
.items = (bool[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(bool, __VA_ARGS__) * 2)]){__VA_ARGS__}, \
.count = wapp_misc_utils_va_args_count(bool, __VA_ARGS__), \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(bool, __VA_ARGS__) * 2), \
.item_size = sizeof(bool) \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(bool, __VA_ARGS__) * 2) \
})
#define wapp_bool_array_with_capacity(CAPACITY) ((BoolArray){.items = (bool[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(bool)})
#define wapp_bool_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((BoolArray *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(bool)))
#define wapp_bool_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
*_bool_array_pop(ARRAY_PTR) : \
(bool){0} \
)
#define wapp_bool_array_with_capacity(CAPACITY) ((BoolArray){.items = (bool[CAPACITY]){0}, .count = 0, .capacity = CAPACITY})
#define wapp_char_array(...) ((CharArray){ \
.items = (char[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(char, __VA_ARGS__) * 2)]){__VA_ARGS__}, \
.count = wapp_misc_utils_va_args_count(char, __VA_ARGS__), \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(char, __VA_ARGS__) * 2), \
.item_size = sizeof(char) \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(char, __VA_ARGS__) * 2) \
})
#define wapp_char_array_with_capacity(CAPACITY) ((CharArray){.items = (char[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(char)})
#define wapp_char_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((CharArray *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(char)))
#define wapp_char_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
*_char_array_pop(ARRAY_PTR) : \
(char){0} \
)
#define wapp_char_array_with_capacity(CAPACITY) ((CharArray){.items = (char[CAPACITY]){0}, .count = 0, .capacity = CAPACITY})
#define wapp_c8_array(...) ((C8Array){ \
.items = (c8[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c8, __VA_ARGS__) * 2)]){__VA_ARGS__}, \
.count = wapp_misc_utils_va_args_count(c8, __VA_ARGS__), \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c8, __VA_ARGS__) * 2), \
.item_size = sizeof(c8) \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c8, __VA_ARGS__) * 2) \
})
#define wapp_c8_array_with_capacity(CAPACITY) ((C8Array){.items = (c8[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(c8)})
#define wapp_c8_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((C8Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(c8)))
#define wapp_c8_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
*_c8_array_pop(ARRAY_PTR) : \
(c8){0} \
)
#define wapp_c8_array_with_capacity(CAPACITY) ((C8Array){.items = (c8[CAPACITY]){0}, .count = 0, .capacity = CAPACITY})
#define wapp_c16_array(...) ((C16Array){ \
.items = (c16[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c16, __VA_ARGS__) * 2)]){__VA_ARGS__}, \
.count = wapp_misc_utils_va_args_count(c16, __VA_ARGS__), \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c16, __VA_ARGS__) * 2), \
.item_size = sizeof(c16) \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c16, __VA_ARGS__) * 2) \
})
#define wapp_c16_array_with_capacity(CAPACITY) ((C16Array){.items = (c16[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(c16)})
#define wapp_c16_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((C16Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(c16)))
#define wapp_c16_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
*_c16_array_pop(ARRAY_PTR) : \
(c16){0} \
)
#define wapp_c16_array_with_capacity(CAPACITY) ((C16Array){.items = (c16[CAPACITY]){0}, .count = 0, .capacity = CAPACITY})
#define wapp_c32_array(...) ((C32Array){ \
.items = (c32[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c32, __VA_ARGS__) * 2)]){__VA_ARGS__}, \
.count = wapp_misc_utils_va_args_count(c32, __VA_ARGS__), \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c32, __VA_ARGS__) * 2), \
.item_size = sizeof(c32) \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c32, __VA_ARGS__) * 2) \
})
#define wapp_c32_array_with_capacity(CAPACITY) ((C32Array){.items = (c32[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(c32)})
#define wapp_c32_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((C32Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(c32)))
#define wapp_c32_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
*_c32_array_pop(ARRAY_PTR) : \
(c32){0} \
)
#define wapp_c32_array_with_capacity(CAPACITY) ((C32Array){.items = (c32[CAPACITY]){0}, .count = 0, .capacity = CAPACITY})
#define wapp_i8_array(...) ((I8Array){ \
.items = (i8[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i8, __VA_ARGS__) * 2)]){__VA_ARGS__}, \
.count = wapp_misc_utils_va_args_count(i8, __VA_ARGS__), \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i8, __VA_ARGS__) * 2), \
.item_size = sizeof(i8) \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i8, __VA_ARGS__) * 2) \
})
#define wapp_i8_array_with_capacity(CAPACITY) ((I8Array){.items = (i8[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(i8)})
#define wapp_i8_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((I8Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(i8)))
#define wapp_i8_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
*_i8_array_pop(ARRAY_PTR) : \
(i8){0} \
)
#define wapp_i8_array_with_capacity(CAPACITY) ((I8Array){.items = (i8[CAPACITY]){0}, .count = 0, .capacity = CAPACITY})
#define wapp_i16_array(...) ((I16Array){ \
.items = (i16[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i16, __VA_ARGS__) * 2)]){__VA_ARGS__}, \
.count = wapp_misc_utils_va_args_count(i16, __VA_ARGS__), \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i16, __VA_ARGS__) * 2), \
.item_size = sizeof(i16) \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i16, __VA_ARGS__) * 2) \
})
#define wapp_i16_array_with_capacity(CAPACITY) ((I16Array){.items = (i16[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(i16)})
#define wapp_i16_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((I16Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(i16)))
#define wapp_i16_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
*_i16_array_pop(ARRAY_PTR) : \
(i16){0} \
)
#define wapp_i16_array_with_capacity(CAPACITY) ((I16Array){.items = (i16[CAPACITY]){0}, .count = 0, .capacity = CAPACITY})
#define wapp_i32_array(...) ((I32Array){ \
.items = (i32[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i32, __VA_ARGS__) * 2)]){__VA_ARGS__}, \
.count = wapp_misc_utils_va_args_count(i32, __VA_ARGS__), \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i32, __VA_ARGS__) * 2), \
.item_size = sizeof(i32) \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i32, __VA_ARGS__) * 2) \
})
#define wapp_i32_array_with_capacity(CAPACITY) ((I32Array){.items = (i32[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(i32)})
#define wapp_i32_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((I32Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(i32)))
#define wapp_i32_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
*_i32_array_pop(ARRAY_PTR) : \
(i32){0} \
)
#define wapp_i32_array_with_capacity(CAPACITY) ((I32Array){.items = (i32[CAPACITY]){0}, .count = 0, .capacity = CAPACITY})
#define wapp_i64_array(...) ((I64Array){ \
.items = (i64[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i64, __VA_ARGS__) * 2)]){__VA_ARGS__}, \
.count = wapp_misc_utils_va_args_count(i64, __VA_ARGS__), \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i64, __VA_ARGS__) * 2), \
.item_size = sizeof(i64) \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i64, __VA_ARGS__) * 2) \
})
#define wapp_i64_array_with_capacity(CAPACITY) ((I64Array){.items = (i64[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(i64)})
#define wapp_i64_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((I64Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(i64)))
#define wapp_i64_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
*_i64_array_pop(ARRAY_PTR) : \
(i64){0} \
)
#define wapp_i64_array_with_capacity(CAPACITY) ((I64Array){.items = (i64[CAPACITY]){0}, .count = 0, .capacity = CAPACITY})
#define wapp_u8_array(...) ((U8Array){ \
.items = (u8[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u8, __VA_ARGS__) * 2)]){__VA_ARGS__}, \
.count = wapp_misc_utils_va_args_count(u8, __VA_ARGS__), \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u8, __VA_ARGS__) * 2), \
.item_size = sizeof(u8) \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u8, __VA_ARGS__) * 2) \
})
#define wapp_u8_array_with_capacity(CAPACITY) ((U8Array){.items = (u8[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(u8)})
#define wapp_u8_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((U8Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(u8)))
#define wapp_u8_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
*_u8_array_pop(ARRAY_PTR) : \
(u8){0} \
)
#define wapp_u8_array_with_capacity(CAPACITY) ((U8Array){.items = (u8[CAPACITY]){0}, .count = 0, .capacity = CAPACITY})
#define wapp_u16_array(...) ((U16Array){ \
.items = (u16[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u16, __VA_ARGS__) * 2)]){__VA_ARGS__}, \
.count = wapp_misc_utils_va_args_count(u16, __VA_ARGS__), \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u16, __VA_ARGS__) * 2), \
.item_size = sizeof(u16) \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u16, __VA_ARGS__) * 2) \
})
#define wapp_u16_array_with_capacity(CAPACITY) ((U16Array){.items = (u16[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(u16)})
#define wapp_u16_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((U16Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(u16)))
#define wapp_u16_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
*_u16_array_pop(ARRAY_PTR) : \
(u16){0} \
)
#define wapp_u16_array_with_capacity(CAPACITY) ((U16Array){.items = (u16[CAPACITY]){0}, .count = 0, .capacity = CAPACITY})
#define wapp_u32_array(...) ((U32Array){ \
.items = (u32[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u32, __VA_ARGS__) * 2)]){__VA_ARGS__}, \
.count = wapp_misc_utils_va_args_count(u32, __VA_ARGS__), \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u32, __VA_ARGS__) * 2), \
.item_size = sizeof(u32) \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u32, __VA_ARGS__) * 2) \
})
#define wapp_u32_array_with_capacity(CAPACITY) ((U32Array){.items = (u32[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(u32)})
#define wapp_u32_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((U32Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(u32)))
#define wapp_u32_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
*_u32_array_pop(ARRAY_PTR) : \
(u32){0} \
)
#define wapp_u32_array_with_capacity(CAPACITY) ((U32Array){.items = (u32[CAPACITY]){0}, .count = 0, .capacity = CAPACITY})
#define wapp_u64_array(...) ((U64Array){ \
.items = (u64[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u64, __VA_ARGS__) * 2)]){__VA_ARGS__}, \
.count = wapp_misc_utils_va_args_count(u64, __VA_ARGS__), \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u64, __VA_ARGS__) * 2), \
.item_size = sizeof(u64) \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u64, __VA_ARGS__) * 2) \
})
#define wapp_u64_array_with_capacity(CAPACITY) ((U64Array){.items = (u64[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(u64)})
#define wapp_u64_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((U64Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(u64)))
#define wapp_u64_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
*_u64_array_pop(ARRAY_PTR) : \
(u64){0} \
)
#define wapp_u64_array_with_capacity(CAPACITY) ((U64Array){.items = (u64[CAPACITY]){0}, .count = 0, .capacity = CAPACITY})
#define wapp_f32_array(...) ((F32Array){ \
.items = (f32[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f32, __VA_ARGS__) * 2)]){__VA_ARGS__}, \
.count = wapp_misc_utils_va_args_count(f32, __VA_ARGS__), \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f32, __VA_ARGS__) * 2), \
.item_size = sizeof(f32) \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f32, __VA_ARGS__) * 2) \
})
#define wapp_f32_array_with_capacity(CAPACITY) ((F32Array){.items = (f32[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(f32)})
#define wapp_f32_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((F32Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(f32)))
#define wapp_f32_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
*_f32_array_pop(ARRAY_PTR) : \
(f32){0} \
)
#define wapp_f32_array_with_capacity(CAPACITY) ((F32Array){.items = (f32[CAPACITY]){0}, .count = 0, .capacity = CAPACITY})
#define wapp_f64_array(...) ((F64Array){ \
.items = (f64[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f64, __VA_ARGS__) * 2)]){__VA_ARGS__}, \
.count = wapp_misc_utils_va_args_count(f64, __VA_ARGS__), \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f64, __VA_ARGS__) * 2), \
.item_size = sizeof(f64) \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f64, __VA_ARGS__) * 2) \
})
#define wapp_f64_array_with_capacity(CAPACITY) ((F64Array){.items = (f64[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(f64)})
#define wapp_f64_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((F64Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(f64)))
#define wapp_f64_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
*_f64_array_pop(ARRAY_PTR) : \
(f64){0} \
)
#define wapp_f64_array_with_capacity(CAPACITY) ((F64Array){.items = (f64[CAPACITY]){0}, .count = 0, .capacity = CAPACITY})
#define wapp_f128_array(...) ((F128Array){ \
.items = (f128[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f128, __VA_ARGS__) * 2)]){__VA_ARGS__}, \
.count = wapp_misc_utils_va_args_count(f128, __VA_ARGS__), \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f128, __VA_ARGS__) * 2), \
.item_size = sizeof(f128) \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f128, __VA_ARGS__) * 2) \
})
#define wapp_f128_array_with_capacity(CAPACITY) ((F128Array){.items = (f128[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(f128)})
#define wapp_f128_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((F128Array *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(f128)))
#define wapp_f128_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
*_f128_array_pop(ARRAY_PTR) : \
(f128){0} \
)
#define wapp_f128_array_with_capacity(CAPACITY) ((F128Array){.items = (f128[CAPACITY]){0}, .count = 0, .capacity = CAPACITY})
#define wapp_iptr_array(...) ((IptrArray){ \
.items = (iptr[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(iptr, __VA_ARGS__) * 2)]){__VA_ARGS__}, \
.count = wapp_misc_utils_va_args_count(iptr, __VA_ARGS__), \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(iptr, __VA_ARGS__) * 2), \
.item_size = sizeof(iptr) \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(iptr, __VA_ARGS__) * 2) \
})
#define wapp_iptr_array_with_capacity(CAPACITY) ((IptrArray){.items = (iptr[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(iptr)})
#define wapp_iptr_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((IptrArray *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(iptr)))
#define wapp_iptr_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
*_iptr_array_pop(ARRAY_PTR) : \
(iptr){0} \
)
#define wapp_iptr_array_with_capacity(CAPACITY) ((IptrArray){.items = (iptr[CAPACITY]){0}, .count = 0, .capacity = CAPACITY})
#define wapp_uptr_array(...) ((UptrArray){ \
.items = (uptr[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(uptr, __VA_ARGS__) * 2)]){__VA_ARGS__}, \
.count = wapp_misc_utils_va_args_count(uptr, __VA_ARGS__), \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(uptr, __VA_ARGS__) * 2), \
.item_size = sizeof(uptr) \
.capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(uptr, __VA_ARGS__) * 2) \
})
#define wapp_uptr_array_with_capacity(CAPACITY) ((UptrArray){.items = (uptr[CAPACITY]){0}, .count = 0, .capacity = CAPACITY, .item_size = sizeof(uptr)})
#define wapp_uptr_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY) ((UptrArray *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, sizeof(uptr)))
#define wapp_uptr_array_pop(ARRAY_PTR) (ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
*_uptr_array_pop(ARRAY_PTR) : \
(uptr){0} \
)
typedef struct str8 Str8;
#define wapp_uptr_array_with_capacity(CAPACITY) ((UptrArray){.items = (uptr[CAPACITY]){0}, .count = 0, .capacity = CAPACITY})
typedef struct Str8Array Str8Array;
struct Str8Array {
Str8 *items;
u64 count;
u64 capacity;
u64 item_size;
};
typedef struct VoidPArray VoidPArray;
@ -267,7 +149,6 @@ struct VoidPArray {
void * *items;
u64 count;
u64 capacity;
u64 item_size;
};
typedef struct BoolArray BoolArray;
@ -275,7 +156,6 @@ struct BoolArray {
bool *items;
u64 count;
u64 capacity;
u64 item_size;
};
typedef struct CharArray CharArray;
@ -283,7 +163,6 @@ struct CharArray {
char *items;
u64 count;
u64 capacity;
u64 item_size;
};
typedef struct C8Array C8Array;
@ -291,7 +170,6 @@ struct C8Array {
c8 *items;
u64 count;
u64 capacity;
u64 item_size;
};
typedef struct C16Array C16Array;
@ -299,7 +177,6 @@ struct C16Array {
c16 *items;
u64 count;
u64 capacity;
u64 item_size;
};
typedef struct C32Array C32Array;
@ -307,7 +184,6 @@ struct C32Array {
c32 *items;
u64 count;
u64 capacity;
u64 item_size;
};
typedef struct I8Array I8Array;
@ -315,7 +191,6 @@ struct I8Array {
i8 *items;
u64 count;
u64 capacity;
u64 item_size;
};
typedef struct I16Array I16Array;
@ -323,7 +198,6 @@ struct I16Array {
i16 *items;
u64 count;
u64 capacity;
u64 item_size;
};
typedef struct I32Array I32Array;
@ -331,7 +205,6 @@ struct I32Array {
i32 *items;
u64 count;
u64 capacity;
u64 item_size;
};
typedef struct I64Array I64Array;
@ -339,7 +212,6 @@ struct I64Array {
i64 *items;
u64 count;
u64 capacity;
u64 item_size;
};
typedef struct U8Array U8Array;
@ -347,7 +219,6 @@ struct U8Array {
u8 *items;
u64 count;
u64 capacity;
u64 item_size;
};
typedef struct U16Array U16Array;
@ -355,7 +226,6 @@ struct U16Array {
u16 *items;
u64 count;
u64 capacity;
u64 item_size;
};
typedef struct U32Array U32Array;
@ -363,7 +233,6 @@ struct U32Array {
u32 *items;
u64 count;
u64 capacity;
u64 item_size;
};
typedef struct U64Array U64Array;
@ -371,7 +240,6 @@ struct U64Array {
u64 *items;
u64 count;
u64 capacity;
u64 item_size;
};
typedef struct F32Array F32Array;
@ -379,7 +247,6 @@ struct F32Array {
f32 *items;
u64 count;
u64 capacity;
u64 item_size;
};
typedef struct F64Array F64Array;
@ -387,7 +254,6 @@ struct F64Array {
f64 *items;
u64 count;
u64 capacity;
u64 item_size;
};
typedef struct F128Array F128Array;
@ -395,7 +261,6 @@ struct F128Array {
f128 *items;
u64 count;
u64 capacity;
u64 item_size;
};
typedef struct IptrArray IptrArray;
@ -403,7 +268,6 @@ struct IptrArray {
iptr *items;
u64 count;
u64 capacity;
u64 item_size;
};
typedef struct UptrArray UptrArray;
@ -411,209 +275,231 @@ struct UptrArray {
uptr *items;
u64 count;
u64 capacity;
u64 item_size;
};
Str8 *wapp_str8_array_get(const Str8Array *array, u64 index);
void wapp_str8_array_set(Str8Array *array, u64 index, Str8 *item);
void wapp_str8_array_append_capped(Str8Array *array, Str8 *item);
void wapp_str8_array_set(Str8Array *array, u64 index, Str8 item);
void wapp_str8_array_append_capped(Str8Array *array, Str8 item);
void wapp_str8_array_extend_capped(Str8Array *array, const Str8Array *other);
void wapp_str8_array_clear(Str8Array *array);
Str8 wapp_str8_array_pop(Str8Array *array);
void wapp_str8_array_copy_capped(const Str8Array *src, Str8Array *dst);
Str8Array *wapp_str8_array_append_alloc(const Allocator *allocator, Str8Array *array, Str8 *item);
Str8Array *wapp_str8_array_alloc_capacity(const Allocator *allocator, u64 capacity);
Str8Array *wapp_str8_array_append_alloc(const Allocator *allocator, Str8Array *array, Str8 item);
Str8Array *wapp_str8_array_extend_alloc(const Allocator *allocator, Str8Array *array, const Str8Array *other);
Str8Array *wapp_str8_array_copy_alloc(const Allocator *allocator, const Str8Array *src, Str8Array *dst);
Str8 *_str8_array_pop(Str8Array *array);
void * *wapp_void_ptr_array_get(const VoidPArray *array, u64 index);
void wapp_void_ptr_array_set(VoidPArray *array, u64 index, void * *item);
void wapp_void_ptr_array_append_capped(VoidPArray *array, void * *item);
void wapp_void_ptr_array_set(VoidPArray *array, u64 index, void * item);
void wapp_void_ptr_array_append_capped(VoidPArray *array, void * item);
void wapp_void_ptr_array_extend_capped(VoidPArray *array, const VoidPArray *other);
void wapp_void_ptr_array_clear(VoidPArray *array);
void * wapp_void_ptr_array_pop(VoidPArray *array);
void wapp_void_ptr_array_copy_capped(const VoidPArray *src, VoidPArray *dst);
VoidPArray *wapp_void_ptr_array_append_alloc(const Allocator *allocator, VoidPArray *array, void * *item);
VoidPArray *wapp_void_ptr_array_alloc_capacity(const Allocator *allocator, u64 capacity);
VoidPArray *wapp_void_ptr_array_append_alloc(const Allocator *allocator, VoidPArray *array, void * item);
VoidPArray *wapp_void_ptr_array_extend_alloc(const Allocator *allocator, VoidPArray *array, const VoidPArray *other);
VoidPArray *wapp_void_ptr_array_copy_alloc(const Allocator *allocator, const VoidPArray *src, VoidPArray *dst);
void * *_void_ptr_array_pop(VoidPArray *array);
bool *wapp_bool_array_get(const BoolArray *array, u64 index);
void wapp_bool_array_set(BoolArray *array, u64 index, bool *item);
void wapp_bool_array_append_capped(BoolArray *array, bool *item);
void wapp_bool_array_set(BoolArray *array, u64 index, bool item);
void wapp_bool_array_append_capped(BoolArray *array, bool item);
void wapp_bool_array_extend_capped(BoolArray *array, const BoolArray *other);
void wapp_bool_array_clear(BoolArray *array);
bool wapp_bool_array_pop(BoolArray *array);
void wapp_bool_array_copy_capped(const BoolArray *src, BoolArray *dst);
BoolArray *wapp_bool_array_append_alloc(const Allocator *allocator, BoolArray *array, bool *item);
BoolArray *wapp_bool_array_alloc_capacity(const Allocator *allocator, u64 capacity);
BoolArray *wapp_bool_array_append_alloc(const Allocator *allocator, BoolArray *array, bool item);
BoolArray *wapp_bool_array_extend_alloc(const Allocator *allocator, BoolArray *array, const BoolArray *other);
BoolArray *wapp_bool_array_copy_alloc(const Allocator *allocator, const BoolArray *src, BoolArray *dst);
bool *_bool_array_pop(BoolArray *array);
char *wapp_char_array_get(const CharArray *array, u64 index);
void wapp_char_array_set(CharArray *array, u64 index, char *item);
void wapp_char_array_append_capped(CharArray *array, char *item);
void wapp_char_array_set(CharArray *array, u64 index, char item);
void wapp_char_array_append_capped(CharArray *array, char item);
void wapp_char_array_extend_capped(CharArray *array, const CharArray *other);
void wapp_char_array_clear(CharArray *array);
char wapp_char_array_pop(CharArray *array);
void wapp_char_array_copy_capped(const CharArray *src, CharArray *dst);
CharArray *wapp_char_array_append_alloc(const Allocator *allocator, CharArray *array, char *item);
CharArray *wapp_char_array_alloc_capacity(const Allocator *allocator, u64 capacity);
CharArray *wapp_char_array_append_alloc(const Allocator *allocator, CharArray *array, char item);
CharArray *wapp_char_array_extend_alloc(const Allocator *allocator, CharArray *array, const CharArray *other);
CharArray *wapp_char_array_copy_alloc(const Allocator *allocator, const CharArray *src, CharArray *dst);
char *_char_array_pop(CharArray *array);
c8 *wapp_c8_array_get(const C8Array *array, u64 index);
void wapp_c8_array_set(C8Array *array, u64 index, c8 *item);
void wapp_c8_array_append_capped(C8Array *array, c8 *item);
void wapp_c8_array_set(C8Array *array, u64 index, c8 item);
void wapp_c8_array_append_capped(C8Array *array, c8 item);
void wapp_c8_array_extend_capped(C8Array *array, const C8Array *other);
void wapp_c8_array_clear(C8Array *array);
c8 wapp_c8_array_pop(C8Array *array);
void wapp_c8_array_copy_capped(const C8Array *src, C8Array *dst);
C8Array *wapp_c8_array_append_alloc(const Allocator *allocator, C8Array *array, c8 *item);
C8Array *wapp_c8_array_alloc_capacity(const Allocator *allocator, u64 capacity);
C8Array *wapp_c8_array_append_alloc(const Allocator *allocator, C8Array *array, c8 item);
C8Array *wapp_c8_array_extend_alloc(const Allocator *allocator, C8Array *array, const C8Array *other);
C8Array *wapp_c8_array_copy_alloc(const Allocator *allocator, const C8Array *src, C8Array *dst);
c8 *_c8_array_pop(C8Array *array);
c16 *wapp_c16_array_get(const C16Array *array, u64 index);
void wapp_c16_array_set(C16Array *array, u64 index, c16 *item);
void wapp_c16_array_append_capped(C16Array *array, c16 *item);
void wapp_c16_array_set(C16Array *array, u64 index, c16 item);
void wapp_c16_array_append_capped(C16Array *array, c16 item);
void wapp_c16_array_extend_capped(C16Array *array, const C16Array *other);
void wapp_c16_array_clear(C16Array *array);
c16 wapp_c16_array_pop(C16Array *array);
void wapp_c16_array_copy_capped(const C16Array *src, C16Array *dst);
C16Array *wapp_c16_array_append_alloc(const Allocator *allocator, C16Array *array, c16 *item);
C16Array *wapp_c16_array_alloc_capacity(const Allocator *allocator, u64 capacity);
C16Array *wapp_c16_array_append_alloc(const Allocator *allocator, C16Array *array, c16 item);
C16Array *wapp_c16_array_extend_alloc(const Allocator *allocator, C16Array *array, const C16Array *other);
C16Array *wapp_c16_array_copy_alloc(const Allocator *allocator, const C16Array *src, C16Array *dst);
c16 *_c16_array_pop(C16Array *array);
c32 *wapp_c32_array_get(const C32Array *array, u64 index);
void wapp_c32_array_set(C32Array *array, u64 index, c32 *item);
void wapp_c32_array_append_capped(C32Array *array, c32 *item);
void wapp_c32_array_set(C32Array *array, u64 index, c32 item);
void wapp_c32_array_append_capped(C32Array *array, c32 item);
void wapp_c32_array_extend_capped(C32Array *array, const C32Array *other);
void wapp_c32_array_clear(C32Array *array);
c32 wapp_c32_array_pop(C32Array *array);
void wapp_c32_array_copy_capped(const C32Array *src, C32Array *dst);
C32Array *wapp_c32_array_append_alloc(const Allocator *allocator, C32Array *array, c32 *item);
C32Array *wapp_c32_array_alloc_capacity(const Allocator *allocator, u64 capacity);
C32Array *wapp_c32_array_append_alloc(const Allocator *allocator, C32Array *array, c32 item);
C32Array *wapp_c32_array_extend_alloc(const Allocator *allocator, C32Array *array, const C32Array *other);
C32Array *wapp_c32_array_copy_alloc(const Allocator *allocator, const C32Array *src, C32Array *dst);
c32 *_c32_array_pop(C32Array *array);
i8 *wapp_i8_array_get(const I8Array *array, u64 index);
void wapp_i8_array_set(I8Array *array, u64 index, i8 *item);
void wapp_i8_array_append_capped(I8Array *array, i8 *item);
void wapp_i8_array_set(I8Array *array, u64 index, i8 item);
void wapp_i8_array_append_capped(I8Array *array, i8 item);
void wapp_i8_array_extend_capped(I8Array *array, const I8Array *other);
void wapp_i8_array_clear(I8Array *array);
i8 wapp_i8_array_pop(I8Array *array);
void wapp_i8_array_copy_capped(const I8Array *src, I8Array *dst);
I8Array *wapp_i8_array_append_alloc(const Allocator *allocator, I8Array *array, i8 *item);
I8Array *wapp_i8_array_alloc_capacity(const Allocator *allocator, u64 capacity);
I8Array *wapp_i8_array_append_alloc(const Allocator *allocator, I8Array *array, i8 item);
I8Array *wapp_i8_array_extend_alloc(const Allocator *allocator, I8Array *array, const I8Array *other);
I8Array *wapp_i8_array_copy_alloc(const Allocator *allocator, const I8Array *src, I8Array *dst);
i8 *_i8_array_pop(I8Array *array);
i16 *wapp_i16_array_get(const I16Array *array, u64 index);
void wapp_i16_array_set(I16Array *array, u64 index, i16 *item);
void wapp_i16_array_append_capped(I16Array *array, i16 *item);
void wapp_i16_array_set(I16Array *array, u64 index, i16 item);
void wapp_i16_array_append_capped(I16Array *array, i16 item);
void wapp_i16_array_extend_capped(I16Array *array, const I16Array *other);
void wapp_i16_array_clear(I16Array *array);
i16 wapp_i16_array_pop(I16Array *array);
void wapp_i16_array_copy_capped(const I16Array *src, I16Array *dst);
I16Array *wapp_i16_array_append_alloc(const Allocator *allocator, I16Array *array, i16 *item);
I16Array *wapp_i16_array_alloc_capacity(const Allocator *allocator, u64 capacity);
I16Array *wapp_i16_array_append_alloc(const Allocator *allocator, I16Array *array, i16 item);
I16Array *wapp_i16_array_extend_alloc(const Allocator *allocator, I16Array *array, const I16Array *other);
I16Array *wapp_i16_array_copy_alloc(const Allocator *allocator, const I16Array *src, I16Array *dst);
i16 *_i16_array_pop(I16Array *array);
i32 *wapp_i32_array_get(const I32Array *array, u64 index);
void wapp_i32_array_set(I32Array *array, u64 index, i32 *item);
void wapp_i32_array_append_capped(I32Array *array, i32 *item);
void wapp_i32_array_set(I32Array *array, u64 index, i32 item);
void wapp_i32_array_append_capped(I32Array *array, i32 item);
void wapp_i32_array_extend_capped(I32Array *array, const I32Array *other);
void wapp_i32_array_clear(I32Array *array);
i32 wapp_i32_array_pop(I32Array *array);
void wapp_i32_array_copy_capped(const I32Array *src, I32Array *dst);
I32Array *wapp_i32_array_append_alloc(const Allocator *allocator, I32Array *array, i32 *item);
I32Array *wapp_i32_array_alloc_capacity(const Allocator *allocator, u64 capacity);
I32Array *wapp_i32_array_append_alloc(const Allocator *allocator, I32Array *array, i32 item);
I32Array *wapp_i32_array_extend_alloc(const Allocator *allocator, I32Array *array, const I32Array *other);
I32Array *wapp_i32_array_copy_alloc(const Allocator *allocator, const I32Array *src, I32Array *dst);
i32 *_i32_array_pop(I32Array *array);
i64 *wapp_i64_array_get(const I64Array *array, u64 index);
void wapp_i64_array_set(I64Array *array, u64 index, i64 *item);
void wapp_i64_array_append_capped(I64Array *array, i64 *item);
void wapp_i64_array_set(I64Array *array, u64 index, i64 item);
void wapp_i64_array_append_capped(I64Array *array, i64 item);
void wapp_i64_array_extend_capped(I64Array *array, const I64Array *other);
void wapp_i64_array_clear(I64Array *array);
i64 wapp_i64_array_pop(I64Array *array);
void wapp_i64_array_copy_capped(const I64Array *src, I64Array *dst);
I64Array *wapp_i64_array_append_alloc(const Allocator *allocator, I64Array *array, i64 *item);
I64Array *wapp_i64_array_alloc_capacity(const Allocator *allocator, u64 capacity);
I64Array *wapp_i64_array_append_alloc(const Allocator *allocator, I64Array *array, i64 item);
I64Array *wapp_i64_array_extend_alloc(const Allocator *allocator, I64Array *array, const I64Array *other);
I64Array *wapp_i64_array_copy_alloc(const Allocator *allocator, const I64Array *src, I64Array *dst);
i64 *_i64_array_pop(I64Array *array);
u8 *wapp_u8_array_get(const U8Array *array, u64 index);
void wapp_u8_array_set(U8Array *array, u64 index, u8 *item);
void wapp_u8_array_append_capped(U8Array *array, u8 *item);
void wapp_u8_array_set(U8Array *array, u64 index, u8 item);
void wapp_u8_array_append_capped(U8Array *array, u8 item);
void wapp_u8_array_extend_capped(U8Array *array, const U8Array *other);
void wapp_u8_array_clear(U8Array *array);
u8 wapp_u8_array_pop(U8Array *array);
void wapp_u8_array_copy_capped(const U8Array *src, U8Array *dst);
U8Array *wapp_u8_array_append_alloc(const Allocator *allocator, U8Array *array, u8 *item);
U8Array *wapp_u8_array_alloc_capacity(const Allocator *allocator, u64 capacity);
U8Array *wapp_u8_array_append_alloc(const Allocator *allocator, U8Array *array, u8 item);
U8Array *wapp_u8_array_extend_alloc(const Allocator *allocator, U8Array *array, const U8Array *other);
U8Array *wapp_u8_array_copy_alloc(const Allocator *allocator, const U8Array *src, U8Array *dst);
u8 *_u8_array_pop(U8Array *array);
u16 *wapp_u16_array_get(const U16Array *array, u64 index);
void wapp_u16_array_set(U16Array *array, u64 index, u16 *item);
void wapp_u16_array_append_capped(U16Array *array, u16 *item);
void wapp_u16_array_set(U16Array *array, u64 index, u16 item);
void wapp_u16_array_append_capped(U16Array *array, u16 item);
void wapp_u16_array_extend_capped(U16Array *array, const U16Array *other);
void wapp_u16_array_clear(U16Array *array);
u16 wapp_u16_array_pop(U16Array *array);
void wapp_u16_array_copy_capped(const U16Array *src, U16Array *dst);
U16Array *wapp_u16_array_append_alloc(const Allocator *allocator, U16Array *array, u16 *item);
U16Array *wapp_u16_array_alloc_capacity(const Allocator *allocator, u64 capacity);
U16Array *wapp_u16_array_append_alloc(const Allocator *allocator, U16Array *array, u16 item);
U16Array *wapp_u16_array_extend_alloc(const Allocator *allocator, U16Array *array, const U16Array *other);
U16Array *wapp_u16_array_copy_alloc(const Allocator *allocator, const U16Array *src, U16Array *dst);
u16 *_u16_array_pop(U16Array *array);
u32 *wapp_u32_array_get(const U32Array *array, u64 index);
void wapp_u32_array_set(U32Array *array, u64 index, u32 *item);
void wapp_u32_array_append_capped(U32Array *array, u32 *item);
void wapp_u32_array_set(U32Array *array, u64 index, u32 item);
void wapp_u32_array_append_capped(U32Array *array, u32 item);
void wapp_u32_array_extend_capped(U32Array *array, const U32Array *other);
void wapp_u32_array_clear(U32Array *array);
u32 wapp_u32_array_pop(U32Array *array);
void wapp_u32_array_copy_capped(const U32Array *src, U32Array *dst);
U32Array *wapp_u32_array_append_alloc(const Allocator *allocator, U32Array *array, u32 *item);
U32Array *wapp_u32_array_alloc_capacity(const Allocator *allocator, u64 capacity);
U32Array *wapp_u32_array_append_alloc(const Allocator *allocator, U32Array *array, u32 item);
U32Array *wapp_u32_array_extend_alloc(const Allocator *allocator, U32Array *array, const U32Array *other);
U32Array *wapp_u32_array_copy_alloc(const Allocator *allocator, const U32Array *src, U32Array *dst);
u32 *_u32_array_pop(U32Array *array);
u64 *wapp_u64_array_get(const U64Array *array, u64 index);
void wapp_u64_array_set(U64Array *array, u64 index, u64 *item);
void wapp_u64_array_append_capped(U64Array *array, u64 *item);
void wapp_u64_array_set(U64Array *array, u64 index, u64 item);
void wapp_u64_array_append_capped(U64Array *array, u64 item);
void wapp_u64_array_extend_capped(U64Array *array, const U64Array *other);
void wapp_u64_array_clear(U64Array *array);
u64 wapp_u64_array_pop(U64Array *array);
void wapp_u64_array_copy_capped(const U64Array *src, U64Array *dst);
U64Array *wapp_u64_array_append_alloc(const Allocator *allocator, U64Array *array, u64 *item);
U64Array *wapp_u64_array_alloc_capacity(const Allocator *allocator, u64 capacity);
U64Array *wapp_u64_array_append_alloc(const Allocator *allocator, U64Array *array, u64 item);
U64Array *wapp_u64_array_extend_alloc(const Allocator *allocator, U64Array *array, const U64Array *other);
U64Array *wapp_u64_array_copy_alloc(const Allocator *allocator, const U64Array *src, U64Array *dst);
u64 *_u64_array_pop(U64Array *array);
f32 *wapp_f32_array_get(const F32Array *array, u64 index);
void wapp_f32_array_set(F32Array *array, u64 index, f32 *item);
void wapp_f32_array_append_capped(F32Array *array, f32 *item);
void wapp_f32_array_set(F32Array *array, u64 index, f32 item);
void wapp_f32_array_append_capped(F32Array *array, f32 item);
void wapp_f32_array_extend_capped(F32Array *array, const F32Array *other);
void wapp_f32_array_clear(F32Array *array);
f32 wapp_f32_array_pop(F32Array *array);
void wapp_f32_array_copy_capped(const F32Array *src, F32Array *dst);
F32Array *wapp_f32_array_append_alloc(const Allocator *allocator, F32Array *array, f32 *item);
F32Array *wapp_f32_array_alloc_capacity(const Allocator *allocator, u64 capacity);
F32Array *wapp_f32_array_append_alloc(const Allocator *allocator, F32Array *array, f32 item);
F32Array *wapp_f32_array_extend_alloc(const Allocator *allocator, F32Array *array, const F32Array *other);
F32Array *wapp_f32_array_copy_alloc(const Allocator *allocator, const F32Array *src, F32Array *dst);
f32 *_f32_array_pop(F32Array *array);
f64 *wapp_f64_array_get(const F64Array *array, u64 index);
void wapp_f64_array_set(F64Array *array, u64 index, f64 *item);
void wapp_f64_array_append_capped(F64Array *array, f64 *item);
void wapp_f64_array_set(F64Array *array, u64 index, f64 item);
void wapp_f64_array_append_capped(F64Array *array, f64 item);
void wapp_f64_array_extend_capped(F64Array *array, const F64Array *other);
void wapp_f64_array_clear(F64Array *array);
f64 wapp_f64_array_pop(F64Array *array);
void wapp_f64_array_copy_capped(const F64Array *src, F64Array *dst);
F64Array *wapp_f64_array_append_alloc(const Allocator *allocator, F64Array *array, f64 *item);
F64Array *wapp_f64_array_alloc_capacity(const Allocator *allocator, u64 capacity);
F64Array *wapp_f64_array_append_alloc(const Allocator *allocator, F64Array *array, f64 item);
F64Array *wapp_f64_array_extend_alloc(const Allocator *allocator, F64Array *array, const F64Array *other);
F64Array *wapp_f64_array_copy_alloc(const Allocator *allocator, const F64Array *src, F64Array *dst);
f64 *_f64_array_pop(F64Array *array);
f128 *wapp_f128_array_get(const F128Array *array, u64 index);
void wapp_f128_array_set(F128Array *array, u64 index, f128 *item);
void wapp_f128_array_append_capped(F128Array *array, f128 *item);
void wapp_f128_array_set(F128Array *array, u64 index, f128 item);
void wapp_f128_array_append_capped(F128Array *array, f128 item);
void wapp_f128_array_extend_capped(F128Array *array, const F128Array *other);
void wapp_f128_array_clear(F128Array *array);
f128 wapp_f128_array_pop(F128Array *array);
void wapp_f128_array_copy_capped(const F128Array *src, F128Array *dst);
F128Array *wapp_f128_array_append_alloc(const Allocator *allocator, F128Array *array, f128 *item);
F128Array *wapp_f128_array_alloc_capacity(const Allocator *allocator, u64 capacity);
F128Array *wapp_f128_array_append_alloc(const Allocator *allocator, F128Array *array, f128 item);
F128Array *wapp_f128_array_extend_alloc(const Allocator *allocator, F128Array *array, const F128Array *other);
F128Array *wapp_f128_array_copy_alloc(const Allocator *allocator, const F128Array *src, F128Array *dst);
f128 *_f128_array_pop(F128Array *array);
iptr *wapp_iptr_array_get(const IptrArray *array, u64 index);
void wapp_iptr_array_set(IptrArray *array, u64 index, iptr *item);
void wapp_iptr_array_append_capped(IptrArray *array, iptr *item);
void wapp_iptr_array_set(IptrArray *array, u64 index, iptr item);
void wapp_iptr_array_append_capped(IptrArray *array, iptr item);
void wapp_iptr_array_extend_capped(IptrArray *array, const IptrArray *other);
void wapp_iptr_array_clear(IptrArray *array);
iptr wapp_iptr_array_pop(IptrArray *array);
void wapp_iptr_array_copy_capped(const IptrArray *src, IptrArray *dst);
IptrArray *wapp_iptr_array_append_alloc(const Allocator *allocator, IptrArray *array, iptr *item);
IptrArray *wapp_iptr_array_alloc_capacity(const Allocator *allocator, u64 capacity);
IptrArray *wapp_iptr_array_append_alloc(const Allocator *allocator, IptrArray *array, iptr item);
IptrArray *wapp_iptr_array_extend_alloc(const Allocator *allocator, IptrArray *array, const IptrArray *other);
IptrArray *wapp_iptr_array_copy_alloc(const Allocator *allocator, const IptrArray *src, IptrArray *dst);
iptr *_iptr_array_pop(IptrArray *array);
uptr *wapp_uptr_array_get(const UptrArray *array, u64 index);
void wapp_uptr_array_set(UptrArray *array, u64 index, uptr *item);
void wapp_uptr_array_append_capped(UptrArray *array, uptr *item);
void wapp_uptr_array_set(UptrArray *array, u64 index, uptr item);
void wapp_uptr_array_append_capped(UptrArray *array, uptr item);
void wapp_uptr_array_extend_capped(UptrArray *array, const UptrArray *other);
void wapp_uptr_array_clear(UptrArray *array);
uptr wapp_uptr_array_pop(UptrArray *array);
void wapp_uptr_array_copy_capped(const UptrArray *src, UptrArray *dst);
UptrArray *wapp_uptr_array_append_alloc(const Allocator *allocator, UptrArray *array, uptr *item);
UptrArray *wapp_uptr_array_alloc_capacity(const Allocator *allocator, u64 capacity);
UptrArray *wapp_uptr_array_append_alloc(const Allocator *allocator, UptrArray *array, uptr item);
UptrArray *wapp_uptr_array_extend_alloc(const Allocator *allocator, UptrArray *array, const UptrArray *other);
UptrArray *wapp_uptr_array_copy_alloc(const Allocator *allocator, const UptrArray *src, UptrArray *dst);
uptr *_uptr_array_pop(UptrArray *array);
VoidPArray *_array_alloc_capacity(const Allocator *allocator, u64 capacity, u64 item_size);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // !WAPP_PLATFORM_CPP
#endif // !ARRAY_H

File diff suppressed because it is too large Load Diff

View File

@ -9,6 +9,10 @@
#include "../../common/platform/platform.h"
#include <stdbool.h>
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // !WAPP_PLATFORM_CPP
#define wapp_str8_list_node(ITEM_PTR) ((Str8Node){.item = ITEM_PTR})
#define wapp_void_ptr_list_node(ITEM_PTR) ((VoidPNode){.item = ITEM_PTR})
#define wapp_bool_list_node(ITEM_PTR) ((BoolNode){.item = ITEM_PTR})
@ -473,4 +477,8 @@ UptrNode *wapp_uptr_list_pop_back(UptrList *list);
UptrNode *wapp_uptr_list_remove(UptrList *list, u64 index);
void wapp_uptr_list_empty(UptrList *list);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // !WAPP_PLATFORM_CPP
#endif // !DBL_LIST_H

View File

@ -1,26 +1,37 @@
#include "mem_allocator.h"
#include "../../common/aliases/aliases.h"
#include <stdlib.h>
#include <assert.h>
void *wapp_mem_allocator_alloc(const Allocator *allocator, u64 size) {
assert(allocator != NULL && (allocator->alloc) != NULL);
if (!allocator || !(allocator->alloc)) {
return 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);
if (!allocator || !(allocator->alloc_aligned)) {
return 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);
if (!allocator || !(allocator->realloc)) {
return 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);
if (!allocator || !(allocator->realloc_aligned)) {
return NULL;
}
return allocator->realloc_aligned(ptr, old_size, new_size, alignment, allocator->obj);
}

View File

@ -5,12 +5,17 @@
#include "../../common/platform/platform.h"
#include <string.h>
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
typedef void *(MemAllocFunc)(u64 size, void *alloc_obj);
typedef void *(MemAllocAlignedFunc)(u64 size, u64 alignment, void *alloc_obj);
typedef void *(MemReallocFunc)(void *ptr, u64 old_size, u64 new_size, void *alloc_obj);
typedef void *(MemReallocAlignedFunc)(void *ptr, u64 old_size, u64 new_size, u64 alignment, void *alloc_obj);
typedef void (MemFreeFunc)(void **ptr, u64 size, void *alloc_obj);
typedef struct allocator Allocator;
struct allocator {
void *obj;
@ -23,6 +28,7 @@ struct allocator {
#define wapp_mem_allocator_invalid(ALLOCATOR) (memcmp(ALLOCATOR, &((Allocator){0}), sizeof(Allocator)) == 0)
void *wapp_mem_allocator_alloc(const Allocator *allocator, u64 size);
void *wapp_mem_allocator_alloc_aligned(const Allocator *allocator, u64 size, u64 alignment);
void *wapp_mem_allocator_realloc(const Allocator *allocator, void *ptr, u64 old_size, u64 new_size);
@ -30,4 +36,8 @@ void *wapp_mem_allocator_realloc_aligned(const Allocator *allocator, void *ptr,
u64 new_size, u64 alignment);
void wapp_mem_allocator_free(const Allocator *allocator, void **ptr, u64 size);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !MEM_ALLOCATOR_H

View File

@ -6,14 +6,17 @@
#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);
Str8 *str = NULL;
Str8 *str = wapp_mem_allocator_alloc(allocator, STR8_BUF_ALLOC_SIZE(capacity));
if (!allocator) {
goto RETURN_STR8;
}
str = wapp_mem_allocator_alloc(allocator, STR8_BUF_ALLOC_SIZE(capacity));
if (!str) {
goto RETURN_STR8;
}
@ -27,10 +30,14 @@ RETURN_STR8:
}
Str8 *wapp_str8_alloc_cstr(const Allocator *allocator, const char *str) {
assert(allocator != NULL && str != NULL);
Str8 *output = NULL;
if (!allocator || !str) {
goto RETURN_ALLOC_CSTR;
}
u64 length = strlen(str);
Str8 *output = wapp_str8_alloc_buf(allocator, length * 2);
output = wapp_str8_alloc_buf(allocator, length * 2);
if (!output) {
goto RETURN_ALLOC_CSTR;
}
@ -43,9 +50,13 @@ RETURN_ALLOC_CSTR:
}
Str8 *wapp_str8_alloc_str8(const Allocator *allocator, Str8RO *str) {
assert(allocator != NULL && str != NULL);
Str8 *output = NULL;
Str8 *output = wapp_str8_alloc_buf(allocator, str->capacity);
if (!allocator || !str) {
goto RETURN_ALLOC_STR8;
}
output = wapp_str8_alloc_buf(allocator, str->capacity);
if (!output) {
goto RETURN_ALLOC_STR8;
}
@ -58,9 +69,10 @@ RETURN_ALLOC_STR8:
}
Str8 *wapp_str8_alloc_substr(const Allocator *allocator, Str8RO *str, u64 start, u64 end) {
assert(allocator != NULL && str != NULL);
Str8 *output = NULL;
if (!allocator || !str) {
goto RETURN_ALLOC_SUBSTR;
}
if (start >= str->size || start >= end) {
goto RETURN_ALLOC_SUBSTR;
@ -83,7 +95,10 @@ RETURN_ALLOC_SUBSTR:
}
void wapp_str8_dealloc_buf(const Allocator *allocator, Str8 **str) {
assert(allocator != NULL && str != NULL && (*str) != NULL);
if (!allocator || !str || !(*str)) {
return;
}
wapp_mem_allocator_free(allocator, (void **)str, STR8_BUF_ALLOC_SIZE((*str)->capacity));
}
@ -121,11 +136,11 @@ bool wapp_str8_equal(Str8RO *s1, Str8RO *s2) {
}
bool wapp_str8_equal_to_count(Str8RO* s1, Str8RO* s2, u64 count) {
if (!s1 || !s2) {
return false;
}
if (!s1 || !s2) {
return false;
}
return memcmp(s1->buf, s2->buf, count) == 0;
return memcmp(s1->buf, s2->buf, count) == 0;
}
Str8 wapp_str8_slice(Str8RO *str, u64 start, u64 end) {
@ -146,7 +161,9 @@ 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);
if (!allocator || !dst || !src) {
return NULL;
}
Str8 *output = NULL;
u64 remaining = dst->capacity - dst->size;
@ -172,7 +189,9 @@ RETURN_STR8_CONCAT:
}
void wapp_str8_concat_capped(Str8 *dst, Str8RO *src) {
assert(dst != NULL && src != NULL);
if (!dst || !src) {
return;
}
u64 remaining = dst->capacity - dst->size;
u64 to_copy = remaining < src->size ? remaining : src->size;
@ -182,7 +201,9 @@ 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);
if (!dst || !src) {
return;
}
u64 length = strlen(src);
u64 to_copy = length <= dst->capacity ? length : dst->capacity;
@ -193,7 +214,9 @@ 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);
if (!dst || !src) {
return;
}
u64 to_copy = src->size <= dst->capacity ? src->size : dst->capacity;
@ -203,7 +226,9 @@ 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);
if (!dst || !src) {
return;
}
u64 to_copy = src->size < dst_capacity ? src->size : dst_capacity - 1;
@ -212,7 +237,9 @@ 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);
if (!dst || !format) {
return;
}
va_list args1;
va_list args2;
@ -237,7 +264,7 @@ i64 wapp_str8_find(Str8RO *str, Str8RO substr) {
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
// MSVC Spectre mitigation warnings
u64 char_index = 0;
bool running = char_index < str->size;
bool running = true;
while (running) {
const c8 *sub = str->buf + char_index;
if (memcmp(sub, substr.buf, substr.size) == 0) {
@ -259,7 +286,7 @@ i64 wapp_str8_rfind(Str8RO *str, Str8RO substr) {
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
// MSVC Spectre mitigation warnings
i64 char_index = str->size - substr.size;
bool running = char_index >= 0;
bool running = true;
while (running) {
const c8 *sub = str->buf + char_index;
if (memcmp(sub, substr.buf, substr.size) == 0) {
@ -274,7 +301,9 @@ 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);
if (!allocator || !str || !delimiter) {
return NULL;
}
Str8List *output = wapp_mem_allocator_alloc(allocator, sizeof(Str8List));
@ -302,7 +331,7 @@ Str8List *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8
before_str = wapp_str8_alloc_substr(allocator, str, start, start + end);
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
if (node && before_str) {
if (node) {
node->item = before_str;
wapp_str8_list_push_back(output, node);
}
@ -317,7 +346,7 @@ Str8List *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8
// Ensure the last part of the string after the delimiter is added to the list
rest = wapp_str8_alloc_substr(allocator, str, start, str->size);
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
if (node && rest) {
if (node) {
node->item = rest;
wapp_str8_list_push_back(output, node);
}
@ -327,14 +356,16 @@ 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);
if (!allocator || !str || !delimiter) {
return NULL;
}
Str8List *output = wapp_mem_allocator_alloc(allocator, sizeof(Str8List));
if (delimiter->size > str->size) {
Str8 *full = wapp_str8_alloc_str8(allocator, str);
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
if (node && full) {
if (node) {
node->item = full;
wapp_str8_list_push_back(output, node);
}
@ -367,7 +398,7 @@ Str8List *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str
rest = wapp_str8_alloc_substr(allocator, str, 0, rest->size);
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
if (node && rest) {
if (node) {
node->item = rest;
wapp_str8_list_push_front(output, node);
}
@ -377,7 +408,9 @@ RETURN_STR8_SPLIT:
}
Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8RO *delimiter) {
assert(allocator != NULL && list != NULL && delimiter != NULL);
if (!allocator || !list || !delimiter) {
return NULL;
}
u64 capacity = wapp_str8_list_total_size(list) + (delimiter->size * (list->node_count - 1));
Str8 *output = wapp_str8_alloc_buf(allocator, capacity * 2);
@ -386,7 +419,7 @@ Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8RO *d
// MSVC Spectre mitigation warnings
Str8Node *node;
u64 node_index = 0;
bool running = node_index < list->node_count;
bool running = true;
while (running) {
node = wapp_str8_list_get(list, node_index);
if (!node) {
@ -419,7 +452,7 @@ u64 wapp_str8_list_total_size(const Str8List *list) {
Str8Node* node;
u64 node_index = 0;
u64 output = 0;
bool running = node_index < list->node_count;
bool running = true;
while (running) {
node = wapp_str8_list_get(list, node_index);
if (!node) {

View File

@ -8,6 +8,10 @@
#include <string.h>
#include <stdbool.h>
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // !WAPP_PLATFORM_CPP
typedef struct str8 Str8;
struct str8 {
u64 capacity;
@ -92,4 +96,8 @@ Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8R
#define wapp_str8_node_from_str8(STRING) wapp_str8_list_node(&(STRING))
u64 wapp_str8_list_total_size(const Str8List *list);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // !WAPP_PLATFORM_CPP
#endif // !STR8_H

View File

@ -88,12 +88,12 @@ internal u64 split_mix_64(SplitMix64State *state) {
return result ^ (result >> 31);
}
#if defined(WAPP_PLATFORM_C) && WAPP_PLATFORM_C_VERSION >= WAPP_PLATFORM_C11_VERSION
#if defined(WAPP_PLATFORM_CPP) || (defined(WAPP_PLATFORM_C) && WAPP_PLATFORM_C_VERSION >= WAPP_PLATFORM_C11_VERSION)
#ifdef WAPP_PLATFORM_POSIX
internal void seed_os_generator(void) {
struct timespec ts = {0};
int result = clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
assert(result == 0);
assert(result == 0 && "Failed to get time");
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);
assert(result != 0 && "Failed to get time");
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));
assert(result != (time_t)(-1) && "Failed to get time");
srand(result);
}
@ -131,4 +131,4 @@ internal u64 generate_random_number(void) {
return (((u64)n1) << 32 | (u64)n2);
}
#endif // !WAPP_PLATFORM_C
#endif // !WAPP_PLATFORM_CPP

View File

@ -4,6 +4,10 @@
#include "../../common/aliases/aliases.h"
#include "../../common/platform/platform.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
typedef struct xor_256_state XOR256State;
struct xor_256_state {
u64 x;
@ -17,4 +21,8 @@ u64 wapp_prng_xorshift_256(XOR256State *state);
u64 wapp_prng_xorshift_256ss(XOR256State *state);
u64 wapp_prng_xorshift_256p(XOR256State *state);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !XORSHIFT_H

View File

@ -6,6 +6,10 @@
#include "../../primitives/strings/str8/str8.h"
#include <stdbool.h>
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#define wapp_tester_result(PASSED) ((TestFuncResult){.name = wapp_str8_lit_ro(__func__), .passed = PASSED})
#define wapp_tester_run_tests(...) run_tests(__VA_ARGS__, NULL)
@ -23,4 +27,8 @@ typedef TestFuncResult(TestFunc)(void);
void run_tests(TestFunc *func1, ...);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !TESTER_H

View File

@ -4,7 +4,6 @@
#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)
@ -18,12 +17,15 @@ 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);
if (!uuid) {
goto RETURN_INIT_UUID4;
}
UUID4 uuid4 = generate_uuid4();
uuid4_to_uuid(&uuid4, uuid);
return uuid;
RETURN_INIT_UUID4:
return uuid;
}
internal UUID4 generate_uuid4(void) {

View File

@ -5,6 +5,10 @@
#include "../common/platform/platform.h"
#include "../primitives/strings/str8/str8.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#define UUID_BUF_LENGTH 48
#define WAPP_UUID_SPEC WAPP_STR8_SPEC
#define wapp_uuid_varg(UUID) wapp_str8_varg((UUID).uuid)
@ -21,7 +25,11 @@ 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.
// Fails when passed a NULL pointer.
// If the pointer is NULL, it skips initialisation.
UUID *wapp_uuid_init_uuid4(UUID *uuid);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !UUID_H

View File

@ -2,7 +2,7 @@
#define WAPP_UUID_C
#include "uuid.c"
#include "../primitives/wapp_primitives.c"
#include "../core/wapp_core.c"
#include "../prng/wapp_prng.c"
#endif // !WAPP_UUID_C

View File

@ -3,7 +3,7 @@
#include "uuid.h"
#include "../common/wapp_common.h"
#include "../primitives/wapp_primitives.h"
#include "../core/wapp_core.h"
#include "../prng/wapp_prng.h"
#endif // !WAPP_UUID_H

View File

@ -3,6 +3,14 @@
#include "wapp.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
TestFuncResult test_arena_allocator(void);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !TEST_ALLOCATOR_H

View File

@ -3,6 +3,10 @@
#include "wapp.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
TestFuncResult test_arena_init(void);
TestFuncResult test_arena_init_succeeds_when_reserving_very_large_size(void);
TestFuncResult test_arena_alloc_succeeds_when_within_capacity(void);
@ -12,4 +16,8 @@ TestFuncResult test_arena_realloc_smaller_size(void);
TestFuncResult test_arena_clear(void);
TestFuncResult test_arena_destroy(void);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !TEST_ARENA_H

View File

@ -62,8 +62,7 @@ TestFuncResult test_i32_array_set(void) {
u64 index = 0;
bool running = true;
while (running) {
i32 num = (i32)(index * 2);
wapp_i32_array_set(&array, index, &num);
wapp_i32_array_set(&array, index, (i32)(index * 2));
item = wapp_i32_array_get(&array, index);
result = result && item && (*item == (i32)(index * 2));
@ -78,14 +77,15 @@ TestFuncResult test_i32_array_append_capped(void) {
bool result;
I32Array array = wapp_i32_array_with_capacity(64);
wapp_i32_array_append_capped(&array, &((i32){10}));
wapp_i32_array_append_capped(&array, 10);
result = array.count == 1;
i32 *item = wapp_i32_array_get(&array, 0);
result = result && item && *item == 10;
array = wapp_i32_array(1);
wapp_i32_array_append_capped(&array, &((i32){10}));
wapp_i32_array_append_capped(&array, 10);
wapp_i32_array_append_capped(&array, 20);
result = result && array.count == 2;
@ -104,6 +104,10 @@ TestFuncResult test_i32_array_extend_capped(void) {
result = result && array1.count == 6;
wapp_i32_array_extend_capped(&array1, &array1);
result = result && array1.count == 6;
return wapp_tester_result(result);
}
@ -191,15 +195,14 @@ TestFuncResult test_i32_array_append_alloc(void) {
I32Array array1 = wapp_i32_array(1, 2, 3, 4, 5, 6, 7, 8);
I32Array array2 = wapp_i32_array(1, 2);
I32Array *arr_ptr = wapp_i32_array_append_alloc(&allocator, &array1, &((i32){10}));
I32Array *arr_ptr = wapp_i32_array_append_alloc(&allocator, &array1, 10);
result = arr_ptr == &array1;
u64 count = 4;
u64 index = 0;
bool running = true;
while (running) {
i32 num = (i32)index;
arr_ptr = wapp_i32_array_append_alloc(&allocator, &array2, &num);
arr_ptr = wapp_i32_array_append_alloc(&allocator, &array2, (i32)index);
++index;
running = index < count;

View File

@ -3,6 +3,10 @@
#include "wapp.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
TestFuncResult test_i32_array(void);
TestFuncResult test_i32_array_with_capacity(void);
TestFuncResult test_i32_array_get(void);
@ -17,4 +21,8 @@ TestFuncResult test_i32_array_append_alloc(void);
TestFuncResult test_i32_array_extend_alloc(void);
TestFuncResult test_i32_array_copy_alloc(void);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !TEST_INT_ARRAY_H

View File

@ -3,8 +3,16 @@
#include "wapp.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
TestFuncResult test_cpath_join_path(void);
TestFuncResult test_cpath_dirname(void);
TestFuncResult test_cpath_dirup(void);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !TEST_CPATH_H

View File

@ -3,9 +3,17 @@
#include "wapp.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
TestFuncResult test_commander_cmd_success(void);
TestFuncResult test_commander_cmd_failure(void);
TestFuncResult test_commander_cmd_out_buf_success(void);
TestFuncResult test_commander_cmd_out_buf_failure(void);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !TEST_SHELL_COMMANDER_H

View File

@ -3,6 +3,10 @@
#include "wapp.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
TestFuncResult test_str8_lit(void);
TestFuncResult test_str8_lit_ro(void);
TestFuncResult test_str8_buf(void);
@ -29,4 +33,8 @@ TestFuncResult test_str8_rsplit(void);
TestFuncResult test_str8_rsplit_with_max(void);
TestFuncResult test_str8_join(void);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !TEST_STR8_H

View File

@ -3,6 +3,10 @@
#include "wapp.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
TestFuncResult test_str8_list_get(void);
TestFuncResult test_str8_list_push_front(void);
TestFuncResult test_str8_list_push_back(void);
@ -12,4 +16,8 @@ TestFuncResult test_str8_list_pop_back(void);
TestFuncResult test_str8_list_remove(void);
TestFuncResult test_str8_list_empty(void);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !TEST_STR8_LIST_H