Skip to content
Snippets Groups Projects
Commit c5fc0ba1 authored by Marek Vavruša's avatar Marek Vavruša
Browse files

lib/generic: changed map alloc callbacks signature

parent 0c74992f
No related branches found
No related tags found
No related merge requests found
...@@ -53,12 +53,12 @@ static inline cb_node_t *ref_get_internal(uint8_t *p) ...@@ -53,12 +53,12 @@ static inline cb_node_t *ref_get_internal(uint8_t *p)
} }
/* Standard memory allocation functions */ /* Standard memory allocation functions */
static void *malloc_std(size_t size, void *baton) { static void *malloc_std(void *baton, size_t size) {
(void)baton; /* Prevent compiler warnings */ (void)baton; /* Prevent compiler warnings */
return malloc(size); return malloc(size);
} }
static void free_std(void *ptr, void *baton) { static void free_std(void *baton, void *ptr) {
(void)baton; /* Prevent compiler warnings */ (void)baton; /* Prevent compiler warnings */
free(ptr); free(ptr);
} }
...@@ -71,9 +71,9 @@ static void cbt_traverse_delete(map_t *map, void *top) ...@@ -71,9 +71,9 @@ static void cbt_traverse_delete(map_t *map, void *top)
cb_node_t *q = ref_get_internal(p); cb_node_t *q = ref_get_internal(p);
cbt_traverse_delete(map, q->child[0]); cbt_traverse_delete(map, q->child[0]);
cbt_traverse_delete(map, q->child[1]); cbt_traverse_delete(map, q->child[1]);
map->free(q, map->baton); map->free(map->baton, q);
} else { } else {
map->free(p, map->baton); map->free(map->baton, p);
} }
} }
...@@ -103,7 +103,7 @@ static int cbt_traverse_prefixed(void *top, ...@@ -103,7 +103,7 @@ static int cbt_traverse_prefixed(void *top,
static cb_data_t *cbt_make_data(map_t *map, const uint8_t *str, size_t len, void *value) static cb_data_t *cbt_make_data(map_t *map, const uint8_t *str, size_t len, void *value)
{ {
cb_data_t *x = map->malloc(sizeof(cb_data_t) + len, map->baton); cb_data_t *x = map->malloc(map->baton, sizeof(cb_data_t) + len);
if (x != NULL) { if (x != NULL) {
x->value = value; x->value = value;
memcpy(x->key, str, len); memcpy(x->key, str, len);
...@@ -215,14 +215,14 @@ int map_set(map_t *map, const char *str, void *value) ...@@ -215,14 +215,14 @@ int map_set(map_t *map, const char *str, void *value)
c = data->key[newbyte]; c = data->key[newbyte];
newdirection = (1 + (newotherbits | c)) >> 8; newdirection = (1 + (newotherbits | c)) >> 8;
newnode = map->malloc(sizeof(cb_node_t), map->baton); newnode = map->malloc(map->baton, sizeof(cb_node_t));
if (newnode == NULL) { if (newnode == NULL) {
return ENOMEM; return ENOMEM;
} }
x = (uint8_t *)cbt_make_data(map, ubytes, ulen + 1, value); x = (uint8_t *)cbt_make_data(map, ubytes, ulen + 1, value);
if (x == NULL) { if (x == NULL) {
map->free(newnode, map->baton); map->free(map->baton, newnode);
return ENOMEM; return ENOMEM;
} }
...@@ -293,7 +293,7 @@ int map_del(map_t *map, const char *str) ...@@ -293,7 +293,7 @@ int map_del(map_t *map, const char *str)
if (strcmp(str, (const char *)data->key) != 0) { if (strcmp(str, (const char *)data->key) != 0) {
return 1; return 1;
} }
map->free(p, map->baton); map->free(map->baton, p);
if (!whereq) { if (!whereq) {
map->root = NULL; map->root = NULL;
...@@ -301,7 +301,7 @@ int map_del(map_t *map, const char *str) ...@@ -301,7 +301,7 @@ int map_del(map_t *map, const char *str)
} }
*whereq = q->child[1 - direction]; *whereq = q->child[1 - direction];
map->free(q, map->baton); map->free(map->baton, q);
return 0; return 0;
} }
......
...@@ -58,8 +58,8 @@ extern "C" { ...@@ -58,8 +58,8 @@ extern "C" {
/*! Main data structure */ /*! Main data structure */
typedef struct { typedef struct {
void *root; void *root;
void *(*malloc)(size_t size, void *baton); void *(*malloc)(void *baton, size_t size);
void (*free)(void *ptr, void *baton); void (*free)(void *baton, void *ptr);
void *baton; /*! Passed to malloc() and free() */ void *baton; /*! Passed to malloc() and free() */
} map_t; } map_t;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment