From fe17acf07b0816c9629ee4a9642b53b43c32939d Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 1 Nov 2019 10:08:00 +1030 Subject: [PATCH] TAGS: reformat to fix when PRINTF_FMT() used. I was wondering why TAGS was missing some functions, and finally tracked it down: PRINTF_FMT() confuses etags if it's at the start of a function, and it ignores the rest of the file. So we put PRINTF_FMT at the end, but that doesn't work for *definitions*, only *declarations*. So we remove it from definitions and add gratuitous declarations in the few static places.1 Signed-off-by: Rusty Russell --- ccan/ccan/json_out/json_out.h | 4 ++-- connectd/connectd.c | 26 +++++++++++++++++++------- gossipd/seeker.c | 12 ++++++++---- hsmd/hsmd.c | 15 ++++++++++----- lightningd/channel.h | 8 ++++---- lightningd/htlc_end.c | 6 ++++-- lightningd/json_stream.h | 3 +-- lightningd/log.c | 2 +- lightningd/plugin.c | 2 +- lightningd/plugin.h | 2 +- plugins/libplugin.h | 2 +- 11 files changed, 52 insertions(+), 30 deletions(-) diff --git a/ccan/ccan/json_out/json_out.h b/ccan/ccan/json_out/json_out.h index 2911ff247..72cc32a1e 100644 --- a/ccan/ccan/json_out/json_out.h +++ b/ccan/ccan/json_out/json_out.h @@ -87,11 +87,11 @@ bool json_out_end(struct json_out *jout, char type); * If the resulting string requires escaping, and @quote is true, we * call json_escape(). */ -PRINTF_FMT(4,5) bool json_out_add(struct json_out *jout, const char *fieldname, bool quote, - const char *fmt, ...); + const char *fmt, ...) + PRINTF_FMT(4,5); /** * json_out_addv - add a formatted member (vararg variant) diff --git a/connectd/connectd.c b/connectd/connectd.c index f57171d8e..4e44c49ac 100644 --- a/connectd/connectd.c +++ b/connectd/connectd.c @@ -558,13 +558,25 @@ struct io_plan *connection_out(struct io_conn *conn, struct connecting *connect) handshake_out_success, connect); } -/*~ When we've exhausted all addresses without success, we come here. */ -static void PRINTF_FMT(5,6) - connect_failed(struct daemon *daemon, - const struct node_id *id, - u32 seconds_waited, - const struct wireaddr_internal *addrhint, - const char *errfmt, ...) +/*~ When we've exhausted all addresses without success, we come here. + * + * Note that gcc gets upset if we put the PRINTF_FMT at the end like this if + * it's an actual function definition, but etags gets confused and ignores the + * rest of the file if we put PRINTF_FMT at the front. So we put it at the + * end, in a gratuitous declaration. + */ +static void connect_failed(struct daemon *daemon, + const struct node_id *id, + u32 seconds_waited, + const struct wireaddr_internal *addrhint, + const char *errfmt, ...) + PRINTF_FMT(5,6); + +static void connect_failed(struct daemon *daemon, + const struct node_id *id, + u32 seconds_waited, + const struct wireaddr_internal *addrhint, + const char *errfmt, ...) { u8 *msg; va_list ap; diff --git a/gossipd/seeker.c b/gossipd/seeker.c index 5c49ae5d1..5856d58ae 100644 --- a/gossipd/seeker.c +++ b/gossipd/seeker.c @@ -115,10 +115,14 @@ static bool selected_peer(struct seeker *seeker, struct peer *peer) #define set_state(seeker, state, peer, ...) \ set_state_((seeker), (state), (peer), stringify(state), __VA_ARGS__) -static void PRINTF_FMT(5,6) - set_state_(struct seeker *seeker, enum seeker_state state, - struct peer *peer, - const char *statename, const char *fmt, ...) +static void set_state_(struct seeker *seeker, enum seeker_state state, + struct peer *peer, + const char *statename, const char *fmt, ...) +PRINTF_FMT(5,6); + +static void set_state_(struct seeker *seeker, enum seeker_state state, + struct peer *peer, + const char *statename, const char *fmt, ...) { va_list ap; va_start(ap, fmt); diff --git a/hsmd/hsmd.c b/hsmd/hsmd.c index af33f8a44..22c20222a 100644 --- a/hsmd/hsmd.c +++ b/hsmd/hsmd.c @@ -142,11 +142,16 @@ static struct io_plan *handle_client(struct io_conn *conn, struct client *c); * and closes the client connection. This should never happen, of course, but * we definitely want to log if it does. */ -static PRINTF_FMT(4,5) - struct io_plan *bad_req_fmt(struct io_conn *conn, - struct client *c, - const u8 *msg_in, - const char *fmt, ...) +static struct io_plan *bad_req_fmt(struct io_conn *conn, + struct client *c, + const u8 *msg_in, + const char *fmt, ...) + PRINTF_FMT(4,5); + +static struct io_plan *bad_req_fmt(struct io_conn *conn, + struct client *c, + const u8 *msg_in, + const char *fmt, ...) { va_list ap; char *str; diff --git a/lightningd/channel.h b/lightningd/channel.h index d1dc65ac8..3b4f150da 100644 --- a/lightningd/channel.h +++ b/lightningd/channel.h @@ -183,11 +183,11 @@ const char *channel_state_str(enum channel_state state); void channel_set_owner(struct channel *channel, struct subd *owner); /* Channel has failed, but can try again. */ -PRINTF_FMT(2,3) void channel_fail_reconnect(struct channel *channel, - const char *fmt, ...); +void channel_fail_reconnect(struct channel *channel, + const char *fmt, ...) PRINTF_FMT(2,3); /* Channel has failed, but can try again after a minute. */ -PRINTF_FMT(2,3) void channel_fail_reconnect_later(struct channel *channel, - const char *fmt,...); +void channel_fail_reconnect_later(struct channel *channel, + const char *fmt,...) PRINTF_FMT(2,3); /* Channel has failed, give up on it. */ void channel_fail_permanent(struct channel *channel, const char *fmt, ...); diff --git a/lightningd/htlc_end.c b/lightningd/htlc_end.c index a1b70649e..ab3737767 100644 --- a/lightningd/htlc_end.c +++ b/lightningd/htlc_end.c @@ -58,8 +58,10 @@ void connect_htlc_out(struct htlc_out_map *map, struct htlc_out *hend) htlc_out_map_add(map, hend); } -static void *PRINTF_FMT(2,3) - corrupt(const char *abortstr, const char *fmt, ...) +static void *corrupt(const char *abortstr, const char *fmt, ...) + PRINTF_FMT(2,3); + +static void *corrupt(const char *abortstr, const char *fmt, ...) { if (abortstr) { char *p; diff --git a/lightningd/json_stream.h b/lightningd/json_stream.h index 44d2bd96e..59a0a91ec 100644 --- a/lightningd/json_stream.h +++ b/lightningd/json_stream.h @@ -90,11 +90,10 @@ void json_stream_append(struct json_stream *js, const char *str, size_t len); * The resulting string from @fmt is escaped if quote is true: * see json_member_direct to avoid quoting. */ -PRINTF_FMT(4,5) void json_add_member(struct json_stream *js, const char *fieldname, bool quote, - const char *fmt, ...); + const char *fmt, ...) PRINTF_FMT(4,5); /** * json_member_direct - start a generic member. diff --git a/lightningd/log.c b/lightningd/log.c index 388426623..618cf15df 100644 --- a/lightningd/log.c +++ b/lightningd/log.c @@ -140,7 +140,7 @@ struct log_book *new_log_book(struct lightningd *ld, size_t max_mem, } /* With different entry points */ -struct log *PRINTF_FMT(3,4) +struct log * new_log(const tal_t *ctx, struct log_book *record, const char *fmt, ...) { struct log *log = tal(ctx, struct log); diff --git a/lightningd/plugin.c b/lightningd/plugin.c index 917aa21c6..a73d0eb4e 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -135,7 +135,7 @@ bool plugin_remove(struct plugins *plugins, const char *name) return removed; } -void PRINTF_FMT(2,3) plugin_kill(struct plugin *plugin, char *fmt, ...) +void plugin_kill(struct plugin *plugin, char *fmt, ...) { char *msg; va_list ap; diff --git a/lightningd/plugin.h b/lightningd/plugin.h index 1130790e2..b858b1897 100644 --- a/lightningd/plugin.h +++ b/lightningd/plugin.h @@ -157,7 +157,7 @@ bool plugin_remove(struct plugins *plugins, const char *name); /** * Kill a plugin process, with an error message. */ -void PRINTF_FMT(2,3) plugin_kill(struct plugin *plugin, char *fmt, ...); +void plugin_kill(struct plugin *plugin, char *fmt, ...) PRINTF_FMT(2,3); /** * Send the configure message to all plugins. diff --git a/plugins/libplugin.h b/plugins/libplugin.h index 1eca2a6b6..b274ecc5b 100644 --- a/plugins/libplugin.h +++ b/plugins/libplugin.h @@ -142,7 +142,7 @@ struct plugin_timer *plugin_timer(struct plugin_conn *rpc, struct command_result *(*cb)(void)); /* Log something */ -void PRINTF_FMT(2, 3) plugin_log(enum log_level l, const char *fmt, ...); +void plugin_log(enum log_level l, const char *fmt, ...) PRINTF_FMT(2, 3); /* Macro to define arguments */ #define plugin_option(name, type, description, set, arg) \