talloc_link.h 1.5 KB

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