]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lib/generic: 'map' walk callback contains value
authorMarek Vavruša <marek.vavrusa@nic.cz>
Tue, 31 Mar 2015 17:42:09 +0000 (19:42 +0200)
committerMarek Vavruša <marek.vavrusa@nic.cz>
Tue, 31 Mar 2015 17:42:09 +0000 (19:42 +0200)
lib/generic/map.c
lib/generic/map.h
lib/generic/set.h
tests/test_set.c

index 3da5149cbca205493f071aa48426807fd532a5d6..1242d84a19673dcae13f18eb8b8fb440b31909a6 100644 (file)
@@ -78,7 +78,7 @@ static void cbt_traverse_delete(map_t *map, void *top)
 }
 
 static int cbt_traverse_prefixed(void *top,
-       int (*callback)(const char *, void *), void *baton)
+       int (*callback)(const char *, void *, void *), void *baton)
 {
        uint8_t *p = top;
        cb_data_t *x = (cb_data_t *)top;
@@ -98,7 +98,7 @@ static int cbt_traverse_prefixed(void *top,
                return 0;
        }
 
-       return (callback)((const char *)x->key, baton);
+       return (callback)((const char *)x->key, x->value, baton);
 }
 
 static cb_data_t *cbt_make_data(map_t *map, const uint8_t *str, size_t len, void *value)
@@ -316,7 +316,7 @@ void map_clear(map_t *map)
 
 /*! Calls callback for all strings in map with the given prefix */
 int map_walk_prefixed(map_t *map, const char *prefix,
-       int (*callback)(const char *, void *), void *baton)
+       int (*callback)(const char *, void *, void *), void *baton)
 {
        const uint8_t *ubytes = (void *)prefix;
        const size_t ulen = strlen(prefix);
index 42cc51f2aa57dff2f768747d015fab2258dcce79..8126008afa8bcc6758a1484abc0e13f539ab0d08 100644 (file)
@@ -81,9 +81,13 @@ int map_del(map_t *map, const char *str);
 /*! Clears the given map */
 void map_clear(map_t *map);
 
+/*! Calls callback for all strings in map  */
+#define map_walk(map, callback, baton) \
+       map_walk_prefixed((map), "", (callback), (baton))
+
 /*! Calls callback for all strings in map with the given prefix  */
 int map_walk_prefixed(map_t *map, const char *prefix,
-       int (*callback)(const char *, void *), void *baton);
+       int (*callback)(const char *, void *, void *), void *baton);
 
 
 #ifdef __cplusplus
index e7dbc55caa4e924ca772b957b3dd97b075ce737a..a288b6730dd4700eb23d91eb3b59af13246d5075 100644 (file)
@@ -70,9 +70,13 @@ typedef int (set_walk_cb)(const char *, void *);
 #define set_clear(set) \
        map_clear(set)
 
+/*! Calls callback for all strings in map  */
+#define set_walk(set, callback, baton) \
+       map_walk_prefixed((set), "", (callback), (baton))
+
 /*! Calls callback for all strings in set with the given prefix  */
 #define set_walk_prefixed(set, prefix, callback, baton) \
-       map_walk_prefixed((set), (prefix), (callback), baton)
+       map_walk_prefixed((set), (prefix), (callback), (baton))
 
 
 #ifdef __cplusplus
index e2e624dbc03b4ce6ab5538cafcd4806c2f90f833..3f51abe7f7472d8cebea041440a8188e583e2bbd 100644 (file)
@@ -93,11 +93,11 @@ static void test_contains(void **state)
 }
 
 /* Count number of items */
-static int count_cb(const char *s, void *n) { (*(int *)n)++; return 0; }
+static int count_cb(const char *s, void *_, void *n) { (*(int *)n)++; return 0; }
 static void test_complete(set_t *set, int n)
 {
        int i = 0;
-       if (set_walk_prefixed(set, "", count_cb, &i) != 0) {
+       if (set_walk(set, count_cb, &i) != 0) {
                abort();
        }
        if (i != n) {