From: Rusty Russell Date: Tue, 10 Jun 2014 01:37:36 +0000 (+0930) Subject: idtree: use ccan/tal instead of talloc X-Git-Url: https://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=3e44cbb718d3b315fea131106f6ccc6feb11ccc0 idtree: use ccan/tal instead of talloc Signed-off-by: Rusty Russell --- diff --git a/ccan/idtree/_info b/ccan/idtree/_info index f04e00ef..664e7cf7 100644 --- a/ccan/idtree/_info +++ b/ccan/idtree/_info @@ -14,7 +14,7 @@ * * Example: * #include - * #include + * #include * #include * #include * @@ -46,7 +46,7 @@ int main(int argc, char *argv[]) return 1; if (strcmp(argv[1], "depends") == 0) { - printf("ccan/talloc\n"); + printf("ccan/tal\n"); return 0; } diff --git a/ccan/idtree/idtree.c b/ccan/idtree/idtree.c index b3b1d606..e8873926 100644 --- a/ccan/idtree/idtree.c +++ b/ccan/idtree/idtree.c @@ -25,7 +25,7 @@ */ #include -#include +#include #include #include @@ -87,7 +87,7 @@ static void free_layer(struct idtree *idp, struct idtree_layer *p) static int idtree_pre_get(struct idtree *idp) { while (idp->id_free_cnt < IDTREE_FREE_MAX) { - struct idtree_layer *pn = talloc_zero(idp, struct idtree_layer); + struct idtree_layer *pn = talz(idp, struct idtree_layer); if(pn == NULL) return (0); free_layer(idp, pn); @@ -313,14 +313,14 @@ bool idtree_remove(struct idtree *idp, int id) } while (idp->id_free_cnt >= IDTREE_FREE_MAX) { p = alloc_layer(idp); - talloc_free(p); + tal_free(p); } return true; } struct idtree *idtree_new(void *mem_ctx) { - return talloc_zero(mem_ctx, struct idtree); + return talz(mem_ctx, struct idtree); } int idtree_add(struct idtree *idp, const void *ptr, int limit) diff --git a/ccan/idtree/test/run-wrap.c b/ccan/idtree/test/run-wrap.c index 6a62323d..ee64ad11 100644 --- a/ccan/idtree/test/run-wrap.c +++ b/ccan/idtree/test/run-wrap.c @@ -17,6 +17,6 @@ int main(int argc, char *argv[]) ok1(idtree_remove(idtree, INT_MAX-1) == true); ok1(idtree_add_above(idtree, &i, INT_MAX-1, INT_MAX) == INT_MAX-1); ok1(idtree_add_above(idtree, &i, INT_MAX-1, INT_MAX) == -1); - talloc_free(idtree); + tal_free(idtree); exit(exit_status()); } diff --git a/ccan/idtree/test/run.c b/ccan/idtree/test/run.c index 99ea2daa..a3b4fb63 100644 --- a/ccan/idtree/test/run.c +++ b/ccan/idtree/test/run.c @@ -4,6 +4,16 @@ #define ALLOC_MAX (2 * IDTREE_SIZE) +static bool check_tal_parent(const tal_t *parent, const tal_t *ctx) +{ + while (ctx) { + if (ctx == parent) + return true; + ctx = tal_parent(ctx); + } + return false; +} + int main(int argc, char *argv[]) { unsigned int i; @@ -12,9 +22,9 @@ int main(int argc, char *argv[]) void *ctx; plan_tests(ALLOC_MAX * 5 + 2); - ctx = talloc_named_const(NULL, 1, "test root"); + ctx = tal(NULL, char); idtree = idtree_new(ctx); - ok1(talloc_find_parent_byname(idtree, "test root") == ctx); + ok1(check_tal_parent(ctx, idtree)); for (i = 0; i < ALLOC_MAX; i++) { int id = idtree_add(idtree, &allocated[i], ALLOC_MAX-1); @@ -42,6 +52,6 @@ int main(int argc, char *argv[]) for (i = 0; i < ALLOC_MAX; i++) { ok1(idtree_lookup(idtree, i) == &allocated[i]); } - talloc_free(ctx); + tal_free(ctx); exit(exit_status()); }