summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-04-23 15:23:16 +0200
committerThomas Haller <thaller@redhat.com>2019-04-23 16:04:34 +0200
commit9d328e73a737e4688b2cd6b7ba9b670a5b4ce1e3 (patch)
treedd7390418b549f365926c4ac3f1121160367d808
parent62a511ac60058bd0f4b0f856a3ff5fbc51380de6 (diff)
downloadNetworkManager-9d328e73a737e4688b2cd6b7ba9b670a5b4ce1e3.tar.gz
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.
-rw-r--r--clients/cli/nmcli.c16
-rw-r--r--clients/common/nm-meta-setting-desc.c38
2 files changed, 26 insertions, 28 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
@@ -916,18 +916,6 @@ signal_handler (gpointer user_data)
}
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)
{
GHashTable *hash;
@@ -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 3a7e766115..a231615eec 100644
--- a/clients/common/nm-meta-setting-desc.c
+++ b/clients/common/nm-meta-setting-desc.c
@@ -809,7 +809,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;
@@ -828,13 +827,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
@@ -846,16 +846,9 @@ _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);
+ nm_assert (!handle_emptyunset);
- if (str)
- RETURN_STR_TO_FREE (str);
- RETURN_STR_TEMPORARY (cstr);
+ RETURN_STR_TEMPORARY (g_value_get_string (&val));
}
if (gtype_prop == G_TYPE_BOOLEAN) {
@@ -869,6 +862,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;
}