X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftal%2Ftal.h;h=86b56d35a3c26280a9915216a5443ebef78626e1;hb=6abc867fce8c3eba40eb26092d31e34b47dd9165;hp=efe21bc5eb1c619b1ad74c68b9505a2518279fd7;hpb=83c75170a2be2e3fa58a139f866e957aa6b82995;p=ccan diff --git a/ccan/tal/tal.h b/ccan/tal/tal.h index efe21bc5..86b56d35 100644 --- a/ccan/tal/tal.h +++ b/ccan/tal/tal.h @@ -286,39 +286,6 @@ tal_t *tal_parent(const tal_t *ctx); sizeof(type), (n), (extra), \ true, TAL_LABEL(type, "[]"))) -/** - * tal_strdup - duplicate a string - * @ctx: NULL, or tal allocated object to be parent. - * @p: the string to copy (can be take()). - */ -char *tal_strdup(const tal_t *ctx, const char *p); - -/** - * tal_strndup - duplicate a limited amount of a string. - * @ctx: NULL, or tal allocated object to be parent. - * @p: the string to copy (can be take()). - * @n: the maximum length to copy. - * - * Always gives a nul-terminated string, with strlen() <= @n. - */ -char *tal_strndup(const tal_t *ctx, const char *p, size_t n); - -/** - * tal_asprintf - allocate a formatted string - * @ctx: NULL, or tal allocated object to be parent. - * @fmt: the printf-style format (can be take()). - */ -char *tal_asprintf(const tal_t *ctx, const char *fmt, ...) PRINTF_FMT(2,3); - -/** - * tal_vasprintf - allocate a formatted string (va_list version) - * @ctx: NULL, or tal allocated object to be parent. - * @fmt: the printf-style format (can be take()). - * @va: the va_list containing the format args. - */ -char *tal_vasprintf(const tal_t *ctx, const char *fmt, va_list ap) - PRINTF_FMT(2,0); - /** * tal_set_backend - set the allocation or error functions to use @@ -338,6 +305,39 @@ void tal_set_backend(void *(*alloc_fn)(size_t size), void (*free_fn)(void *), void (*error_fn)(const char *msg)); +/** + * tal_expand - expand a tal array with contents. + * @a1p: a pointer to the tal array to expand. + * @a2: the second array (can be take()). + * @num2: the number of elements in the second array. + * + * Note that *@a1 and @a2 should be the same type. tal_count(@a1) will + * be increased by @num2. + * + * Example: + * int *arr1 = tal_arrz(NULL, int, 2); + * int arr2[2] = { 1, 3 }; + * + * tal_expand(&arr1, arr2, 2); + * assert(tal_count(arr1) == 4); + * assert(arr1[2] == 1); + * assert(arr1[3] == 3); + */ +#define tal_expand(a1p, a2, num2) \ + tal_expand_((void **)(a1p), (a2), sizeof**(a1p), \ + (num2) + 0*sizeof(*(a1p) == (a2))) + +/** + * tal_cleanup - remove pointers from NULL node + * + * Internally, tal keeps a list of nodes allocated from @ctx NULL; this + * prevents valgrind from noticing memory leaks. This re-initializes + * that list to empty. + * + * It also calls take_cleanup() for you. + */ +void tal_cleanup(void); + /** * tal_check - set the allocation or error functions to use @@ -407,6 +407,7 @@ void *tal_dup_(const tal_t *ctx, const void *p, size_t size, tal_t *tal_steal_(const tal_t *new_parent, const tal_t *t); bool tal_resize_(tal_t **ctxp, size_t size, size_t count); +bool tal_expand_(tal_t **ctxp, const void *src, size_t size, size_t count); bool tal_add_destructor_(const tal_t *ctx, void (*destroy)(void *me)); bool tal_del_destructor_(const tal_t *ctx, void (*destroy)(void *me));