_info 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "config.h"
  2. #include <stdio.h>
  3. #include <string.h>
  4. /**
  5. * tal/stack - stack of tal contextes (inspired by talloc_stack)
  6. *
  7. * Implement a stack of tal contexts. A new (empty) context is pushed on top
  8. * of the stack using tal_newframe and it is popped/freed using tal_free().
  9. * tal_curframe() can be used to get the stack's top context.
  10. *
  11. * tal_stack can be used to implement per-function temporary allocation context
  12. * to help mitigating memory leaks, but unlike the plain tal approach it does not
  13. * require the caller to pass a destination context for returning allocated
  14. * values. Instead, allocated values are moved to the parent context using
  15. * tal_steal(tal_parent(tmp_ctx), ptr).
  16. *
  17. * Example:
  18. * #include <assert.h>
  19. * #include <ccan/tal/stack/stack.h>
  20. *
  21. * static int *do_work(void)
  22. * {
  23. * int *retval = NULL;
  24. * tal_t *tmp_ctx = tal_newframe();
  25. *
  26. * int *val = talz(tmp_ctx, int);
  27. * assert(val != NULL);
  28. *
  29. * // ... do something with val ...
  30. *
  31. * if (retval >= 0) {
  32. * // steal to parent cxt so it survives tal_free()
  33. * tal_steal(tal_parent(tmp_ctx), val);
  34. * retval = val;
  35. * }
  36. * tal_free(tmp_ctx);
  37. * return retval;
  38. * }
  39. *
  40. * int main(int argc, char *argv[])
  41. * {
  42. * tal_t *tmp_ctx = tal_newframe();
  43. * int *val = do_work();
  44. * if (val) {
  45. * // ... do something with val ...
  46. * }
  47. * // val is eventually freed
  48. * tal_free(tmp_ctx);
  49. * return 0;
  50. * }
  51. *
  52. * License: BSD-MIT
  53. * Author: Delio Brignoli <brignoli.delio@gmail.com>
  54. */
  55. int main(int argc, char *argv[])
  56. {
  57. /* Expect exactly one argument */
  58. if (argc != 2)
  59. return 1;
  60. if (strcmp(argv[1], "depends") == 0) {
  61. printf("ccan/tal\n");
  62. return 0;
  63. }
  64. return 1;
  65. }