Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
*
* 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>
*
return 1;
if (strcmp(argv[1], "depends") == 0) {
return 1;
if (strcmp(argv[1], "depends") == 0) {
- printf("ccan/talloc\n");
*/
#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>
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);
}
while (idp->id_free_cnt >= IDTREE_FREE_MAX) {
p = alloc_layer(idp);
}
while (idp->id_free_cnt >= IDTREE_FREE_MAX) {
p = alloc_layer(idp);
}
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)
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);
#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;
void *ctx;
plan_tests(ALLOC_MAX * 5 + 2);
void *ctx;
plan_tests(ALLOC_MAX * 5 + 2);
- ctx = talloc_named_const(NULL, 1, "test root");
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);
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]);
}