diff options
author | Thomas Haller <thaller@redhat.com> | 2019-07-02 16:14:11 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-07-09 19:18:32 +0200 |
commit | 4d255924ea2af0a5375fe7ef74a59d5f64026d3a (patch) | |
tree | eb26e70b009705becfffb73cdc6603fedeecab05 | |
parent | 6c360e63e83d06f6f240051de922b66a4790325c (diff) | |
download | NetworkManager-4d255924ea2af0a5375fe7ef74a59d5f64026d3a.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.h | 8 |
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 { \ |