From bab7778b5b487af80b1372eb86d4c7c741963116 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 6 Sep 2021 22:12:27 +0930 Subject: [PATCH] libplugin: allow take() for commands, notif_subs, hook_subs, notif_topics. Useful for plugins which dynamically generate them. Signed-off-by: Rusty Russell --- plugins/libplugin.c | 24 ++++++++++++++++-------- plugins/libplugin.h | 8 ++++---- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/plugins/libplugin.c b/plugins/libplugin.c index 2393b1c09..dd27b83df 100644 --- a/plugins/libplugin.c +++ b/plugins/libplugin.c @@ -1370,13 +1370,13 @@ static struct plugin *new_plugin(const tal_t *ctx, const enum plugin_restartability restartability, bool init_rpc, struct feature_set *features STEALS, - const struct plugin_command *commands, + const struct plugin_command *commands TAKES, size_t num_commands, - const struct plugin_notification *notif_subs, + const struct plugin_notification *notif_subs TAKES, size_t num_notif_subs, - const struct plugin_hook *hook_subs, + const struct plugin_hook *hook_subs TAKES, size_t num_hook_subs, - const char **notif_topics, + const char **notif_topics TAKES, size_t num_notif_topics, va_list ap) { @@ -1414,12 +1414,20 @@ static struct plugin *new_plugin(const tal_t *ctx, p->in_timer = 0; p->commands = commands; + if (taken(commands)) + tal_steal(p, commands); p->num_commands = num_commands; p->notif_topics = notif_topics; + if (taken(notif_topics)) + tal_steal(p, notif_topics); p->num_notif_topics = num_notif_topics; p->notif_subs = notif_subs; + if (taken(notif_subs)) + tal_steal(p, notif_subs); p->num_notif_subs = num_notif_subs; p->hook_subs = hook_subs; + if (taken(hook_subs)) + tal_steal(p, hook_subs); p->num_hook_subs = num_hook_subs; p->opts = tal_arr(p, struct plugin_option, 0); @@ -1443,13 +1451,13 @@ void plugin_main(char *argv[], const enum plugin_restartability restartability, bool init_rpc, struct feature_set *features STEALS, - const struct plugin_command *commands, + const struct plugin_command *commands TAKES, size_t num_commands, - const struct plugin_notification *notif_subs, + const struct plugin_notification *notif_subs TAKES, size_t num_notif_subs, - const struct plugin_hook *hook_subs, + const struct plugin_hook *hook_subs TAKES, size_t num_hook_subs, - const char **notif_topics, + const char **notif_topics TAKES, size_t num_notif_topics, ...) { diff --git a/plugins/libplugin.h b/plugins/libplugin.h index 8f6d56336..0b1bf14ca 100644 --- a/plugins/libplugin.h +++ b/plugins/libplugin.h @@ -293,13 +293,13 @@ void NORETURN LAST_ARG_NULL plugin_main(char *argv[], const enum plugin_restartability restartability, bool init_rpc, struct feature_set *features STEALS, - const struct plugin_command *commands, + const struct plugin_command *commands TAKES, size_t num_commands, - const struct plugin_notification *notif_subs, + const struct plugin_notification *notif_subs TAKES, size_t num_notif_subs, - const struct plugin_hook *hook_subs, + const struct plugin_hook *hook_subs TAKES, size_t num_hook_subs, - const char **notif_topics, + const char **notif_topics TAKES, size_t num_notif_topics, ...);