}
static bool iterate(struct strset n,
- bool (*handle)(const char *, void *), void *data)
+ bool (*handle)(const char *, void *), const void *data)
{
if (n.u.s[0])
- return handle(n.u.s, data);
+ return handle(n.u.s, (void *)data);
if (unlikely(n.u.n->byte_num == (size_t)-1))
- return handle(n.u.n->child[0].u.s, data);
+ return handle(n.u.n->child[0].u.s, (void *)data);
return iterate(n.u.n->child[0], handle, data)
|| iterate(n.u.n->child[1], handle, data);
}
void strset_iterate_(const struct strset *set,
- bool (*handle)(const char *, void *), void *data)
+ bool (*handle)(const char *, void *), const void *data)
{
/* Empty set? */
if (!set->u.n)
const char *), \
(arg))
void strset_iterate_(const struct strset *set,
- bool (*handle)(const char *, void *), void *data);
+ bool (*handle)(const char *, void *), const void *data);
/**
--- /dev/null
+#include <ccan/strset/strset.h>
+#include <ccan/strset/strset.c>
+#include <ccan/tap/tap.h>
+
+static bool found = false;
+
+/* Make sure const args work. */
+static bool find_string(const char *str, const char *cmp)
+{
+ if (strcmp(str, cmp) == 0)
+ found = true;
+ return false;
+}
+
+int main(void)
+{
+ struct strset set;
+
+ plan_tests(3);
+
+ strset_init(&set);
+ ok1(strset_set(&set, "hello"));
+ ok1(strset_set(&set, "world"));
+ strset_iterate(&set, find_string, (const char *)"hello");
+ ok1(found);
+ strset_destroy(&set);
+
+ /* This exits depending on whether all tests passed */
+ return exit_status();
+}