diff options
author | Thomas Haller <thaller@redhat.com> | 2020-04-28 16:39:09 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-05-04 12:47:07 +0200 |
commit | 867964d7e0fd3efb40bf2ac7f644c82ac997a73e (patch) | |
tree | a7c3d0198edd2988d42c0f8e9ff769e511b0ada6 | |
parent | d4615e73ed54ca90db666e4c846635a3e8292994 (diff) | |
download | NetworkManager-867964d7e0fd3efb40bf2ac7f644c82ac997a73e.tar.gz |
keyfile: refactor defining keyfile getter/setter functions
Split the macros to define the setter and getter so that setters
and getters are defined by separate macros. This will be used
to define the boolean getter differently, but still using the
macro to define the setter.
Also, don't construct function names in the macro. Instead, pass
the full names as argument to the macro. This helps with the problem
where ctags/cscope is unable to locate the implementation of the
function. Since we define the function with macro, the tools still
don't recognize this as the location of the definition. But at least
when showing all occurrences of the name, it can be found.
-rw-r--r-- | shared/nm-keyfile/nm-keyfile-utils.c | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/shared/nm-keyfile/nm-keyfile-utils.c b/shared/nm-keyfile/nm-keyfile-utils.c index 041b5eab11..a0965f8481 100644 --- a/shared/nm-keyfile/nm-keyfile-utils.c +++ b/shared/nm-keyfile/nm-keyfile-utils.c @@ -172,46 +172,50 @@ nm_keyfile_plugin_kf_set_integer_list_uint8 (GKeyFile *kf, nm_keyfile_plugin_kf_set_value (kf, group, key, value); } -/* Single value helpers */ -#define DEFINE_KF_WRAPPER(stype, get_ctype, set_ctype) \ +#define DEFINE_KF_WRAPPER_GET(fcn_name, get_ctype, key_file_get_fcn) \ get_ctype \ -nm_keyfile_plugin_kf_get_##stype (GKeyFile *kf, \ - const char *group, \ - const char *key, \ - GError **error) \ +fcn_name (GKeyFile *kf, \ + const char *group, \ + const char *key, \ + GError **error) \ { \ get_ctype val; \ const char *alias; \ GError *local = NULL; \ - \ - val = g_key_file_get_##stype (kf, group, key, &local); \ +\ + val = key_file_get_fcn (kf, group, key, &local); \ if (g_error_matches (local, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND)) { \ alias = nm_keyfile_plugin_get_alias_for_setting_name (group); \ if (alias) { \ g_clear_error (&local); \ - val = g_key_file_get_##stype (kf, alias, key, &local); \ + val = key_file_get_fcn (kf, alias, key, &local); \ } \ } \ if (local) \ g_propagate_error (error, local); \ return val; \ -} \ - \ +} + +DEFINE_KF_WRAPPER_GET (nm_keyfile_plugin_kf_get_string, char *, g_key_file_get_string); +DEFINE_KF_WRAPPER_GET (nm_keyfile_plugin_kf_get_boolean, gboolean, g_key_file_get_boolean); +DEFINE_KF_WRAPPER_GET (nm_keyfile_plugin_kf_get_value, char *, g_key_file_get_value); + +#define DEFINE_KF_WRAPPER_SET(fcn_name, set_ctype, key_file_set_fcn) \ void \ -nm_keyfile_plugin_kf_set_##stype (GKeyFile *kf, \ - const char *group, \ - const char *key, \ - set_ctype value) \ +fcn_name (GKeyFile *kf, \ + const char *group, \ + const char *key, \ + set_ctype value) \ { \ const char *alias; \ - \ +\ alias = nm_keyfile_plugin_get_alias_for_setting_name (group); \ - g_key_file_set_##stype (kf, alias ?: group, key, value); \ + key_file_set_fcn (kf, alias ?: group, key, value); \ } -DEFINE_KF_WRAPPER(string, char*, const char*); -DEFINE_KF_WRAPPER(boolean, gboolean, gboolean); -DEFINE_KF_WRAPPER(value, char*, const char*); +DEFINE_KF_WRAPPER_SET (nm_keyfile_plugin_kf_set_string, const char *, g_key_file_set_string); +DEFINE_KF_WRAPPER_SET (nm_keyfile_plugin_kf_set_boolean, gboolean, g_key_file_set_boolean); +DEFINE_KF_WRAPPER_SET (nm_keyfile_plugin_kf_set_value, const char *, g_key_file_set_value); gint64 nm_keyfile_plugin_kf_get_int64 (GKeyFile *kf, |