g_strdup_value_contents(): dump GStrv more usefully
authorWill Thompson <will.thompson@collabora.co.uk>
Thu, 9 Sep 2010 16:24:00 +0000 (17:24 +0100)
committerWill Thompson <will.thompson@collabora.co.uk>
Mon, 13 Sep 2010 18:19:46 +0000 (19:19 +0100)
Previously, dumping a GValue holding a GStrv just yielded "((GStrv *)
0xDEADBEEF)". I think it'd be more useful to dump a Python list-style
representation of the GStrv's contents, if it's not NULL.

Fixes: <https://bugzilla.gnome.org/show_bug.cgi?id=629192>

gobject/gvaluetypes.c

index 8bd612f..aa22b2d 100644 (file)
@@ -1339,6 +1339,25 @@ g_strdup_value_contents (const GValue *value)
        contents = g_strdup_printf ("((%s*) %p)", G_OBJECT_TYPE_NAME (p), p);
       else if (G_VALUE_HOLDS_PARAM (value))
        contents = g_strdup_printf ("((%s*) %p)", G_PARAM_SPEC_TYPE_NAME (p), p);
+      else if (G_VALUE_HOLDS (value, G_TYPE_STRV))
+        {
+          GStrv strv = g_value_get_boxed (value);
+          GString *tmp = g_string_new ("[");
+
+          while (*strv != NULL)
+            {
+              gchar *escaped = g_strescape (*strv, NULL);
+
+              g_string_append_printf (tmp, "\"%s\"", escaped);
+              g_free (escaped);
+
+              if (*++strv != NULL)
+                g_string_append (tmp, ", ");
+            }
+
+          g_string_append (tmp, "]");
+          contents = g_string_free (tmp, FALSE);
+        }
       else if (G_VALUE_HOLDS_BOXED (value))
        contents = g_strdup_printf ("((%s*) %p)", g_type_name (G_VALUE_TYPE (value)), p);
       else if (G_VALUE_HOLDS_POINTER (value))