]> git.ozlabs.org Git - ccan/blobdiff - ccan/tal/tal.c
ccan/rune: simplify check helper interfaces, allow explicit string lengths.
[ccan] / ccan / tal / tal.c
index a49541114ff863128dd03a1429fa84c1d4e06ffb..061fc2907aff4cb5e67e8863c04a25233b9e5ea7 100644 (file)
@@ -767,11 +767,17 @@ out:
 }
 
 void *tal_dup_(const tal_t *ctx, const void *p, size_t size,
-              size_t n, size_t extra, const char *label)
+              size_t n, size_t extra, bool nullok, const char *label)
 {
        void *ret;
        size_t nbytes = size;
 
+       if (nullok && p == NULL) {
+               /* take(NULL) works. */
+               (void)taken(p);
+               return NULL;
+       }
+       
        if (!adjust_size(&nbytes, n)) {
                if (taken(p))
                        tal_free(p);
@@ -802,6 +808,11 @@ void *tal_dup_(const tal_t *ctx, const void *p, size_t size,
        return ret;
 }
 
+void *tal_dup_talarr_(const tal_t *ctx, const tal_t *src TAKES, const char *label)
+{
+       return tal_dup_(ctx, src, 1, tal_bytelen(src), 0, true, label);
+}
+
 void tal_set_backend(void *(*alloc_fn)(size_t size),
                     void *(*resize_fn)(void *, size_t size),
                     void (*free_fn)(void *),
@@ -824,36 +835,36 @@ static void dump_node(unsigned int indent, const struct tal_hdr *t)
         const struct prop_hdr *p;
 
        for (i = 0; i < indent; i++)
-               printf("  ");
-       printf("%p len=%zu", t, t->bytelen);
+               fprintf(stderr, "  ");
+       fprintf(stderr, "%p len=%zu", t, t->bytelen);
         for (p = t->prop; p; p = p->next) {
                struct children *c;
                struct name *n;
                struct notifier *no;
                 if (is_literal(p)) {
-                       printf(" \"%s\"", (const char *)p);
+                       fprintf(stderr, " \"%s\"", (const char *)p);
                        break;
                }
                switch (p->type) {
                case CHILDREN:
                        c = (struct children *)p;
-                       printf(" CHILDREN(%p):parent=%p,children={%p,%p}\n",
+                       fprintf(stderr, " CHILDREN(%p):parent=%p,children={%p,%p}",
                               p, c->parent,
                               c->children.n.prev, c->children.n.next);
                        break;
                case NAME:
                        n = (struct name *)p;
-                       printf(" NAME(%p):%s", p, n->name);
+                       fprintf(stderr, " NAME(%p):%s", p, n->name);
                        break;
                case NOTIFIER:
                        no = (struct notifier *)p;
-                       printf(" NOTIFIER(%p):fn=%p", p, no->u.notifyfn);
+                       fprintf(stderr, " NOTIFIER(%p):fn=%p", p, no->u.notifyfn);
                        break;
                default:
-                       printf(" **UNKNOWN(%p):%i**", p, p->type);
+                       fprintf(stderr, " **UNKNOWN(%p):%i**", p, p->type);
                }
        }
-       printf("\n");
+       fprintf(stderr, "\n");
 }
 
 static void tal_dump_(unsigned int level, const struct tal_hdr *t)