From d4d1e5f00d0bdf03f55e06d157c793ecdb472b2c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 23 Apr 2019 15:23:16 +0200 Subject: cli: drop GValue transform function for G_TYPE_STRV to G_TYPE_STRING It's ugly to modify the global behavior of glib to convert between types. Instead, _get_fcn_gobject_impl() is perfectly capable to implement converting a strv array to string. --- clients/cli/nmcli.c | 16 ------------- clients/common/nm-meta-setting-desc.c | 45 ++++++++++++++++++++++++----------- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/clients/cli/nmcli.c b/clients/cli/nmcli.c index d8300e780c..2f401e134f 100644 --- a/clients/cli/nmcli.c +++ b/clients/cli/nmcli.c @@ -915,18 +915,6 @@ signal_handler (gpointer user_data) return G_SOURCE_CONTINUE; } -static void -nmc_convert_strv_to_string (const GValue *src_value, GValue *dest_value) -{ - char **strings; - - strings = g_value_get_boxed (src_value); - if (strings) - g_value_take_string (dest_value, g_strjoinv (",", strings)); - else - g_value_set_string (dest_value, ""); -} - static void nmc_convert_string_hash_to_string (const GValue *src_value, GValue *dest_value) { @@ -981,10 +969,6 @@ nmc_convert_bytes_to_string (const GValue *src_value, GValue *dest_value) static void nmc_value_transforms_register (void) { - g_value_register_transform_func (G_TYPE_STRV, - G_TYPE_STRING, - nmc_convert_strv_to_string); - /* This depends on the fact that all of the hash-table-valued properties * in libnm-core are string->string. */ diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c index d02d62b9ad..5bb9a3e8e7 100644 --- a/clients/common/nm-meta-setting-desc.c +++ b/clients/common/nm-meta-setting-desc.c @@ -821,7 +821,6 @@ _get_fcn_gobject_impl (const NMMetaPropertyInfo *property_info, gboolean *out_is_default, gpointer *out_to_free) { - char *str = NULL; const char *cstr; GType gtype_prop; nm_auto_unset_gvalue GValue val = G_VALUE_INIT; @@ -836,13 +835,14 @@ _get_fcn_gobject_impl (const NMMetaPropertyInfo *property_info, gtype_prop = _gobject_property_get_gtype (G_OBJECT (setting), property_info->property_name); - glib_handles_str_transform = !NM_IN_SET (gtype_prop, G_TYPE_BOOLEAN); + glib_handles_str_transform = !NM_IN_SET (gtype_prop, G_TYPE_BOOLEAN, + G_TYPE_STRV); if (glib_handles_str_transform) { /* We rely on the type convertion of the gobject property to string. * * Note that we register some transformations via nmc_value_transforms_register() - * to make that working for G_TYPE_STRV, G_TYPE_HASH_TABLE, and G_TYPE_BYTES. + * to make that working for G_TYPE_HASH_TABLE, and G_TYPE_BYTES. * * FIXME: that is particularly ugly because it's non-obvious which code relies * on nmc_value_transforms_register(). Also, nmc_value_transforms_register() is @@ -853,18 +853,14 @@ _get_fcn_gobject_impl (const NMMetaPropertyInfo *property_info, g_object_get_property (G_OBJECT (setting), property_info->property_name, &val); - if (glib_handles_str_transform) { - cstr = g_value_get_string (&val); - - /* special hack for handling properties that can be empty and unset - * (see multilist.clear_emptyunset_fcn). */ - if (handle_emptyunset) - cstr = _coerce_str_emptyunset (get_type, is_default, cstr, &str); + /* Currently only one particular property asks us to "handle_emptyunset". + * So, don't implement it (yet) for the other types, where it's unneeded. */ + nm_assert ( !handle_emptyunset + || ( gtype_prop == G_TYPE_STRV + && !glib_handles_str_transform)); - if (str) - RETURN_STR_TO_FREE (str); - RETURN_STR_TEMPORARY (cstr); - } + if (glib_handles_str_transform) + RETURN_STR_TEMPORARY (g_value_get_string (&val)); if (gtype_prop == G_TYPE_BOOLEAN) { gboolean b; @@ -877,6 +873,27 @@ _get_fcn_gobject_impl (const NMMetaPropertyInfo *property_info, return cstr; } + if (gtype_prop == G_TYPE_STRV) { + const char *const*strv; + + strv = g_value_get_boxed (&val); + if (strv && strv[0]) + RETURN_STR_TO_FREE (g_strjoinv (",", (char **) strv)); + + /* special hack for handling properties that can be empty and unset + * (see multilist.clear_emptyunset_fcn). */ + if (handle_emptyunset) { + char *str = NULL; + + cstr = _coerce_str_emptyunset (get_type, is_default, NULL, &str); + if (str) + RETURN_STR_TO_FREE (str); + RETURN_STR_TEMPORARY (cstr); + } + + return ""; + } + nm_assert_not_reached (); return NULL; } -- cgit v1.2.1