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

@@ -68,7 +68,7 @@ static void set_pubkey(struct pubkey *key)
#define eq_var(p1, p2, field) \
(tal_count((p1)->field) == tal_count((p2)->field) \
&& (tal_count((p1)->field) == 0 || memcmp((p1)->field, (p2)->field, tal_len((p1)->field)) == 0))
&& (tal_count((p1)->field) == 0 || memcmp((p1)->field, (p2)->field, tal_bytelen((p1)->field)) == 0))
/* Convenience structs for everyone! */
struct msg_error {

View File

@@ -160,7 +160,7 @@ void towire_wirestring(u8 **pptr, const char *str)
void towire_bitcoin_tx(u8 **pptr, const struct bitcoin_tx *tx)
{
u8 *lin = linearize_tx(tmpctx, tx);
towire_u8_array(pptr, lin, tal_len(lin));
towire_u8_array(pptr, lin, tal_count(lin));
}
void towire_siphash_seed(u8 **pptr, const struct siphash_seed *seed)

View File

@@ -104,7 +104,7 @@ static int do_write_wire_header(int fd, struct io_plan_arg *arg)
static int do_write_wire(int fd, struct io_plan_arg *arg)
{
ssize_t ret;
size_t totlen = tal_len(arg->u1.cp);
size_t totlen = tal_bytelen(arg->u1.cp);
/* Still writing header? */
if (arg->u2.s & INSIDE_HEADER_BIT)
@@ -131,13 +131,14 @@ struct io_plan *io_write_wire_(struct io_conn *conn,
{
struct io_plan_arg *arg = io_plan_arg(conn, IO_OUT);
if (tal_len(data) >= INSIDE_HEADER_BIT) {
if (tal_bytelen(data) >= INSIDE_HEADER_BIT) {
errno = E2BIG;
return io_close(conn);
}
arg->u1.const_vp = tal_dup_arr(conn, u8, memcheck(data, tal_len(data)),
tal_len(data), 0);
arg->u1.const_vp = tal_dup_arr(conn, u8,
memcheck(data, tal_bytelen(data)),
tal_bytelen(data), 0);
/* We use u2 to store the length we've written. */
arg->u2.s = INSIDE_HEADER_BIT;

View File

@@ -7,10 +7,10 @@
bool wire_sync_write(int fd, const void *msg TAKES)
{
wire_len_t hdr = cpu_to_wirelen(tal_len(msg));
wire_len_t hdr = cpu_to_wirelen(tal_bytelen(msg));
bool ret;
assert(tal_len(msg) < WIRE_LEN_LIMIT);
assert(tal_bytelen(msg) < WIRE_LEN_LIMIT);
ret = write_all(fd, &hdr, sizeof(hdr))
&& write_all(fd, msg, tal_count(msg));