* 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.
tal_t *tal_parent(const tal_t *ctx);
/**
- * tal_dup - duplicate an array.
+ * tal_dup - duplicate an object.
+ * @ctx: The tal allocated object to be parent of the result (may be NULL).
+ * @type: the type (should match type of @p!)
+ * @p: the object to copy (or reparented if take())
+ */
+#define tal_dup(ctx, type, p) \
+ ((type *)tal_dup_((ctx), tal_typechk_(p, type *), \
+ sizeof(type), 1, 0, \
+ false, TAL_LABEL(type, "")))
+
+/**
+ * tal_dup_arr - duplicate an array.
* @ctx: The tal allocated object to be parent of the result (may be NULL).
* @type: the type (should match type of @p!)
* @p: the array to copy (or resized & reparented if take())
* @n: the number of sizeof(type) entries to copy.
* @extra: the number of extra sizeof(type) entries to allocate.
*/
-#define tal_dup(ctx, type, p, n, extra) \
+#define tal_dup_arr(ctx, type, p, n, extra) \
((type *)tal_dup_((ctx), tal_typechk_(p, type *), \
sizeof(type), (n), (extra), \
true, TAL_LABEL(type, "[]")))
/**
- * 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);
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));