Remove tal_len, use tal_count() or tal_bytelen().

tal_count() is used where there's a type, even if it's char or u8, and
tal_bytelen() is going to replace tal_len() for clarity: it's only needed
where a pointer is void.

We shim tal_bytelen() for now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2018-07-28 15:30:16 +09:30
committed by Christian Decker
parent eae9b81099
commit 5cf34d6618
57 changed files with 200 additions and 195 deletions

View File

@@ -57,8 +57,8 @@ void towire_gossip_getnodes_entry(u8 **pptr,
for (i=0; i<numaddresses; i++) {
towire_wireaddr(pptr, &entry->addresses[i]);
}
towire_u8(pptr, tal_len(entry->alias));
towire(pptr, entry->alias, tal_len(entry->alias));
towire_u8(pptr, tal_count(entry->alias));
towire(pptr, entry->alias, tal_count(entry->alias));
towire(pptr, entry->color, sizeof(entry->color));
}
@@ -127,8 +127,8 @@ fromwire_peer_features(const tal_t *ctx, const u8 **pptr, size_t *max)
void towire_peer_features(u8 **pptr, const struct peer_features *pf)
{
towire_u16(pptr, tal_len(pf->local_features));
towire_u8_array(pptr, pf->local_features, tal_len(pf->local_features));
towire_u16(pptr, tal_len(pf->global_features));
towire_u8_array(pptr, pf->global_features, tal_len(pf->global_features));
towire_u16(pptr, tal_count(pf->local_features));
towire_u8_array(pptr, pf->local_features, tal_count(pf->local_features));
towire_u16(pptr, tal_count(pf->global_features));
towire_u8_array(pptr, pf->global_features, tal_count(pf->global_features));
}

View File

@@ -732,10 +732,10 @@ static void json_decodepay(struct command *cmd,
json_array_start(response, "extra");
list_for_each(&b11->extra_fields, extra, list) {
char *data = tal_arr(cmd, char, tal_len(extra->data)+1);
char *data = tal_arr(cmd, char, tal_count(extra->data)+1);
size_t i;
for (i = 0; i < tal_len(extra->data); i++)
for (i = 0; i < tal_count(extra->data); i++)
data[i] = bech32_charset[extra->data[i]];
data[i] = '\0';
json_object_start(response, NULL);

View File

@@ -98,7 +98,7 @@ static void log_to_stdout(const char *prefix,
static size_t mem_used(const struct log_entry *e)
{
return sizeof(*e) + strlen(e->log) + 1 + tal_len(e->io);
return sizeof(*e) + strlen(e->log) + 1 + tal_count(e->io);
}
static size_t prune_log(struct log_book *log)

View File

@@ -14,7 +14,7 @@ bool log_status_msg(struct log *log, const u8 *msg)
}
} else if (fromwire_status_io(msg, msg, &level, &who, &data)) {
if (level == LOG_IO_IN || level == LOG_IO_OUT) {
log_io(log, level, who, data, tal_len(data));
log_io(log, level, who, data, tal_count(data));
return true;
}
}

View File

@@ -239,7 +239,7 @@ static char *opt_set_rgb(const char *arg, struct lightningd *ld)
* byte is the green value, and the last byte is the blue value.
*/
ld->rgb = tal_hexdata(ld, arg, strlen(arg));
if (!ld->rgb || tal_len(ld->rgb) != 3)
if (!ld->rgb || tal_count(ld->rgb) != 3)
return tal_fmt(NULL, "rgb '%s' is not six hex digits", arg);
return NULL;
}

View File

@@ -71,7 +71,7 @@ static void copy_to_parent_log(const char *prefix,
struct log *parent_log)
{
if (level == LOG_IO_IN || level == LOG_IO_OUT)
log_io(parent_log, level, prefix, io, tal_len(io));
log_io(parent_log, level, prefix, io, tal_count(io));
else if (continued)
log_add(parent_log, "%s ... %s", prefix, str);
else
@@ -388,7 +388,7 @@ void channel_errmsg(struct channel *channel,
if (err_for_them && !channel->error)
channel->error = tal_dup_arr(channel, u8,
err_for_them,
tal_len(err_for_them), 0);
tal_count(err_for_them), 0);
/* Make sure channel_fail_permanent doesn't tell connectd we died! */
channel->connected = false;
@@ -459,10 +459,10 @@ void peer_connected(struct lightningd *ld, const u8 *msg,
" and localfeatures %s",
tal_hexstr(msg,
global_features,
tal_len(global_features)),
tal_count(global_features)),
tal_hexstr(msg,
local_features,
tal_len(local_features)));
tal_count(local_features)));
goto send_error;
}

View File

@@ -95,7 +95,7 @@ static void fail_in_htlc(struct htlc_in *hin,
assert(failcode || failuremsg);
hin->failcode = failcode;
if (failuremsg)
hin->failuremsg = tal_dup_arr(hin, u8, failuremsg, tal_len(failuremsg), 0);
hin->failuremsg = tal_dup_arr(hin, u8, failuremsg, tal_count(failuremsg), 0);
/* We need this set, since we send it to channeld. */
if (hin->failcode & UPDATE)
@@ -377,7 +377,7 @@ static void rcvd_htlc_reply(struct subd *subd, const u8 *msg, const int *fds UNU
if (!hout->in) {
char *localfail = tal_fmt(msg, "%s: %.*s",
onion_type_name(failure_code),
(int)tal_len(failurestr),
(int)tal_count(failurestr),
(const char *)failurestr);
payment_failed(ld, hout, localfail);
} else
@@ -784,7 +784,7 @@ static bool peer_failed_our_htlc(struct channel *channel,
hout->failcode = failed->failcode;
if (!failed->failcode)
hout->failuremsg = tal_dup_arr(hout, u8, failed->failreason,
tal_len(failed->failreason), 0);
tal_count(failed->failreason), 0);
else
hout->failuremsg = NULL;
@@ -1348,7 +1348,7 @@ void peer_got_revoke(struct channel *channel, const u8 *msg)
static void *tal_arr_append_(void **p, size_t size)
{
size_t n = tal_len(*p) / size;
size_t n = tal_bytelen(*p) / size;
tal_resize_(p, size, n+1, false);
return (char *)(*p) + n * size;
}
@@ -1418,7 +1418,7 @@ static void add_fail(u64 id, enum side side,
if (failuremsg)
(*f)->failreason
= tal_dup_arr(*f, u8, failuremsg, tal_len(failuremsg), 0);
= tal_dup_arr(*f, u8, failuremsg, tal_count(failuremsg), 0);
else
(*f)->failreason = NULL;
*s = side;

View File

@@ -65,8 +65,8 @@ static void tx_must_be_eq(const struct bitcoin_tx *a,
lina = linearize_tx(tmpctx, a);
linb = linearize_tx(tmpctx, b);
for (i = 0; i < tal_len(lina); i++) {
if (i >= tal_len(linb))
for (i = 0; i < tal_count(lina); i++) {
if (i >= tal_count(linb))
errx(1, "Second tx is truncated:\n"
"%s\n"
"%s",
@@ -80,7 +80,7 @@ static void tx_must_be_eq(const struct bitcoin_tx *a,
tal_hex(tmpctx, lina),
tal_hex(tmpctx, linb));
}
if (i != tal_len(linb))
if (i != tal_count(linb))
errx(1, "First tx is truncated:\n"
"%s\n"
"%s",