From 7c9e016fb794f308653738310328e810cae6ff8b Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 23 Oct 2025 14:23:03 +1030 Subject: [PATCH] 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 --- common/msg_queue.c | 13 ++----------- common/utils.c | 10 ++++++++++ common/utils.h | 5 ++++- plugins/libplugin.c | 12 +----------- 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/common/msg_queue.c b/common/msg_queue.c index 566bb3bff..091b8380f 100644 --- a/common/msg_queue.c +++ b/common/msg_queue.c @@ -2,6 +2,7 @@ #include #include #include +#include #include 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); diff --git a/common/utils.c b/common/utils.c index 01047ea57..e467c19de 100644 --- a/common/utils.c +++ b/common/utils.c @@ -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; +} + diff --git a/common/utils.h b/common/utils.h index 45b91f87f..a4f3ed97a 100644 --- a/common/utils.h +++ b/common/utils.h @@ -8,8 +8,8 @@ #include #include +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) diff --git a/plugins/libplugin.c b/plugins/libplugin.c index 5b5c2f4eb..836e1768a 100644 --- a/plugins/libplugin.c +++ b/plugins/libplugin.c @@ -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;