if (ib->count[i] != count)
continue;
- id = tal_dup(ctx, u8, idsum_ptr(ib, i), ib->id_size, 0);
+ id = tal_dup_arr(ctx, u8, idsum_ptr(ib, i), ib->id_size, 0);
return id;
}
return NULL;
goto out;
len = strlen(base);
- ret = tal_dup(ctx, char, base, len, 1 + strlen(a) + 1);
+ ret = tal_dup_arr(ctx, char, base, len, 1 + strlen(a) + 1);
if (!ret)
goto out;
if (ret[len-1] != PATH_SEP)
static char *fixed_string(const tal_t *ctx,
const char *str, const char *path)
{
- char *ret = tal_dup(ctx, char, path, 0, strlen(str)+1);
+ char *ret = tal_dup_arr(ctx, char, path, 0, strlen(str)+1);
if (ret)
strcpy(ret, str);
return ret;
#else
c = tal_typechk_(parent, char *);
#endif
- c = tal_dup(parent, char, "hello", 6, 0);
+ c = tal_dup_arr(parent, char, "hello", 6, 0);
ok1(strcmp(c, "hello") == 0);
ok1(strcmp(tal_name(c), "char[]") == 0);
ok1(tal_parent(c) == parent);
tal_free(c);
/* Now with an extra byte. */
- c = tal_dup(parent, char, "hello", 6, 1);
+ c = tal_dup_arr(parent, char, "hello", 6, 1);
ok1(strcmp(c, "hello") == 0);
ok1(strcmp(tal_name(c), "char[]") == 0);
ok1(tal_parent(c) == parent);
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, "[]")))
#define tal_parent(ctx) talloc_parent(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_talloc_dup_((ctx), tal_talloc_typechk_(p, type *), \
+ sizeof(type), 1, 0, \
+ 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_talloc_dup_((ctx), tal_talloc_typechk_(p, type *), \
sizeof(type), (n), (extra), \
TAL_LABEL(type, "[]")))
origpi = tal_arr(NULL, int, 100);
ok1(origpi);
ok1(error_count == 0);
- pi = tal_dup(NULL, int, origpi, (size_t)-1, 0);
+ pi = tal_dup_arr(NULL, int, origpi, (size_t)-1, 0);
ok1(!pi);
ok1(error_count == 1);
- pi = tal_dup(NULL, int, origpi, 0, (size_t)-1);
+ pi = tal_dup_arr(NULL, int, origpi, 0, (size_t)-1);
ok1(!pi);
ok1(error_count == 2);
- pi = tal_dup(NULL, int, origpi, (size_t)-1UL / sizeof(int),
+ pi = tal_dup_arr(NULL, int, origpi, (size_t)-1UL / sizeof(int),
(size_t)-1UL / sizeof(int));
ok1(!pi);
ok1(error_count == 3);
/* This will still overflow when tal_hdr is added. */
- pi = tal_dup(NULL, int, origpi, (size_t)-1UL / sizeof(int) / 2,
+ pi = tal_dup_arr(NULL, int, origpi, (size_t)-1UL / sizeof(int) / 2,
(size_t)-1UL / sizeof(int) / 2);
ok1(!pi);
ok1(error_count == 4);
/* Now, check that with taltk() we free old one on failure. */
origpi = tal_arr(NULL, int, 100);
error_count = 0;
- pi = tal_dup(NULL, int, take(origpi), (size_t)-1, 0);
+ pi = tal_dup_arr(NULL, int, take(origpi), (size_t)-1, 0);
ok1(!pi);
ok1(error_count == 1);
origpi = tal_arr(NULL, int, 100);
error_count = 0;
- pi = tal_dup(NULL, int, take(origpi), 0, (size_t)-1);
+ pi = tal_dup_arr(NULL, int, take(origpi), 0, (size_t)-1);
ok1(!pi);
ok1(error_count == 1);
ok1(talloc_total_blocks(NULL) == 1);
origpi = tal_arr(NULL, int, 100);
error_count = 0;
- pi = tal_dup(NULL, int, take(origpi), (size_t)-1UL / sizeof(int),
+ pi = tal_dup_arr(NULL, int, take(origpi), (size_t)-1UL / sizeof(int),
(size_t)-1UL / sizeof(int));
ok1(!pi);
ok1(error_count == 1);
origpi = tal_arr(NULL, int, 100);
error_count = 0;
/* This will still overflow when tal_hdr is added. */
- pi = tal_dup(NULL, int, take(origpi), (size_t)-1UL / sizeof(int) / 2,
+ pi = tal_dup_arr(NULL, int, take(origpi), (size_t)-1UL / sizeof(int) / 2,
(size_t)-1UL / sizeof(int) / 2);
ok1(!pi);
ok1(error_count == 1);
c = tal(parent, char);
*c = 'h';
- c = tal_dup(parent, char, take(c), 1, 0);
+ c = tal_dup(parent, char, take(c));
ok1(c[0] == 'h');
ok1(tal_parent(c) == parent);
- c = tal_dup(parent, char, take(c), 1, 2);
+ c = tal_dup_arr(parent, char, take(c), 1, 2);
ok1(c[0] == 'h');
strcpy(c, "hi");
ok1(tal_parent(c) == parent);
/* dup must reparent child. */
- c = tal_dup(NULL, char, take(c), 1, 0);
+ c = tal_dup(NULL, char, take(c));
ok1(c[0] == 'h');
ok1(tal_parent(c) == NULL);
/* NULL pass-through. */
c = NULL;
- ok1(tal_dup(NULL, char, take(c), 5, 5) == NULL);
+ ok1(tal_dup_arr(NULL, char, take(c), 5, 5) == NULL);
ok1(!taken_any());
return exit_status();
origpi = tal_arr(NULL, int, 100);
ok1(origpi);
ok1(error_count == 0);
- pi = tal_dup(NULL, int, origpi, (size_t)-1, 0);
+ pi = tal_dup_arr(NULL, int, origpi, (size_t)-1, 0);
ok1(!pi);
ok1(error_count == 1);
- pi = tal_dup(NULL, int, origpi, 0, (size_t)-1);
+ pi = tal_dup_arr(NULL, int, origpi, 0, (size_t)-1);
ok1(!pi);
ok1(error_count == 2);
- pi = tal_dup(NULL, int, origpi, (size_t)-1UL / sizeof(int),
+ pi = tal_dup_arr(NULL, int, origpi, (size_t)-1UL / sizeof(int),
(size_t)-1UL / sizeof(int));
ok1(!pi);
ok1(error_count == 3);
/* This will still overflow when tal_hdr is added. */
- pi = tal_dup(NULL, int, origpi, (size_t)-1UL / sizeof(int) / 2,
+ pi = tal_dup_arr(NULL, int, origpi, (size_t)-1UL / sizeof(int) / 2,
(size_t)-1UL / sizeof(int) / 2);
ok1(!pi);
ok1(error_count == 4);
/* Now, check that with taltk() we free old one on failure. */
origpi = tal_arr(NULL, int, 100);
error_count = 0;
- pi = tal_dup(NULL, int, take(origpi), (size_t)-1, 0);
+ pi = tal_dup_arr(NULL, int, take(origpi), (size_t)-1, 0);
ok1(!pi);
ok1(error_count == 1);
origpi = tal_arr(NULL, int, 100);
error_count = 0;
- pi = tal_dup(NULL, int, take(origpi), 0, (size_t)-1);
+ pi = tal_dup_arr(NULL, int, take(origpi), 0, (size_t)-1);
ok1(!pi);
ok1(error_count == 1);
ok1(!tal_first(NULL));
origpi = tal_arr(NULL, int, 100);
error_count = 0;
- pi = tal_dup(NULL, int, take(origpi), (size_t)-1UL / sizeof(int),
+ pi = tal_dup_arr(NULL, int, take(origpi), (size_t)-1UL / sizeof(int),
(size_t)-1UL / sizeof(int));
ok1(!pi);
ok1(error_count == 1);
origpi = tal_arr(NULL, int, 100);
error_count = 0;
/* This will still overflow when tal_hdr is added. */
- pi = tal_dup(NULL, int, take(origpi), (size_t)-1UL / sizeof(int) / 2,
+ pi = tal_dup_arr(NULL, int, take(origpi), (size_t)-1UL / sizeof(int) / 2,
(size_t)-1UL / sizeof(int) / 2);
ok1(!pi);
ok1(error_count == 1);
c = tal(parent, char);
*c = 'h';
- c = tal_dup(parent, char, take(c), 1, 0);
+ c = tal_dup(parent, char, take(c));
ok1(c[0] == 'h');
ok1(tal_parent(c) == parent);
- c = tal_dup(parent, char, take(c), 1, 2);
+ c = tal_dup_arr(parent, char, take(c), 1, 2);
ok1(c[0] == 'h');
strcpy(c, "hi");
ok1(tal_parent(c) == parent);
/* dup must reparent child. */
- c = tal_dup(NULL, char, take(c), 1, 0);
+ c = tal_dup(NULL, char, take(c));
ok1(c[0] == 'h');
ok1(tal_parent(c) == NULL);
/* NULL pass-through. */
c = NULL;
- ok1(tal_dup(NULL, char, take(c), 5, 5) == NULL);
+ ok1(tal_dup_arr(NULL, char, take(c), 5, 5) == NULL);
ok1(!taken_any());
tal_cleanup();
}
/* Now remove NUL and append test dependencies to deps. */
- deps = tal_dup(m, char *, take(deps), core_deps, test_deps + 2);
+ deps = tal_dup_arr(m, char *, take(deps), core_deps, test_deps + 2);
memcpy(deps + core_deps, tdeps, sizeof(tdeps[0]) * test_deps);
/* ccan/tap is given a free pass. */
deps[core_deps + test_deps] = (char *)"ccan/tap";