talloc_link.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* Licensed under GPLv2+ - see LICENSE file for details */
  2. #ifndef TALLOC_LINK_H
  3. #define TALLOC_LINK_H
  4. #include <ccan/talloc/talloc.h>
  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. * talloc_link - add another link to a linkable object.
  21. * @ctx - the context to link to
  22. * @obj - the object previously made linkable with talloc_linked().
  23. *
  24. * The @obj will only be freed when all contexts linked to it are
  25. * freed (or talloc_delink()ed).
  26. *
  27. * Returns @obj, or NULL on failure (out of memory).
  28. */
  29. #define talloc_link(ctx, obj) \
  30. ((_TALLOC_TYPEOF(obj))_talloc_link((ctx), (obj)))
  31. /**
  32. * talloc_delink - explicitly remove a link from a linkable object.
  33. * @ctx - the context previously used for talloc_link/talloc_linked
  34. * @obj - the object previously used for talloc_link/talloc_linked
  35. *
  36. * Explicitly remove a link: normally it is implied by freeing @ctx.
  37. * Removing the last link frees the object.
  38. */
  39. void talloc_delink(const void *ctx, const void *linked);
  40. /* Internal helpers. */
  41. void *_talloc_link(const void *ctx, const void *linked);
  42. void *_talloc_linked(const void *ctx, const void *linked);
  43. #endif /* TALLOC_LINK_H */