Use asserts in array
This commit is contained in:
parent
cac66b9dbb
commit
6c8434a530
@ -100,7 +100,11 @@ 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")],
|
||||
includes=[
|
||||
CInclude(header, local=True, same_dir=True),
|
||||
CInclude(header="stddef.h"),
|
||||
CInclude(header="assert.h"),
|
||||
],
|
||||
internal_funcs=[],
|
||||
funcs=header.funcs
|
||||
)
|
||||
|
@ -1,11 +1,7 @@
|
||||
assert(allocator != NULL);
|
||||
|
||||
u64 allocation_size = sizeof({ArrayType}) + item_size * capacity;
|
||||
{ArrayType} *array = NULL;
|
||||
|
||||
if (!allocator) {{
|
||||
goto RETURN_GENERIC_ARRAY_ALLOC;
|
||||
}}
|
||||
|
||||
array = wapp_mem_allocator_alloc(allocator, allocation_size);
|
||||
{ArrayType} *array = wapp_mem_allocator_alloc(allocator, allocation_size);
|
||||
if (!array) {{
|
||||
goto RETURN_GENERIC_ARRAY_ALLOC;
|
||||
}}
|
||||
|
@ -1,8 +1,6 @@
|
||||
{ArrayType} *output = array;
|
||||
assert(allocator != NULL && array != NULL);
|
||||
|
||||
if (!allocator || !array) {{
|
||||
goto RETURN_{Tupper}_ARRAY_APPEND_ALLOC;
|
||||
}}
|
||||
{ArrayType} *output = array;
|
||||
|
||||
if (array->count >= array->capacity) {{
|
||||
u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2);
|
||||
|
@ -1,6 +1,4 @@
|
||||
if (!array || array->count >= array->capacity) {{
|
||||
return;
|
||||
}}
|
||||
assert(array != NULL && array->count < array->capacity);
|
||||
|
||||
u64 index = (array->count)++;
|
||||
wapp_{Tlower}_array_set(array, index, item);
|
||||
|
@ -1,6 +1,4 @@
|
||||
if (!array || index >= array->count) {{
|
||||
return NULL;
|
||||
}}
|
||||
assert(array != NULL & index < array->count);
|
||||
|
||||
u8 *ptr = (u8 *)(array->items) + (array->item_size * index);
|
||||
return ({T} *)ptr;
|
||||
|
@ -1,6 +1,3 @@
|
||||
{T} *ptr = wapp_{Tlower}_array_get(array, index);
|
||||
if (!ptr) {{
|
||||
return;
|
||||
}}
|
||||
|
||||
memcpy((void *)ptr, (void *)item, array->item_size);
|
||||
|
@ -1,5 +1,2 @@
|
||||
if (!array) {{
|
||||
return;
|
||||
}}
|
||||
|
||||
assert(array != NULL);
|
||||
array->count = 0;
|
||||
|
@ -1,8 +1,6 @@
|
||||
{ArrayType} *output = dst;
|
||||
assert(allocator != NULL & src != NULL && dst != NULL);
|
||||
|
||||
if (!allocator || !src || !dst) {{
|
||||
goto RETURN_{Tupper}_ARRAY_COPY_ALLOC;
|
||||
}}
|
||||
{ArrayType} *output = dst;
|
||||
|
||||
if (src->count >= dst->capacity) {{
|
||||
u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2);
|
||||
|
@ -1,6 +1,4 @@
|
||||
if (!src || !dst) {{
|
||||
return;
|
||||
}}
|
||||
assert(src != NULL && dst != NULL);
|
||||
|
||||
wapp_{Tlower}_array_clear(dst);
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
{ArrayType} *output = array;
|
||||
assert(allocator != NULL && array != NULL && other != NULL);
|
||||
|
||||
if (!allocator || !array || !other) {{
|
||||
goto RETURN_{Tupper}_ARRAY_EXTEND_ALLOC;
|
||||
}}
|
||||
{ArrayType} *output = array;
|
||||
|
||||
u64 remaining_capacity = array->capacity - array->count;
|
||||
if (other->count >= remaining_capacity) {{
|
||||
|
@ -1,11 +1,7 @@
|
||||
if (!array || !other) {{
|
||||
return;
|
||||
}}
|
||||
assert(array != NULL && other != NULL);
|
||||
|
||||
u64 remaining_capacity = array->capacity - array->count;
|
||||
if (other->count >= remaining_capacity) {{
|
||||
return;
|
||||
}}
|
||||
assert(other->count < remaining_capacity);
|
||||
|
||||
{T} *item;
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -86,7 +86,6 @@ TestFuncResult test_i32_array_append_capped(void) {
|
||||
|
||||
array = wapp_i32_array(1);
|
||||
wapp_i32_array_append_capped(&array, &((i32){10}));
|
||||
wapp_i32_array_append_capped(&array, &((i32){20}));
|
||||
|
||||
result = result && array.count == 2;
|
||||
|
||||
@ -105,10 +104,6 @@ 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);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user