6 * tal/stack - stack of tal contextes (inspired by talloc_stack)
8 * Implement a stack of tal contexts. A new (empty) context is pushed on top
9 * of the stack using tal_newframe and it is popped/freed using tal_free().
10 * tal_curframe() can be used to get the stack's top context.
12 * tal_stack can be used to implement per-function temporary allocation context
13 * to help mitigating memory leaks, but unlike the plain tal approach it does not
14 * require the caller to pass a destination context for returning allocated
15 * values. Instead, allocated values are moved to the parent context using
16 * tal_steal(tal_parent(tmp_ctx), ptr).
20 * #include <ccan/tal/stack/stack.h>
22 * static int *do_work(void)
25 * tal_t *tmp_ctx = tal_newframe();
27 * int *val = talz(tmp_ctx, int);
28 * assert(val != NULL);
30 * // ... do something with val ...
33 * // steal to parent cxt so it survives tal_free()
34 * tal_steal(tal_parent(tmp_ctx), val);
41 * int main(int argc, char *argv[])
43 * tal_t *tmp_ctx = tal_newframe();
44 * int *val = do_work();
46 * // ... do something with val ...
48 * // val is eventually freed
54 * Author: Delio Brignoli <brignoli.delio@gmail.com>
56 int main(int argc, char *argv[])
58 /* Expect exactly one argument */
62 if (strcmp(argv[1], "depends") == 0) {