common: tal_dup_talarr() helper.

This is a common thing to do, so create a macro.

Unfortunately, it still needs the type arg, because the paramter may
be const, and the return cannot be, and C doesn't have a general
"(-const)" cast.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2020-02-27 12:47:01 +10:30
parent 684ed4231f
commit 2aad3ffcf8
21 changed files with 54 additions and 49 deletions

View File

@@ -77,8 +77,7 @@ static void destroy_peer(struct peer *peer)
static void peer_update_features(struct peer *peer, const u8 *features TAKES)
{
tal_free(peer->features);
peer->features = tal_dup_arr(peer, u8,
features, tal_count(features), 0);
peer->features = tal_dup_talarr(peer, u8, features);
}
struct peer *new_peer(struct lightningd *ld, u64 dbid,
@@ -386,9 +385,7 @@ void channel_errmsg(struct channel *channel,
/* Do we have an error to send? */
if (err_for_them && !channel->error)
channel->error = tal_dup_arr(channel, u8,
err_for_them,
tal_count(err_for_them), 0);
channel->error = tal_dup_talarr(channel, u8, err_for_them);
/* Other implementations chose to ignore errors early on. Not
* surprisingly, they now spew out spurious errors frequently,