]> git.ozlabs.org Git - ccan/blobdiff - ccan/talloc/talloc.h
talloc: define TALLOC_CTX
[ccan] / ccan / talloc / talloc.h
index e65588cd57d3966b7b9108e35cfde35706d05797..58b406e54b8002b47fce9305725b07491868174e 100644 (file)
  */
 #define talloc(ctx, type) (type *)talloc_named_const(ctx, sizeof(type), #type)
 
  */
 #define talloc(ctx, type) (type *)talloc_named_const(ctx, sizeof(type), #type)
 
+/**
+ * TALLOC_CTX - indicate that a pointer is used as a talloc parent.
+ *
+ * As talloc is a hierarchial memory allocator, every talloc chunk is a
+ * potential parent to other talloc chunks. So defining a separate type for a
+ * talloc chunk is not strictly necessary. TALLOC_CTX is defined nevertheless,
+ * as it provides an indicator for function arguments.
+ *
+ * Example:
+ *     struct foo {
+ *             int val;
+ *     };
+ *
+ *     static struct foo *foo_new(TALLOC_CTX *mem_ctx)
+ *     {
+ *             struct foo *foo = talloc(mem_ctx, struct foo);
+ *             if (foo)
+ *                     foo->val = 0;
+ *     return foo;
+ *     }
+ */
+typedef void TALLOC_CTX;
+
 /**
  * talloc_set - allocate dynamic memory for a type, into a pointer
  * @ptr: pointer to the pointer to assign.
 /**
  * talloc_set - allocate dynamic memory for a type, into a pointer
  * @ptr: pointer to the pointer to assign.