]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lib/generic: changed map alloc callbacks signature
authorMarek Vavruša <marek.vavrusa@nic.cz>
Wed, 15 Apr 2015 13:49:09 +0000 (15:49 +0200)
committerMarek Vavruša <marek.vavrusa@nic.cz>
Wed, 15 Apr 2015 13:49:09 +0000 (15:49 +0200)
lib/generic/map.c
lib/generic/map.h

index 683db284658a8f0e090fe0cccf4546c0c8507132..86c2b19aa4deb26b662c9a7f0a3495309e895a92 100644 (file)
@@ -53,12 +53,12 @@ static inline cb_node_t *ref_get_internal(uint8_t *p)
 }
 
 /* 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 */
        return malloc(size);
 }
 
-static void free_std(void *ptr, void *baton) {
+static void free_std(void *baton, void *ptr) {
        (void)baton; /* Prevent compiler warnings */
        free(ptr);
 }
@@ -71,9 +71,9 @@ static void cbt_traverse_delete(map_t *map, void *top)
                cb_node_t *q = ref_get_internal(p);
                cbt_traverse_delete(map, q->child[0]);
                cbt_traverse_delete(map, q->child[1]);
-               map->free(q, map->baton);
+               map->free(map->baton, q);
        } else {
-               map->free(p, map->baton);
+               map->free(map->baton, p);
        }
 }
 
@@ -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)
 {
-       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) {
                x->value = value;
                memcpy(x->key, str, len);
@@ -215,14 +215,14 @@ different_byte_found:
        c = data->key[newbyte];
        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) {
                return ENOMEM;
        }
 
        x = (uint8_t *)cbt_make_data(map, ubytes, ulen + 1, value);
        if (x == NULL) {
-               map->free(newnode, map->baton);
+               map->free(map->baton, newnode);
                return ENOMEM;
        }
 
@@ -293,7 +293,7 @@ int map_del(map_t *map, const char *str)
        if (strcmp(str, (const char *)data->key) != 0) {
                return 1;
        }
-       map->free(p, map->baton);
+       map->free(map->baton, p);
 
        if (!whereq) {
                map->root = NULL;
@@ -301,7 +301,7 @@ int map_del(map_t *map, const char *str)
        }
 
        *whereq = q->child[1 - direction];
-       map->free(q, map->baton);
+       map->free(map->baton, q);
        return 0;
 }
 
index 25258d198f34c4a38b8656ed1828b4cba1a41386..96ce01714709a8b9b783d80f9e6a73d2a944ef39 100644 (file)
@@ -58,8 +58,8 @@ extern "C" {
 /*! Main data structure */
 typedef struct {
        void *root;
-       void *(*malloc)(size_t size, void *baton);
-       void (*free)(void *ptr, void *baton);
+       void *(*malloc)(void *baton, size_t size);
+       void (*free)(void *baton, void *ptr);
        void *baton; /*! Passed to malloc() and free() */
 } map_t;