Commit 932aeb6d authored by Rusty Russell's avatar Rusty Russell

strset: allow const arguments to strset_iterate().

parent 4ea280eb
......@@ -229,19 +229,19 @@ char *strset_clear(struct strset *set, const char *member)
}
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)
......
......@@ -139,7 +139,7 @@ void strset_destroy(struct strset *set);
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);
/**
......
#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();
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment