static struct memblock_t *mem_start = NULL;
void *util_memory_a(size_t byte, unsigned int line, const char *file) {
- struct memblock_t *info = malloc(sizeof(struct memblock_t) + byte);
+ struct memblock_t *info = (struct memblock_t*)malloc(sizeof(struct memblock_t) + byte);
void *data = (void*)(info+1);
if (!info) return NULL;
info->line = line;
if (!s)
return NULL;
- if ((len = strlen(s)) && (ptr = mem_a(len+1))) {
+ if ((len = strlen(s)) && (ptr = (char*)mem_a(len+1))) {
memcpy(ptr, s, len);
ptr[len] = '\0';
}
/* TODO: rewrite ... when I redo the ve cleanup */
void _util_vec_grow(void **a, size_t i, size_t s) {
- size_t m = *a ? 2*_vec_beg(*a)+i : i+1;
- void *p = mem_r((*a ? _vec_raw(*a) : NULL), s * m + sizeof(size_t)*2);
+ vector_t *d = vec_meta(*a);
+ size_t m = *a ? 2 * d->allocated +i : i+1;
+ void *p = mem_r((*a ? d : NULL), s * m + sizeof(vector_t));
+
if (!*a)
- ((size_t*)p)[1] = 0;
- *a = (void*)((size_t*)p + 2);
- _vec_beg(*a) = m;
+ ((vector_t*)p)->used = 0;
+ *a = (vector_t*)p + 1;
+
+ vec_meta(*a)->allocated = m;
}
/*
hash_node_t *_util_htnewpair(const char *key, void *value) {
hash_node_t *node;
- if (!(node = mem_a(sizeof(hash_node_t))))
+ if (!(node = (hash_node_t*)mem_a(sizeof(hash_node_t))))
return NULL;
if (!(node->key = util_strdup(key))) {
if (size < 1)
return NULL;
- if (!(hashtable = mem_a(sizeof(hash_table_t))))
+ if (!(hashtable = (hash_table_t*)mem_a(sizeof(hash_table_t))))
return NULL;
- if (!(hashtable->table = mem_a(sizeof(hash_node_t*) * size))) {
+ if (!(hashtable->table = (hash_node_t**)mem_a(sizeof(hash_node_t*) * size))) {
mem_d(hashtable);
return NULL;
}