summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-02-13 09:35:05 +0100
committerThomas Haller <thaller@redhat.com>2020-02-13 10:46:34 +0100
commit487141d4a86282ce5cc6b98847af8acd11ca90b9 (patch)
tree33a7e88b249c8494eda8eae11a0ae9cfd4cc3df3
parent904050dd2dc09826e8ae59fd19eae95e8e7adcb7 (diff)
shared: add entry_cmd argument to NM_UTILS_STRING_TABLE_LOOKUP_DEFINE*() macro
This extra argument allows to tweak whether to assert for the input argument name.
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.h40
-rw-r--r--src/supplicant/nm-supplicant-interface.c1
2 files changed, 25 insertions, 16 deletions
diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h
index 9f75c7f81..3d211f39f 100644
--- a/shared/nm-glib-aux/nm-shared-utils.h
+++ b/shared/nm-glib-aux/nm-shared-utils.h
@@ -1543,7 +1543,12 @@ guint8 *nm_utils_hexstr2bin_alloc (const char *hexstr,
/*****************************************************************************/
-#define _NM_UTILS_STRING_TABLE_LOOKUP_DEFINE(scope, fcn_name, result_type, unknown_val, ...) \
+#define _NM_UTILS_STRING_TABLE_LOOKUP_DEFINE(scope, \
+ fcn_name, \
+ result_type, \
+ entry_cmd, \
+ unknown_val_cmd, \
+ ...) \
scope result_type \
fcn_name (const char *name) \
{ \
@@ -1553,9 +1558,8 @@ fcn_name (const char *name) \
} LIST[] = { \
__VA_ARGS__ \
}; \
- gssize idx; \
\
- nm_assert (name); \
+ { entry_cmd; } \
\
if (NM_MORE_ASSERTS > 5) { \
static gboolean checked = FALSE; \
@@ -1574,22 +1578,26 @@ fcn_name (const char *name) \
} \
} \
\
- idx = nm_utils_array_find_binary_search (LIST, \
- sizeof (LIST[0]), \
- G_N_ELEMENTS (LIST), \
- &name, \
- nm_strcmp_p_with_data, \
- NULL); \
- if (idx >= 0) \
- return LIST[idx].value; \
+ if (G_LIKELY (name)) { \
+ gssize idx; \
+ \
+ idx = nm_utils_array_find_binary_search (LIST, \
+ sizeof (LIST[0]), \
+ G_N_ELEMENTS (LIST), \
+ &name, \
+ nm_strcmp_p_with_data, \
+ NULL); \
+ if (G_LIKELY (idx >= 0)) \
+ return LIST[idx].value; \
+ } \
\
- { unknown_val; } \
+ { unknown_val_cmd; } \
}
-#define NM_UTILS_STRING_TABLE_LOOKUP_DEFINE(fcn_name, lookup_type, unknown_val, ...) \
- _NM_UTILS_STRING_TABLE_LOOKUP_DEFINE (, fcn_name, lookup_type, unknown_val, __VA_ARGS__)
-#define NM_UTILS_STRING_TABLE_LOOKUP_DEFINE_STATIC(fcn_name, lookup_type, unknown_val, ...) \
- _NM_UTILS_STRING_TABLE_LOOKUP_DEFINE (static, fcn_name, lookup_type, unknown_val, __VA_ARGS__)
+#define NM_UTILS_STRING_TABLE_LOOKUP_DEFINE(fcn_name, lookup_type, entry_cmd, unknown_val_cmd, ...) \
+ _NM_UTILS_STRING_TABLE_LOOKUP_DEFINE (, fcn_name, lookup_type, entry_cmd, unknown_val_cmd, __VA_ARGS__)
+#define NM_UTILS_STRING_TABLE_LOOKUP_DEFINE_STATIC(fcn_name, lookup_type, entry_cmd, unknown_val_cmd, ...) \
+ _NM_UTILS_STRING_TABLE_LOOKUP_DEFINE (static, fcn_name, lookup_type, entry_cmd, unknown_val_cmd, __VA_ARGS__)
/*****************************************************************************/
diff --git a/src/supplicant/nm-supplicant-interface.c b/src/supplicant/nm-supplicant-interface.c
index 099a8c306..ba162e237 100644
--- a/src/supplicant/nm-supplicant-interface.c
+++ b/src/supplicant/nm-supplicant-interface.c
@@ -189,6 +189,7 @@ NM_UTILS_LOOKUP_STR_DEFINE (nm_supplicant_interface_state_to_string, NMSupplican
NM_UTILS_STRING_TABLE_LOOKUP_DEFINE_STATIC (
wpas_state_string_to_enum,
NMSupplicantInterfaceState,
+ { nm_assert (name); },
{ return NM_SUPPLICANT_INTERFACE_STATE_INVALID; },
{ "4way_handshake", NM_SUPPLICANT_INTERFACE_STATE_4WAY_HANDSHAKE },
{ "associated", NM_SUPPLICANT_INTERFACE_STATE_ASSOCIATED },