From: Marek VavruĊĦa Date: Tue, 31 Mar 2015 17:42:09 +0000 (+0200) Subject: lib/generic: 'map' walk callback contains value X-Git-Tag: v1.0.0-beta1~274^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e00befcd716c038c1ccac3c491a0e957749f5fec;p=thirdparty%2Fknot-resolver.git lib/generic: 'map' walk callback contains value --- diff --git a/lib/generic/map.c b/lib/generic/map.c index 3da5149cb..1242d84a1 100644 --- a/lib/generic/map.c +++ b/lib/generic/map.c @@ -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); diff --git a/lib/generic/map.h b/lib/generic/map.h index 42cc51f2a..8126008af 100644 --- a/lib/generic/map.h +++ b/lib/generic/map.h @@ -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 diff --git a/lib/generic/set.h b/lib/generic/set.h index e7dbc55ca..a288b6730 100644 --- a/lib/generic/set.h +++ b/lib/generic/set.h @@ -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 diff --git a/tests/test_set.c b/tests/test_set.c index e2e624dbc..3f51abe7f 100644 --- a/tests/test_set.c +++ b/tests/test_set.c @@ -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) {