1 /* MIT (BSD) license - see LICENSE file for details */
2 #ifndef CCAN_TAL_AUTOPTR_H
3 #define CCAN_TAL_AUTOPTR_H
4 #include <ccan/tal/tal.h>
9 * autonull_set_ptr - set a pointer, NULL it when pointer tal_free'd.
10 * @ctx: the tal context which owns this autonull.
11 * @pp: pointer to tal pointer
12 * @p: the tal pointer to set *@pp to.
14 * *@pp is set to @p. When @p is tal_free'd directly or indirectly, *@pp will
15 * be set to NULL. Or, if the returned object is freed, the callback is
28 * struct parent *p = tal(NULL, struct parent);
29 * struct child *c = tal(p, struct child);
32 * autonull_set_ptr(p, &p->c, c);
35 * // Automatically clears p->c.
37 * assert(p->c == NULL);
42 #define autonull_set_ptr(ctx, pp, p) \
43 autonull_set_ptr_((ctx), (pp) + 0*sizeof(*(pp) = (p)), (p))
45 struct autonull *autonull_set_ptr_(const tal_t *ctx, void *pp, const tal_t *p);
47 #endif /* CCAN_TAL_AUTOPTR_H */