]> git.ozlabs.org Git - ccan/commitdiff
idtree: use ccan/tal instead of talloc
authorRusty Russell <rusty@rustcorp.com.au>
Tue, 10 Jun 2014 01:37:36 +0000 (11:07 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 10 Jun 2014 01:37:36 +0000 (11:07 +0930)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/idtree/_info
ccan/idtree/idtree.c
ccan/idtree/test/run-wrap.c
ccan/idtree/test/run.c

index f04e00ef4c6b1eebfb03aaa3552383f57fc05c01..664e7cf7ea567fea17ccc5ba68a97015c56bcd84 100644 (file)
@@ -14,7 +14,7 @@
  *
  * Example:
  *     #include <ccan/idtree/idtree.h>
  *
  * Example:
  *     #include <ccan/idtree/idtree.h>
- *     #include <ccan/talloc/talloc.h>
+ *     #include <ccan/tal/tal.h>
  *     #include <stdlib.h>
  *     #include <stdio.h>
  *
  *     #include <stdlib.h>
  *     #include <stdio.h>
  *
@@ -46,7 +46,7 @@ int main(int argc, char *argv[])
                return 1;
 
        if (strcmp(argv[1], "depends") == 0) {
                return 1;
 
        if (strcmp(argv[1], "depends") == 0) {
-               printf("ccan/talloc\n");
+               printf("ccan/tal\n");
                return 0;
        }
 
                return 0;
        }
 
index b3b1d606156a8ab79b2066cdadcfa8c8a34ef674..e8873926a79c07a21b7b843f06b3b4cfaa7078c9 100644 (file)
@@ -25,7 +25,7 @@
 */
 
 #include <ccan/idtree/idtree.h>
 */
 
 #include <ccan/idtree/idtree.h>
-#include <ccan/talloc/talloc.h>
+#include <ccan/tal/tal.h>
 #include <stdint.h>
 #include <string.h>
 
 #include <stdint.h>
 #include <string.h>
 
@@ -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) {
 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);
                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);
        }
        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 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)
 }
 
 int idtree_add(struct idtree *idp, const void *ptr, int limit)
index 6a62323d4eb2f1c4efcc047e4f972009d1f376f8..ee64ad1198d02a2634e8e44b50506caf7d1c3402 100644 (file)
@@ -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);
        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());
 }
        exit(exit_status());
 }
index 99ea2daa1d6da512c582c9bf8389ef8b8135b526..a3b4fb63a877c1703d4628b612ed0b5501da832b 100644 (file)
@@ -4,6 +4,16 @@
 
 #define ALLOC_MAX (2 * IDTREE_SIZE)
 
 
 #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;
 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);
        void *ctx;
 
        plan_tests(ALLOC_MAX * 5 + 2);
-       ctx = talloc_named_const(NULL, 1, "test root");
+       ctx = tal(NULL, char);
        idtree = idtree_new(ctx);
        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);
 
        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]);
        }
        for (i = 0; i < ALLOC_MAX; i++) {
                ok1(idtree_lookup(idtree, i) == &allocated[i]);
        }
-       talloc_free(ctx);
+       tal_free(ctx);
        exit(exit_status());
 }
        exit(exit_status());
 }