From 6d30021feee57df33c184e71cfc2a86b90632b5f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 2 Jul 2019 16:14:11 +0200 Subject: [PATCH] shared: optimize nm_utils_error_set() for string literals If there is only one argument, we can assume this is a plain string. That is especially the case, because g_set_error() is G_GNUC_PRINTF() and would warn if this would be a format string with missing parameters. This is for convenience. Previously, one was compelled to explicitly choose between nm_utils_error_set_literal() and nm_utils_error_set(). Now, it automatically chooses. Note that there are a few things that won't work, like nm_utils_error_set (error, code, "bogus %u escape"); But that's good. You get a compiler warning (as you used to) and it's clear in this case you really need nm_utils_error_set_literal(). --- shared/nm-glib-aux/nm-shared-utils.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h index 7de6c06208..e1a905c4de 100644 --- a/shared/nm-glib-aux/nm-shared-utils.h +++ b/shared/nm-glib-aux/nm-shared-utils.h @@ -759,7 +759,13 @@ nm_utils_error_set_literal (GError **error, int error_code, const char *literal) } #define nm_utils_error_set(error, error_code, ...) \ - g_set_error ((error), NM_UTILS_ERROR, error_code, __VA_ARGS__) + G_STMT_START { \ + if (NM_NARG (__VA_ARGS__) == 1) { \ + g_set_error_literal ((error), NM_UTILS_ERROR, (error_code), _NM_UTILS_MACRO_FIRST (__VA_ARGS__)); \ + } else { \ + g_set_error ((error), NM_UTILS_ERROR, (error_code), __VA_ARGS__); \ + } \ + } G_STMT_END #define nm_utils_error_set_errno(error, errsv, fmt, ...) \ G_STMT_START { \