}
static bool iterate(struct strmap n,
- bool (*handle)(const char *, void *, void *), void *data)
+ bool (*handle)(const char *, void *, void *),
+ const void *data)
{
if (n.v)
- return handle(n.u.s, n.v, data);
+ return handle(n.u.s, n.v, (void *)data);
return iterate(n.u.n->child[0], handle, data)
|| iterate(n.u.n->child[1], handle, data);
}
void strmap_iterate_(const struct strmap *map,
- bool (*handle)(const char *, void *, void *), void *data)
+ bool (*handle)(const char *, void *, void *),
+ const void *data)
{
/* Empty map? */
if (!map->u.n)
__typeof__(arg)), (handle)), \
(arg))
void strmap_iterate_(const struct strmap *map,
- bool (*handle)(const char *, void *, void *), void *data);
-
+ bool (*handle)(const char *, void *, void *),
+ const void *data);
/**
* strmap_prefix - return a submap matching a prefix
--- /dev/null
+#include <ccan/strmap/strmap.h>
+#include <ccan/strmap/strmap.c>
+#include <ccan/tap/tap.h>
+
+static bool found = false;
+
+/* Make sure const args work. */
+static bool find_string(const char *str, char *member, const char *cmp)
+{
+ if (strcmp(member, cmp) == 0)
+ found = true;
+ return false;
+}
+
+int main(void)
+{
+ struct strmap_charp {
+ STRMAP_MEMBERS(char *);
+ } map;
+
+ plan_tests(3);
+
+ strmap_init(&map);
+ ok1(strmap_add(&map, "hello", "hello"));
+ ok1(strmap_add(&map, "world", "world"));
+ strmap_iterate(&map, find_string, (const char *)"hello");
+ ok1(found);
+ strmap_clear(&map);
+
+ /* This exits depending on whether all tests passed */
+ return exit_status();
+}