]> git.ozlabs.org Git - ccan/blob - ccan/talloc_link/talloc_link.h
tap: don't _exit on success
[ccan] / ccan / talloc_link / talloc_link.h
1 #ifndef TALLOC_LINK_H
2 #define TALLOC_LINK_H
3 #include <ccan/talloc/talloc.h>
4
5 /**
6  * talloc_linked - set up an object with an initial link.
7  * @ctx - the context to initially link to
8  * @newobj - the newly allocated object (with a NULL parent)
9  *
10  * The object will be freed when @ctx is freed (or talloc_delink(ctx,
11  * newobj) is called), unless more links are added using
12  * talloc_link().
13  *
14  * For convenient chaining, it returns @newobj on success, or frees
15  * @newobj and returns NULL.
16  */
17 #define talloc_linked(ctx, newobj) \
18         ((_TALLOC_TYPEOF(newobj))_talloc_linked((ctx), (newobj)))
19
20 /**
21  * talloc_link - add another link to a linkable object.
22  * @ctx - the context to link to
23  * @obj - the object previously made linkable with talloc_linked().
24  *
25  * The @obj will only be freed when all contexts linked to it are
26  * freed (or talloc_delink()ed).
27  *
28  * Returns @obj, or NULL on failure (out of memory).
29  */
30 #define talloc_link(ctx, obj) \
31         ((_TALLOC_TYPEOF(obj))_talloc_link((ctx), (obj)))
32
33 /**
34  * talloc_delink - explicitly remove a link from a linkable object.
35  * @ctx - the context previously used for talloc_link/talloc_linked
36  * @obj - the object previously used for talloc_link/talloc_linked
37  *
38  * Explicitly remove a link: normally it is implied by freeing @ctx.
39  * Removing the last link frees the object.
40  */
41 void talloc_delink(const void *ctx, const void *linked);
42
43 /* Internal helpers. */
44 void *_talloc_link(const void *ctx, const void *linked);
45 void *_talloc_linked(const void *ctx, const void *linked);
46
47 #endif /* TALLOC_LINK_H */