common: export helper membuf_tal_realloc.

We have to call it membuf_tal_resize() because the other on is
a ccan/json_out static function!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2025-10-23 14:23:03 +10:30
parent e28fed7504
commit 7c9e016fb7
4 changed files with 17 additions and 23 deletions

View File

@@ -2,6 +2,7 @@
#include <ccan/membuf/membuf.h>
#include <common/daemon.h>
#include <common/msg_queue.h>
#include <common/utils.h>
#include <wire/wire.h>
static bool warned_once;
@@ -33,21 +34,11 @@ static void destroy_msg_queue(struct msg_queue *q)
}
}
/* Realloc helper for tal membufs */
static void *membuf_tal_realloc(struct membuf *mb, void *rawelems,
size_t newsize)
{
char *p = rawelems;
tal_resize(&p, newsize);
return p;
}
struct msg_queue *msg_queue_new(const tal_t *ctx, bool fd_passing)
{
struct msg_queue *q = tal(ctx, struct msg_queue);
q->fd_passing = fd_passing;
membuf_init(&q->mb, tal_arr(q, const u8 *, 0), 0, membuf_tal_realloc);
membuf_init(&q->mb, tal_arr(q, const u8 *, 0), 0, membuf_tal_resize);
if (q->fd_passing)
tal_add_destructor(q, destroy_msg_queue);

View File

@@ -194,3 +194,13 @@ char *str_lowering(const void *ctx, const char *string TAKES)
for (char *p = ret; *p; p++) *p = tolower(*p);
return ret;
}
/* Realloc helper for tal membufs */
void *membuf_tal_resize(struct membuf *mb, void *rawelems, size_t newsize)
{
char *p = rawelems;
tal_resize(&p, newsize);
return p;
}

View File

@@ -8,8 +8,8 @@
#include <ccan/tal/tal.h>
#include <secp256k1.h>
struct membuf;
extern secp256k1_context *secp256k1_ctx;
extern const struct chainparams *chainparams;
/* Unsigned min/max macros: BUILD_ASSERT make sure types are unsigned */
@@ -163,6 +163,9 @@ extern const tal_t *wally_tal_ctx;
* Returns created temporary path name at *created if successful. */
int tmpdir_mkstemp(const tal_t *ctx, const char *template TAKES, char **created);
/* For use with membuf_init */
void *membuf_tal_resize(struct membuf *mb, void *rawelems, size_t newsize);
/**
* tal_strlowering - return the same string by in lower case.
* @ctx: the context to tal from (often NULL)

View File

@@ -538,16 +538,6 @@ struct json_out *json_out_obj(const tal_t *ctx,
return jout;
}
/* Realloc helper for tal membufs */
static void *membuf_tal_realloc(struct membuf *mb, void *rawelems,
size_t newsize)
{
char *p = rawelems;
tal_resize(&p, newsize);
return p;
}
static int read_json_from_rpc(struct plugin *p)
{
char *end;
@@ -1597,7 +1587,7 @@ static struct command_result *handle_init(struct command *cmd,
with_rpc = true;
membuf_init(&p->rpc_conn->mb, tal_arr(p, char, READ_CHUNKSIZE),
READ_CHUNKSIZE, membuf_tal_realloc);
READ_CHUNKSIZE, membuf_tal_resize);
} else
with_rpc = false;