summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-07-02 16:14:11 +0200
committerThomas Haller <thaller@redhat.com>2019-07-10 12:43:06 +0200
commit6d30021feee57df33c184e71cfc2a86b90632b5f (patch)
tree71c4d05e012279eb42b0b8ef1d5c0d4ca5673677
parent7f75a1b5f500127fbecebc4921a3f7d1f8546565 (diff)
downloadNetworkManager-6d30021feee57df33c184e71cfc2a86b90632b5f.tar.gz
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().
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.h8
1 files changed, 7 insertions, 1 deletions
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 { \