Use cl_ namespace and fix internal error naming
This commit is contained in:
parent
4848259901
commit
1036867979
210
dynarray.c
210
dynarray.c
@ -23,36 +23,36 @@
|
|||||||
#include <string.h> // memcpy()
|
#include <string.h> // memcpy()
|
||||||
|
|
||||||
// Exporter
|
// Exporter
|
||||||
static dynarray_err corelibs_dynarray_export_slice(const dynarray_t*, uintmax_t, uintmax_t, void*);
|
static cl_dynarray_err corelibs_dynarray_export_slice(const cl_dynarray_t*, uintmax_t, uintmax_t, void*);
|
||||||
|
|
||||||
// Lifetime
|
// Lifetime
|
||||||
static dynarray_err corelibs_dynarray_make_new(size_t, dynarray_t**);
|
static cl_dynarray_err corelibs_dynarray_make_new(size_t, cl_dynarray_t**);
|
||||||
static dynarray_err corelibs_dynarray_make_slice(const dynarray_t*, uintmax_t, uintmax_t, dynarray_t**);
|
static cl_dynarray_err corelibs_dynarray_make_slice(const cl_dynarray_t*, uintmax_t, uintmax_t, cl_dynarray_t**);
|
||||||
static dynarray_err corelibs_dynarray_free(dynarray_t*);
|
static cl_dynarray_err corelibs_dynarray_free(cl_dynarray_t*);
|
||||||
|
|
||||||
// Array storage
|
// Array storage
|
||||||
static dynarray_err corelibs_dynarray_mod_arr_cap(dynarray_t*, uintmax_t);
|
static cl_dynarray_err corelibs_dynarray_mod_arr_cap(cl_dynarray_t*, uintmax_t);
|
||||||
static dynarray_err corelibs_dynarray_mod_arr_lock(dynarray_t*, bool);
|
static cl_dynarray_err corelibs_dynarray_mod_arr_lock(cl_dynarray_t*, bool);
|
||||||
|
|
||||||
// Array contents
|
// Array contents
|
||||||
static dynarray_err corelibs_dynarray_mod_ct_app(dynarray_t*, uintmax_t, const void*);
|
static cl_dynarray_err corelibs_dynarray_mod_ct_app(cl_dynarray_t*, uintmax_t, const void*);
|
||||||
static dynarray_err corelibs_dynarray_mod_ct_ins(dynarray_t*, uintmax_t, uintmax_t, const void*);
|
static cl_dynarray_err corelibs_dynarray_mod_ct_ins(cl_dynarray_t*, uintmax_t, uintmax_t, const void*);
|
||||||
static dynarray_err corelibs_dynarray_mod_ct_rep(dynarray_t*, uintmax_t, uintmax_t, const void*);
|
static cl_dynarray_err corelibs_dynarray_mod_ct_rep(cl_dynarray_t*, uintmax_t, uintmax_t, const void*);
|
||||||
static dynarray_err corelibs_dynarray_mod_ct_rm(dynarray_t*, uintmax_t, uintmax_t);
|
static cl_dynarray_err corelibs_dynarray_mod_ct_rm(cl_dynarray_t*, uintmax_t, uintmax_t);
|
||||||
|
|
||||||
// Get array properties
|
// Get array properties
|
||||||
static dynarray_err corelibs_dynarray_get_len(const dynarray_t*, uintmax_t*);
|
static cl_dynarray_err corelibs_dynarray_get_len(const cl_dynarray_t*, uintmax_t*);
|
||||||
static dynarray_err corelibs_dynarray_get_size(const dynarray_t*, size_t*);
|
static cl_dynarray_err corelibs_dynarray_get_size(const cl_dynarray_t*, size_t*);
|
||||||
static dynarray_err corelibs_dynarray_get_cap_len(const dynarray_t*, uintmax_t*);
|
static cl_dynarray_err corelibs_dynarray_get_cap_len(const cl_dynarray_t*, uintmax_t*);
|
||||||
static dynarray_err corelibs_dynarray_get_cap_lock(const dynarray_t*, bool*);
|
static cl_dynarray_err corelibs_dynarray_get_cap_lock(const cl_dynarray_t*, bool*);
|
||||||
|
|
||||||
// Compare arrays
|
// Compare arrays
|
||||||
static dynarray_err corelibs_dynarray_cmp_data(const dynarray_t* a, const dynarray_t* b, bool* eq);
|
static cl_dynarray_err corelibs_dynarray_cmp_data(const cl_dynarray_t* a, const cl_dynarray_t* b, bool* eq);
|
||||||
|
|
||||||
// Private functions
|
// Private functions
|
||||||
static dynarray_err corelibs_dynarray_bcheck(const dynarray_t*, uintmax_t, uintmax_t);
|
static cl_dynarray_err corelibs_dynarray_bcheck(const cl_dynarray_t*, uintmax_t, uintmax_t);
|
||||||
|
|
||||||
struct dynarray_t {
|
struct cl_dynarray_t {
|
||||||
void* addr; // Location of element
|
void* addr; // Location of element
|
||||||
uintmax_t len; // Element count
|
uintmax_t len; // Element count
|
||||||
struct {
|
struct {
|
||||||
@ -63,15 +63,15 @@ struct dynarray_t {
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum { // Avoid collision in error numbers
|
enum { // Avoid collision in error numbers
|
||||||
CORELIBS_DYNARRAY_ERR_NCOMPAT = -7,
|
CORELIBS_DYNARRAY_ERR_VAR_NCOMPAT = -7,
|
||||||
CORELIBS_DYNARRAY_ERR_INVAL,
|
CORELIBS_DYNARRAY_ERR_VAR_INVAL,
|
||||||
CORELIBS_DYNARRAY_ERR_IMMUT,
|
CORELIBS_DYNARRAY_ERR_VAR_IMMUT,
|
||||||
CORELIBS_DYNARRAY_ERR_UNDEF,
|
CORELIBS_DYNARRAY_ERR_VAR_UNDEF,
|
||||||
CORELIBS_DYNARRAY_ERR_OOB,
|
CORELIBS_DYNARRAY_ERR_MEM_OOB,
|
||||||
CORELIBS_DYNARRAY_ERR_NULL,
|
CORELIBS_DYNARRAY_ERR_MEM_NULL,
|
||||||
CORELIBS_DYNARRAY_ERR_ALLOC,
|
CORELIBS_DYNARRAY_ERR_MEM_ALLOC,
|
||||||
CORELIBS_DYNARRAY_ERR_UNK = 0,
|
CORELIBS_DYNARRAY_ERR_UNKOWN = 0,
|
||||||
CORELIBS_DYNARRAY_ERR_OK = 1,
|
CORELIBS_DYNARRAY_ERR_OK = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Present a unified structure that may receive changes, deprecations and renames without hassle for external users
|
// Present a unified structure that may receive changes, deprecations and renames without hassle for external users
|
||||||
@ -109,34 +109,34 @@ const struct corelibs_dynarray_interface dynarray = {
|
|||||||
},
|
},
|
||||||
.err = {
|
.err = {
|
||||||
.ok = CORELIBS_DYNARRAY_ERR_OK,
|
.ok = CORELIBS_DYNARRAY_ERR_OK,
|
||||||
.unknown = CORELIBS_DYNARRAY_ERR_UNK,
|
.unknown = CORELIBS_DYNARRAY_ERR_UNKOWN,
|
||||||
.mem = {
|
.mem = {
|
||||||
.alloc = CORELIBS_DYNARRAY_ERR_ALLOC,
|
.alloc = CORELIBS_DYNARRAY_ERR_MEM_ALLOC,
|
||||||
.null = CORELIBS_DYNARRAY_ERR_NULL,
|
.null = CORELIBS_DYNARRAY_ERR_MEM_NULL,
|
||||||
.oob = CORELIBS_DYNARRAY_ERR_OOB,
|
.oob = CORELIBS_DYNARRAY_ERR_MEM_OOB,
|
||||||
},
|
},
|
||||||
.var = {
|
.var = {
|
||||||
.undef = CORELIBS_DYNARRAY_ERR_UNDEF,
|
.undef = CORELIBS_DYNARRAY_ERR_VAR_UNDEF,
|
||||||
.immut = CORELIBS_DYNARRAY_ERR_IMMUT,
|
.immut = CORELIBS_DYNARRAY_ERR_VAR_IMMUT,
|
||||||
.inval = CORELIBS_DYNARRAY_ERR_INVAL,
|
.inval = CORELIBS_DYNARRAY_ERR_VAR_INVAL,
|
||||||
.ncompat = CORELIBS_DYNARRAY_ERR_NCOMPAT,
|
.ncompat = CORELIBS_DYNARRAY_ERR_VAR_NCOMPAT,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static dynarray_err
|
static cl_dynarray_err
|
||||||
corelibs_dynarray_make_new(size_t sbyte, dynarray_t** ptr)
|
corelibs_dynarray_make_new(size_t sbyte, cl_dynarray_t** ptr)
|
||||||
{
|
{
|
||||||
dynarray_err err = CORELIBS_DYNARRAY_ERR_OK;
|
cl_dynarray_err err = CORELIBS_DYNARRAY_ERR_OK;
|
||||||
|
|
||||||
if (ptr == NULL) {
|
if (ptr == NULL) {
|
||||||
err = CORELIBS_DYNARRAY_ERR_NULL;
|
err = CORELIBS_DYNARRAY_ERR_MEM_NULL;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
dynarray_t* new = malloc(sizeof(*new));
|
cl_dynarray_t* new = malloc(sizeof(*new));
|
||||||
if (new == NULL) {
|
if (new == NULL) {
|
||||||
err = CORELIBS_DYNARRAY_ERR_ALLOC;
|
err = CORELIBS_DYNARRAY_ERR_MEM_ALLOC;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,13 +151,13 @@ ret:
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static dynarray_err
|
static cl_dynarray_err
|
||||||
corelibs_dynarray_make_slice(const dynarray_t* arr, uintmax_t pos, uintmax_t cnt, dynarray_t** save)
|
corelibs_dynarray_make_slice(const cl_dynarray_t* arr, uintmax_t pos, uintmax_t cnt, cl_dynarray_t** save)
|
||||||
{
|
{
|
||||||
dynarray_err err = CORELIBS_DYNARRAY_ERR_OK;
|
cl_dynarray_err err = CORELIBS_DYNARRAY_ERR_OK;
|
||||||
|
|
||||||
if (save == NULL || arr == NULL) {
|
if (save == NULL || arr == NULL) {
|
||||||
err = CORELIBS_DYNARRAY_ERR_NULL;
|
err = CORELIBS_DYNARRAY_ERR_MEM_NULL;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,7 +170,7 @@ corelibs_dynarray_make_slice(const dynarray_t* arr, uintmax_t pos, uintmax_t cnt
|
|||||||
// Can we slice these elements?
|
// Can we slice these elements?
|
||||||
if ((err = corelibs_dynarray_bcheck(arr, pos, cnt)) != CORELIBS_DYNARRAY_ERR_OK) goto ret;
|
if ((err = corelibs_dynarray_bcheck(arr, pos, cnt)) != CORELIBS_DYNARRAY_ERR_OK) goto ret;
|
||||||
|
|
||||||
dynarray_t* new;
|
cl_dynarray_t* new;
|
||||||
// Create new array
|
// Create new array
|
||||||
if ((err = corelibs_dynarray_make_new(arr->es, &new)) != CORELIBS_DYNARRAY_ERR_OK) goto ret;
|
if ((err = corelibs_dynarray_make_new(arr->es, &new)) != CORELIBS_DYNARRAY_ERR_OK) goto ret;
|
||||||
|
|
||||||
@ -193,13 +193,13 @@ ret:
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static dynarray_err
|
static cl_dynarray_err
|
||||||
corelibs_dynarray_free(dynarray_t* arr)
|
corelibs_dynarray_free(cl_dynarray_t* arr)
|
||||||
{
|
{
|
||||||
dynarray_err err = CORELIBS_DYNARRAY_ERR_OK;
|
cl_dynarray_err err = CORELIBS_DYNARRAY_ERR_OK;
|
||||||
|
|
||||||
if (arr == NULL) {
|
if (arr == NULL) {
|
||||||
err = CORELIBS_DYNARRAY_ERR_NULL;
|
err = CORELIBS_DYNARRAY_ERR_MEM_NULL;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,13 +210,13 @@ ret:
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static dynarray_err
|
static cl_dynarray_err
|
||||||
corelibs_dynarray_mod_arr_cap(dynarray_t* arr, uintmax_t len)
|
corelibs_dynarray_mod_arr_cap(cl_dynarray_t* arr, uintmax_t len)
|
||||||
{
|
{
|
||||||
dynarray_err err = CORELIBS_DYNARRAY_ERR_OK;
|
cl_dynarray_err err = CORELIBS_DYNARRAY_ERR_OK;
|
||||||
|
|
||||||
if (arr == NULL) {
|
if (arr == NULL) {
|
||||||
err = CORELIBS_DYNARRAY_ERR_NULL;
|
err = CORELIBS_DYNARRAY_ERR_MEM_NULL;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,7 +227,7 @@ corelibs_dynarray_mod_arr_cap(dynarray_t* arr, uintmax_t len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (arr->cap.lock) {
|
if (arr->cap.lock) {
|
||||||
err = CORELIBS_DYNARRAY_ERR_IMMUT;
|
err = CORELIBS_DYNARRAY_ERR_VAR_IMMUT;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,12 +236,12 @@ corelibs_dynarray_mod_arr_cap(dynarray_t* arr, uintmax_t len)
|
|||||||
|
|
||||||
if (arr->addr == NULL) {
|
if (arr->addr == NULL) {
|
||||||
if ((reg = malloc(nl)) == NULL) {
|
if ((reg = malloc(nl)) == NULL) {
|
||||||
err = CORELIBS_DYNARRAY_ERR_ALLOC;
|
err = CORELIBS_DYNARRAY_ERR_MEM_ALLOC;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
} else if (arr->cap.len != len) {
|
} else if (arr->cap.len != len) {
|
||||||
if ((reg = realloc(arr->addr, nl)) == NULL) {
|
if ((reg = realloc(arr->addr, nl)) == NULL) {
|
||||||
err = CORELIBS_DYNARRAY_ERR_ALLOC;
|
err = CORELIBS_DYNARRAY_ERR_MEM_ALLOC;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -253,13 +253,13 @@ ret:
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static dynarray_err
|
static cl_dynarray_err
|
||||||
corelibs_dynarray_mod_arr_lock(dynarray_t* arr, bool lock)
|
corelibs_dynarray_mod_arr_lock(cl_dynarray_t* arr, bool lock)
|
||||||
{
|
{
|
||||||
dynarray_err err = CORELIBS_DYNARRAY_ERR_OK;
|
cl_dynarray_err err = CORELIBS_DYNARRAY_ERR_OK;
|
||||||
|
|
||||||
if (arr == NULL) {
|
if (arr == NULL) {
|
||||||
err = CORELIBS_DYNARRAY_ERR_NULL;
|
err = CORELIBS_DYNARRAY_ERR_MEM_NULL;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,19 +268,19 @@ ret:
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static dynarray_err
|
static cl_dynarray_err
|
||||||
corelibs_dynarray_mod_ct_app(dynarray_t* arr, uintmax_t cnt, const void* elem)
|
corelibs_dynarray_mod_ct_app(cl_dynarray_t* arr, uintmax_t cnt, const void* elem)
|
||||||
{
|
{
|
||||||
return corelibs_dynarray_mod_ct_ins(arr, arr->len, cnt, elem);
|
return corelibs_dynarray_mod_ct_ins(arr, arr->len, cnt, elem);
|
||||||
}
|
}
|
||||||
|
|
||||||
static dynarray_err
|
static cl_dynarray_err
|
||||||
corelibs_dynarray_mod_ct_ins(dynarray_t* arr, uintmax_t pos, uintmax_t cnt, const void* elem)
|
corelibs_dynarray_mod_ct_ins(cl_dynarray_t* arr, uintmax_t pos, uintmax_t cnt, const void* elem)
|
||||||
{
|
{
|
||||||
dynarray_err err = CORELIBS_DYNARRAY_ERR_OK;
|
cl_dynarray_err err = CORELIBS_DYNARRAY_ERR_OK;
|
||||||
|
|
||||||
if (arr == NULL || elem == NULL) {
|
if (arr == NULL || elem == NULL) {
|
||||||
err = CORELIBS_DYNARRAY_ERR_NULL;
|
err = CORELIBS_DYNARRAY_ERR_MEM_NULL;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -315,13 +315,13 @@ ret:
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static dynarray_err
|
static cl_dynarray_err
|
||||||
corelibs_dynarray_mod_ct_rep(dynarray_t* arr, uintmax_t pos, uintmax_t cnt, const void* elem)
|
corelibs_dynarray_mod_ct_rep(cl_dynarray_t* arr, uintmax_t pos, uintmax_t cnt, const void* elem)
|
||||||
{
|
{
|
||||||
dynarray_err err = CORELIBS_DYNARRAY_ERR_OK;
|
cl_dynarray_err err = CORELIBS_DYNARRAY_ERR_OK;
|
||||||
|
|
||||||
if (arr == NULL || elem == NULL) {
|
if (arr == NULL || elem == NULL) {
|
||||||
err = CORELIBS_DYNARRAY_ERR_NULL;
|
err = CORELIBS_DYNARRAY_ERR_MEM_NULL;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,13 +346,13 @@ ret:
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static dynarray_err
|
static cl_dynarray_err
|
||||||
corelibs_dynarray_mod_ct_rm(dynarray_t* arr, uintmax_t pos, uintmax_t cnt)
|
corelibs_dynarray_mod_ct_rm(cl_dynarray_t* arr, uintmax_t pos, uintmax_t cnt)
|
||||||
{
|
{
|
||||||
dynarray_err err = CORELIBS_DYNARRAY_ERR_OK;
|
cl_dynarray_err err = CORELIBS_DYNARRAY_ERR_OK;
|
||||||
|
|
||||||
if (arr == NULL) {
|
if (arr == NULL) {
|
||||||
err = CORELIBS_DYNARRAY_ERR_NULL;
|
err = CORELIBS_DYNARRAY_ERR_MEM_NULL;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -362,7 +362,7 @@ corelibs_dynarray_mod_ct_rm(dynarray_t* arr, uintmax_t pos, uintmax_t cnt)
|
|||||||
// Allocate intermediate buffer
|
// Allocate intermediate buffer
|
||||||
void* tbuf = malloc(arr->es * arr->len);
|
void* tbuf = malloc(arr->es * arr->len);
|
||||||
if (tbuf == NULL) {
|
if (tbuf == NULL) {
|
||||||
err = CORELIBS_DYNARRAY_ERR_ALLOC;
|
err = CORELIBS_DYNARRAY_ERR_MEM_ALLOC;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -395,13 +395,13 @@ ret:
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static dynarray_err
|
static cl_dynarray_err
|
||||||
corelibs_dynarray_export_slice(const dynarray_t* arr, uintmax_t pos, uintmax_t cnt, void* save)
|
corelibs_dynarray_export_slice(const cl_dynarray_t* arr, uintmax_t pos, uintmax_t cnt, void* save)
|
||||||
{
|
{
|
||||||
dynarray_err err = CORELIBS_DYNARRAY_ERR_OK;
|
cl_dynarray_err err = CORELIBS_DYNARRAY_ERR_OK;
|
||||||
|
|
||||||
if (arr == NULL || save == NULL) {
|
if (arr == NULL || save == NULL) {
|
||||||
err = CORELIBS_DYNARRAY_ERR_NULL;
|
err = CORELIBS_DYNARRAY_ERR_MEM_NULL;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
if (cnt == 0) goto ret;
|
if (cnt == 0) goto ret;
|
||||||
@ -421,13 +421,13 @@ ret:
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static dynarray_err
|
static cl_dynarray_err
|
||||||
corelibs_dynarray_get_len(const dynarray_t* arr, uintmax_t* save)
|
corelibs_dynarray_get_len(const cl_dynarray_t* arr, uintmax_t* save)
|
||||||
{
|
{
|
||||||
dynarray_err err = CORELIBS_DYNARRAY_ERR_OK;
|
cl_dynarray_err err = CORELIBS_DYNARRAY_ERR_OK;
|
||||||
|
|
||||||
if (arr == NULL || save == NULL) {
|
if (arr == NULL || save == NULL) {
|
||||||
err = CORELIBS_DYNARRAY_ERR_NULL;
|
err = CORELIBS_DYNARRAY_ERR_MEM_NULL;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -436,13 +436,13 @@ ret:
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static dynarray_err
|
static cl_dynarray_err
|
||||||
corelibs_dynarray_get_cap_len(const dynarray_t* arr, uintmax_t* save)
|
corelibs_dynarray_get_cap_len(const cl_dynarray_t* arr, uintmax_t* save)
|
||||||
{
|
{
|
||||||
dynarray_err err = CORELIBS_DYNARRAY_ERR_OK;
|
cl_dynarray_err err = CORELIBS_DYNARRAY_ERR_OK;
|
||||||
|
|
||||||
if (arr == NULL || save == NULL) {
|
if (arr == NULL || save == NULL) {
|
||||||
err = CORELIBS_DYNARRAY_ERR_NULL;
|
err = CORELIBS_DYNARRAY_ERR_MEM_NULL;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -451,13 +451,13 @@ ret:
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static dynarray_err
|
static cl_dynarray_err
|
||||||
corelibs_dynarray_get_cap_lock(const dynarray_t* arr, bool* save)
|
corelibs_dynarray_get_cap_lock(const cl_dynarray_t* arr, bool* save)
|
||||||
{
|
{
|
||||||
dynarray_err err = CORELIBS_DYNARRAY_ERR_OK;
|
cl_dynarray_err err = CORELIBS_DYNARRAY_ERR_OK;
|
||||||
|
|
||||||
if (arr == NULL || save == NULL) {
|
if (arr == NULL || save == NULL) {
|
||||||
err = CORELIBS_DYNARRAY_ERR_NULL;
|
err = CORELIBS_DYNARRAY_ERR_MEM_NULL;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -466,13 +466,13 @@ ret:
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static dynarray_err
|
static cl_dynarray_err
|
||||||
corelibs_dynarray_get_size(const dynarray_t* arr, size_t* save)
|
corelibs_dynarray_get_size(const cl_dynarray_t* arr, size_t* save)
|
||||||
{
|
{
|
||||||
dynarray_err err = CORELIBS_DYNARRAY_ERR_OK;
|
cl_dynarray_err err = CORELIBS_DYNARRAY_ERR_OK;
|
||||||
|
|
||||||
if (arr == NULL || save == NULL) {
|
if (arr == NULL || save == NULL) {
|
||||||
err = CORELIBS_DYNARRAY_ERR_NULL;
|
err = CORELIBS_DYNARRAY_ERR_MEM_NULL;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -481,18 +481,18 @@ ret:
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static dynarray_err
|
static cl_dynarray_err
|
||||||
corelibs_dynarray_cmp_data(const dynarray_t* a, const dynarray_t* b, bool* eq)
|
corelibs_dynarray_cmp_data(const cl_dynarray_t* a, const cl_dynarray_t* b, bool* eq)
|
||||||
{
|
{
|
||||||
dynarray_err err = CORELIBS_DYNARRAY_ERR_OK;
|
cl_dynarray_err err = CORELIBS_DYNARRAY_ERR_OK;
|
||||||
|
|
||||||
if (a == NULL || b == NULL) {
|
if (a == NULL || b == NULL) {
|
||||||
err = CORELIBS_DYNARRAY_ERR_NULL;
|
err = CORELIBS_DYNARRAY_ERR_MEM_NULL;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a->es != b->es) {
|
if (a->es != b->es) {
|
||||||
err = CORELIBS_DYNARRAY_ERR_NCOMPAT;
|
err = CORELIBS_DYNARRAY_ERR_VAR_NCOMPAT;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -507,18 +507,18 @@ ret:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Private functions
|
// Private functions
|
||||||
static dynarray_err
|
static cl_dynarray_err
|
||||||
corelibs_dynarray_bcheck(const dynarray_t* arr, uintmax_t pos, uintmax_t len)
|
corelibs_dynarray_bcheck(const cl_dynarray_t* arr, uintmax_t pos, uintmax_t len)
|
||||||
{
|
{
|
||||||
dynarray_err err = CORELIBS_DYNARRAY_ERR_OK;
|
cl_dynarray_err err = CORELIBS_DYNARRAY_ERR_OK;
|
||||||
|
|
||||||
if (arr == NULL) {
|
if (arr == NULL) {
|
||||||
err = CORELIBS_DYNARRAY_ERR_NULL;
|
err = CORELIBS_DYNARRAY_ERR_MEM_NULL;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arr->cap.len < pos + len) {
|
if (arr->cap.len < pos + len) {
|
||||||
err = CORELIBS_DYNARRAY_ERR_OOB;
|
err = CORELIBS_DYNARRAY_ERR_MEM_OOB;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
ret:
|
ret:
|
||||||
|
52
dynarray.h
52
dynarray.h
@ -23,82 +23,82 @@
|
|||||||
#ifndef CORELIBS_GUARD_DYNARRAY
|
#ifndef CORELIBS_GUARD_DYNARRAY
|
||||||
#define CORELIBS_GUARD_DYNARRAY
|
#define CORELIBS_GUARD_DYNARRAY
|
||||||
|
|
||||||
typedef signed short int dynarray_err;
|
typedef signed short int cl_dynarray_err;
|
||||||
typedef struct dynarray_t dynarray_t;
|
typedef struct cl_dynarray_t cl_dynarray_t;
|
||||||
|
|
||||||
struct corelibs_dynarray_interface {
|
struct corelibs_dynarray_interface {
|
||||||
|
|
||||||
// Makers
|
// Makers
|
||||||
const struct {
|
const struct {
|
||||||
// New - allocate new array
|
// New - allocate new array
|
||||||
dynarray_err (*const new)(size_t sbyte, dynarray_t** ptr);
|
cl_dynarray_err (*const new)(size_t sbyte, cl_dynarray_t** ptr);
|
||||||
// Slicer - gets a slice of a array
|
// Slicer - gets a slice of a array
|
||||||
dynarray_err (*const slice)(const dynarray_t* arr, uintmax_t pos, uintmax_t len, dynarray_t** ssave);
|
cl_dynarray_err (*const slice)(const cl_dynarray_t* arr, uintmax_t pos, uintmax_t len, cl_dynarray_t** ssave);
|
||||||
} make;
|
} make;
|
||||||
|
|
||||||
// Free
|
// Free
|
||||||
dynarray_err (*const free)(dynarray_t* arr);
|
cl_dynarray_err (*const free)(cl_dynarray_t* arr);
|
||||||
|
|
||||||
// Modifiers
|
// Modifiers
|
||||||
const struct {
|
const struct {
|
||||||
|
|
||||||
const struct {
|
const struct {
|
||||||
// Capacity
|
// Capacity
|
||||||
dynarray_err (*const cap)(dynarray_t* ptr, uintmax_t len);
|
cl_dynarray_err (*const cap)(cl_dynarray_t* ptr, uintmax_t len);
|
||||||
// Capacity lock (dynamic / static capacity)
|
// Capacity lock (dynamic / static capacity)
|
||||||
dynarray_err (*const lock)(dynarray_t* ptr, bool cap);
|
cl_dynarray_err (*const lock)(cl_dynarray_t* ptr, bool cap);
|
||||||
} arr;
|
} arr;
|
||||||
|
|
||||||
const struct {
|
const struct {
|
||||||
// Appender - Adds element at end of array
|
// Appender - Adds element at end of array
|
||||||
dynarray_err (*const app)(dynarray_t* arr, uintmax_t cnt, const void* elem);
|
cl_dynarray_err (*const app)(cl_dynarray_t* arr, uintmax_t cnt, const void* elem);
|
||||||
// Inserter - Adds element at position, pushing next element 1 position further
|
// Inserter - Adds element at position, pushing next element 1 position further
|
||||||
dynarray_err (*const ins)(dynarray_t* arr, uintmax_t pos, uintmax_t cnt, const void* elem);
|
cl_dynarray_err (*const ins)(cl_dynarray_t* arr, uintmax_t pos, uintmax_t cnt, const void* elem);
|
||||||
// Replacer - Replaces array item or creates it if not existent
|
// Replacer - Replaces array item or creates it if not existent
|
||||||
dynarray_err (*const rep)(dynarray_t* arr, uintmax_t pos, uintmax_t cnt, const void* elem);
|
cl_dynarray_err (*const rep)(cl_dynarray_t* arr, uintmax_t pos, uintmax_t cnt, const void* elem);
|
||||||
// Remover - removes element from array
|
// Remover - removes element from array
|
||||||
dynarray_err (*const rm)(dynarray_t* arr, uintmax_t pos, uintmax_t cnt);
|
cl_dynarray_err (*const rm)(cl_dynarray_t* arr, uintmax_t pos, uintmax_t cnt);
|
||||||
} ct;
|
} ct;
|
||||||
|
|
||||||
} mod;
|
} mod;
|
||||||
|
|
||||||
// Fetchers
|
// Fetchers
|
||||||
const struct {
|
const struct {
|
||||||
dynarray_err (*const len)(const dynarray_t* arr, uintmax_t* save);
|
cl_dynarray_err (*const len)(const cl_dynarray_t* arr, uintmax_t* save);
|
||||||
dynarray_err (*const size)(const dynarray_t* arr, size_t* save);
|
cl_dynarray_err (*const size)(const cl_dynarray_t* arr, size_t* save);
|
||||||
const struct {
|
const struct {
|
||||||
dynarray_err (*const len)(const dynarray_t* arr, uintmax_t* save);
|
cl_dynarray_err (*const len)(const cl_dynarray_t* arr, uintmax_t* save);
|
||||||
dynarray_err (*const lock)(const dynarray_t* arr, bool* save);
|
cl_dynarray_err (*const lock)(const cl_dynarray_t* arr, bool* save);
|
||||||
} cap;
|
} cap;
|
||||||
} get;
|
} get;
|
||||||
|
|
||||||
// Comparers
|
// Comparers
|
||||||
const struct {
|
const struct {
|
||||||
dynarray_err (*const data)(const dynarray_t* a, const dynarray_t* b, bool* eq);
|
cl_dynarray_err (*const data)(const cl_dynarray_t* a, const cl_dynarray_t* b, bool* eq);
|
||||||
} cmp;
|
} cmp;
|
||||||
|
|
||||||
// Exporter
|
// Exporter
|
||||||
const struct {
|
const struct {
|
||||||
dynarray_err (*const slice)(const dynarray_t* arr, uintmax_t pos, uintmax_t cnt, void* save);
|
cl_dynarray_err (*const slice)(const cl_dynarray_t* arr, uintmax_t pos, uintmax_t cnt, void* save);
|
||||||
} export;
|
} export;
|
||||||
|
|
||||||
// Errors - functions return them on run-time problems
|
// Errors - functions return them on run-time problems
|
||||||
const struct {
|
const struct {
|
||||||
|
|
||||||
const dynarray_err ok, // No error
|
const cl_dynarray_err ok, // No error
|
||||||
unknown; // Unknown error
|
unknown; // Unknown error
|
||||||
|
|
||||||
const struct {
|
const struct {
|
||||||
const dynarray_err alloc, // Memory allocation failed
|
const cl_dynarray_err alloc, // Memory allocation failed
|
||||||
null, // Passed a null pointer
|
null, // Passed a null pointer
|
||||||
oob; // Out of bounds modification or fetch
|
oob; // Out of bounds modification or fetch
|
||||||
} mem;
|
} mem;
|
||||||
|
|
||||||
const struct {
|
const struct {
|
||||||
const dynarray_err undef, // Undefined variable
|
const cl_dynarray_err undef, // Undefined variable
|
||||||
immut, // Immutable (constant) variable
|
immut, // Immutable (constant) variable
|
||||||
inval, // Invalid value passed
|
inval, // Invalid value passed
|
||||||
ncompat; // Incompatible comparasion
|
ncompat; // Incompatible comparasion
|
||||||
} var;
|
} var;
|
||||||
|
|
||||||
} err;
|
} err;
|
||||||
|
Reference in New Issue
Block a user