X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftalloc%2Ftalloc.h;h=d27c68922c9c8f0d98a0b5fe76d3ea4b8093d3fb;hb=2d4243996a4ace6d4eac1da460dd5bbcb31304ce;hp=e65588cd57d3966b7b9108e35cfde35706d05797;hpb=d40331c745a6e4a56a3ea210ef9e1e264f7e6e5a;p=ccan diff --git a/ccan/talloc/talloc.h b/ccan/talloc/talloc.h index e65588cd..d27c6892 100644 --- a/ccan/talloc/talloc.h +++ b/ccan/talloc/talloc.h @@ -78,6 +78,29 @@ */ #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. @@ -557,7 +580,7 @@ char *talloc_strndup(const void *t, const char *p, size_t n); * * talloc_set_name_const(ptr, ptr) */ -char *talloc_asprintf(const void *t, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3); +char *talloc_asprintf(const void *t, const char *fmt, ...) PRINTF_FMT(2,3); /** * talloc_append_string - concatenate onto a tallocated string @@ -587,7 +610,7 @@ char *WARN_UNUSED_RESULT talloc_append_string(char *orig, const char *append); * talloc_set_name_const(ptr, ptr) */ char *WARN_UNUSED_RESULT talloc_asprintf_append(char *s, const char *fmt, ...) - PRINTF_ATTRIBUTE(2,3); + PRINTF_FMT(2,3); /** * talloc_vasprintf - vsprintf into a talloc buffer. @@ -603,7 +626,8 @@ char *WARN_UNUSED_RESULT talloc_asprintf_append(char *s, const char *fmt, ...) * * talloc_set_name_const(ptr, ptr) */ -char *talloc_vasprintf(const void *t, const char *fmt, va_list ap) PRINTF_ATTRIBUTE(2,0); +char *talloc_vasprintf(const void *t, const char *fmt, va_list ap) + PRINTF_FMT(2,0); /** * talloc_vasprintf_append - sprintf onto the end of a talloc buffer. @@ -615,7 +639,7 @@ char *talloc_vasprintf(const void *t, const char *fmt, va_list ap) PRINTF_ATTRIB * talloc_asprintf_append(), except it takes a va_list. */ char *WARN_UNUSED_RESULT talloc_vasprintf_append(char *s, const char *fmt, va_list ap) - PRINTF_ATTRIBUTE(2,0); + PRINTF_FMT(2,0); /** * talloc_set_type - force the name of a pointer to a particular type @@ -691,7 +715,8 @@ int talloc_increase_ref_count(const void *ptr); * without releasing the name. All of the memory is released when the ptr is * freed using talloc_free(). */ -const char *talloc_set_name(const void *ptr, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3); +const char *talloc_set_name(const void *ptr, const char *fmt, ...) + PRINTF_FMT(2,3); /** * talloc_set_name_const - set a talloc pointer name to a string constant @@ -722,7 +747,7 @@ void talloc_set_name_const(const void *ptr, const char *name); * talloc_set_name(ptr, fmt, ....); */ void *talloc_named(const void *context, size_t size, - const char *fmt, ...) PRINTF_ATTRIBUTE(3,4); + const char *fmt, ...) PRINTF_FMT(3,4); /** * talloc_named_const - create a specifically-named talloc pointer @@ -765,7 +790,7 @@ void *talloc_check_name(const void *ptr, const char *name); * * talloc_named(NULL, 0, fmt, ...); */ -void *talloc_init(const char *fmt, ...) PRINTF_ATTRIBUTE(1,2); +void *talloc_init(const char *fmt, ...) PRINTF_FMT(1,2); /** * talloc_total_size - get the bytes used by the pointer and its children