diff --git a/ccan_compat.h b/ccan_compat.h index 7be0efb88..1c648dabe 100644 --- a/ccan_compat.h +++ b/ccan_compat.h @@ -19,5 +19,9 @@ /* Transition for ccan update. */ #define tal_bytelen(x) tal_len(x) +#define tal_arr_label(ctx, type, len, label) \ + ((type *)tal_alloc_arr_(ctx, sizeof(type), len, false, true, label)) +#define tal_arrz_label(ctx, type, len, label) \ + ((type *)tal_alloc_arr_(ctx, sizeof(type), len, true, true, label)) #endif /* LIGHTNING_CCAN_COMPAT_H */ diff --git a/cli/lightning-cli.c b/cli/lightning-cli.c index 35ee46336..1c791b3f3 100644 --- a/cli/lightning-cli.c +++ b/cli/lightning-cli.c @@ -24,8 +24,7 @@ /* Tal wrappers for opt. */ static void *opt_allocfn(size_t size) { - return tal_alloc_(NULL, size, false, false, - TAL_LABEL("opt_allocfn", "")); + return tal_arr_label(NULL, char, size, TAL_LABEL("opt_allocfn", "")); } static void *tal_reallocfn(void *ptr, size_t size) diff --git a/common/json_escaped.c b/common/json_escaped.c index 9ae0b156a..4734c3d87 100644 --- a/common/json_escaped.c +++ b/common/json_escaped.c @@ -6,8 +6,8 @@ struct json_escaped *json_escaped_string_(const tal_t *ctx, { struct json_escaped *esc; - esc = tal_alloc_arr_(ctx, 1, len + 1, false, true, - TAL_LABEL(struct json_escaped, "")); + esc = (void *)tal_arr_label(ctx, char, len + 1, + TAL_LABEL(struct json_escaped, "")); memcpy(esc->s, bytes, len); esc->s[len] = '\0'; return esc; diff --git a/common/memleak.c b/common/memleak.c index 9660cd59c..d3284d0b0 100644 --- a/common/memleak.c +++ b/common/memleak.c @@ -224,8 +224,7 @@ static int append_bt(void *data, uintptr_t pc) static void add_backtrace(tal_t *parent UNUSED, enum tal_notify_type type UNNEEDED, void *child) { - uintptr_t *bt = tal_alloc_arr_(child, sizeof(uintptr_t), 32, true, true, - "backtrace"); + uintptr_t *bt = tal_arrz_label(child, uintptr_t, 32, "backtrace"); /* First serves as counter. */ bt[0] = 1; diff --git a/common/utils.c b/common/utils.c index 8ca22362f..3634f2484 100644 --- a/common/utils.c +++ b/common/utils.c @@ -39,7 +39,7 @@ void setup_locale(void) /* Initial creation of tmpctx. */ void setup_tmpctx(void) { - tmpctx = tal_alloc_(NULL, 0, false, false, "tmpctx"); + tmpctx = tal_arr_label(NULL, char, 0, "tmpctx"); } /* Free any children of tmpctx. */ @@ -48,6 +48,6 @@ void clean_tmpctx(void) /* Minor optimization: don't do anything if tmpctx unused. */ if (tal_first(tmpctx)) { tal_free(tmpctx); - tmpctx = tal_alloc_(NULL, 0, false, false, "tmpctx"); + tmpctx = tal_arr_label(NULL, char, 0, "tmpctx"); } } diff --git a/devtools/bolt11-cli.c b/devtools/bolt11-cli.c index c7eb3d9f2..5432896a5 100644 --- a/devtools/bolt11-cli.c +++ b/devtools/bolt11-cli.c @@ -26,8 +26,7 @@ /* Tal wrappers for opt. */ static void *opt_allocfn(size_t size) { - return tal_alloc_(NULL, size, false, false, - TAL_LABEL("opt_allocfn", "")); + return tal_arr_label(NULL, char, size, TAL_LABEL("opt_allocfn", "")); } static void *tal_reallocfn(void *ptr, size_t size) diff --git a/lightningd/options.c b/lightningd/options.c index d0f6a062e..ef72b56ee 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -39,7 +39,7 @@ bool deprecated_apis = true; /* Tal wrappers for opt. */ static void *opt_allocfn(size_t size) { - return tal_alloc_(NULL, size, false, false, TAL_LABEL("opt_allocfn", "")); + return tal_arr_label(NULL, char, size, TAL_LABEL("opt_allocfn", "")); } static void *tal_reallocfn(void *ptr, size_t size) diff --git a/lightningd/param.c b/lightningd/param.c index 5049efeaa..5569ec7ed 100644 --- a/lightningd/param.c +++ b/lightningd/param.c @@ -80,8 +80,7 @@ static bool make_callback(struct command *cmd, if (def->argsize && def->cb != (param_cb)json_tok_tok) { *(void **)def->arg = arg - = tal_alloc_(cmd, def->argsize, false, false, - "param"); + = tal_arr_label(cmd, char, def->argsize, "param"); } else arg = def->arg; if (!def->cb(buffer, tok, arg)) { diff --git a/wallet/db.c b/wallet/db.c index 57d401cf1..6c07e2998 100644 --- a/wallet/db.c +++ b/wallet/db.c @@ -701,7 +701,7 @@ void *sqlite3_column_arr_(const tal_t *ctx, sqlite3_stmt *stmt, int col, fatal("%s: column size %zu not a multiple of %s (%zu)", caller, sourcelen, label, bytes); - p = tal_alloc_arr_(ctx, bytes, sourcelen / bytes, false, true, label); + p = tal_arr_label(ctx, char, sourcelen, label); memcpy(p, sqlite3_column_blob(stmt, col), sourcelen); return p; }