From 3cad82d7af5af55a13108018737e55dceb312907 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 31 Aug 2024 15:25:05 +0300 Subject: [PATCH 27/27] Give log level deprecation warnings regardless of parameter order Make deprecation warning about numeric log level pending. Log it if later parameter enables deprecation warnings. See osdn #45954 Signed-off-by: Marko Lindqvist --- utility/deprecations.c | 27 +++++++++++++++++++++++++++ utility/deprecations.h | 2 ++ utility/log.c | 2 +- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/utility/deprecations.c b/utility/deprecations.c index 5414bf931d..98008b30d8 100644 --- a/utility/deprecations.c +++ b/utility/deprecations.c @@ -29,12 +29,19 @@ static deprecation_warn_callback depr_cb = nullptr; static bool depr_warns_enabled = FALSE; +static char depr_pending[1024] = ""; + /********************************************************************//** Enable deprecation warnings. ************************************************************************/ void deprecation_warnings_enable(void) { depr_warns_enabled = TRUE; + + if (depr_pending[0] != '\0') { + do_log_deprecation("%s", depr_pending); + depr_pending[0] = '\0'; + } } /********************************************************************//** @@ -69,3 +76,23 @@ void do_log_deprecation(const char *format, ...) } va_end(args); } + +/********************************************************************//** + Even if deprecations are not enabled yet, add the message + to the pending queue (currently can contain just one message). + Message will be logged if deprecations later get enabled. +************************************************************************/ +void deprecation_pending(const char *format, ...) +{ + va_list args; + + va_start(args, format); + fc_vsnprintf(depr_pending, sizeof(depr_pending), format, args); + va_end(args); + + if (depr_warns_enabled) { + /* Enabled already. Log */ + do_log_deprecation("%s", depr_pending); + depr_pending[0] = '\0'; + } +} diff --git a/utility/deprecations.h b/utility/deprecations.h index 0417b2d14b..5ffbc6e7be 100644 --- a/utility/deprecations.h +++ b/utility/deprecations.h @@ -31,6 +31,8 @@ bool are_deprecation_warnings_enabled(void); void do_log_deprecation(const char *format, ...) fc__attribute((__format__ (__printf__, 1, 2))); +void deprecation_pending(const char *format, ...) + fc__attribute((__format__ (__printf__, 1, 2))); #define log_deprecation(message, ...) \ do { \ diff --git a/utility/log.c b/utility/log.c index 663ff80dd8..e15420fd59 100644 --- a/utility/log.c +++ b/utility/log.c @@ -121,7 +121,7 @@ bool log_parse_level_str(const char *level_str, enum log_level *ret_level) } } else { /* TRANS: Do not translate log level names that user has to provide in English */ - log_deprecation( _("Do not provide log level with a numerical value." + deprecation_pending( _("Do not provide log level with a numerical value." " Use one of the levels Fatal, Error, Warning, Normal, Verbose, Debug") ); } if (level <= max_level) { -- 2.45.2