Browse Source

idtree: use ccan/tal instead of talloc

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Rusty Russell 11 years ago
parent
commit
3e44cbb718
4 changed files with 20 additions and 10 deletions
  1. 2 2
      ccan/idtree/_info
  2. 4 4
      ccan/idtree/idtree.c
  3. 1 1
      ccan/idtree/test/run-wrap.c
  4. 13 3
      ccan/idtree/test/run.c

+ 2 - 2
ccan/idtree/_info

@@ -14,7 +14,7 @@
  *
  * Example:
  *	#include <ccan/idtree/idtree.h>
- *	#include <ccan/talloc/talloc.h>
+ *	#include <ccan/tal/tal.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) {
-		printf("ccan/talloc\n");
+		printf("ccan/tal\n");
 		return 0;
 	}
 

+ 4 - 4
ccan/idtree/idtree.c

@@ -25,7 +25,7 @@
 */
 
 #include <ccan/idtree/idtree.h>
-#include <ccan/talloc/talloc.h>
+#include <ccan/tal/tal.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) {
-		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)

+ 1 - 1
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());
 }

+ 13 - 3
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());
 }