X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftal%2Ftal.h;h=3da1e4203d8edcb332e4701d876c05091977acbc;hp=28be3f2034c133b276bc1a9e7f803df6fa033469;hb=291237b4fed863be74051274ac5ad9920cb33cc3;hpb=680aa496521811e7c60afb940bcae5024f4c6adb diff --git a/ccan/tal/tal.h b/ccan/tal/tal.h index 28be3f20..3da1e420 100644 --- a/ccan/tal/tal.h +++ b/ccan/tal/tal.h @@ -110,7 +110,22 @@ void *tal_free(const tal_t *p); * tal_resize(&p, 100); */ #define tal_resize(p, count) \ - tal_resize_((void **)(p), sizeof**(p), (count)) + tal_resize_((void **)(p), sizeof**(p), (count), false) + +/** + * tal_resizez - enlarge or reduce a tal_arr[z]; zero out extra. + * @p: A pointer to the tal allocated array to resize. + * @count: the number to allocate. + * + * This returns true on success (and may move *@p), or false on failure. + * If @p has a length property, it is updated on success. + * On expand, new elements are memset to 0 bytes. + * + * Example: + * tal_resizez(&p, 200); + */ +#define tal_resizez(p, count) \ + tal_resize_((void **)(p), sizeof**(p), (count), true) /** * tal_steal - change the parent of a tal-allocated pointer. @@ -327,15 +342,29 @@ void tal_set_backend(void *(*alloc_fn)(size_t size), 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 + * tal_check - sanity check a tal context and its children. * @ctx: a tal context, or NULL. * @errorstr: a string to prepend calls to error_fn, or NULL. * * This sanity-checks a tal tree (unless NDEBUG is defined, in which case * it simply returns true). If errorstr is not null, error_fn is called * when a problem is found, otherwise it is not. + * + * See also: + * tal_set_backend() */ bool tal_check(const tal_t *ctx, const char *errorstr); @@ -395,7 +424,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_resize_(tal_t **ctxp, size_t size, size_t count, bool clear); 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));