/* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ #include "include.h" #include "../__internal/assert.h" #include "../__internal/vnode.h" ssize_t libcdsb_array_insert(arr_t* x, const void* v, vtype t) { ssize_t i; vnode_t n; i = x->size; n = vnode_tcreate(x->type, v, t); x->mem = realloc(x->mem, ++x->size * vtype_size(x->type)); if (t < VTYPE_STRING) { n = vnode_tcreate(x->type, v, t); memcpy(array_internal_at(x, i), vnode_peek(&n, x->type), vtype_size(x->type)); if (vtype_size(x->type) > sizeof(vnode_t)) vnode_free(&n, x->type); } else { type_assert(x->type, t); get_type_initializer(t)(array_internal_at(x, i), v); } return i; } ssize_t libcdsb_array_attach(arr_t* x, const void* v, vtype t) { ssize_t i; vnode_t n; i = x->size; x->mem = realloc(x->mem, ++x->size * vtype_size(x->type)); if (t < VTYPE_STRING) { n = vnode_tcreate(x->type, v, t); memcpy(array_internal_at(x, i), vnode_peek(&n, x->type), vtype_size(x->type)); if (vtype_size(x->type) > sizeof(vnode_t)) vnode_free(&n, x->type); } else { type_assert(x->type, t); memcpy(array_internal_at(x, i), v, vtype_size(t)); } return i; }