gst_structure_to_string: display actual value of pointers

We used to always display "NULL" which was pretty confusing when
debugging.

https://bugzilla.gnome.org/show_bug.cgi?id=794355
This commit is contained in:
Guillaume Desmottes 2018-03-15 12:43:56 +01:00
parent 8833ca942e
commit 6dba0d91ed
2 changed files with 22 additions and 3 deletions

View file

@ -1823,10 +1823,15 @@ priv_gst_structure_append_to_gstring (const GstStructure * structure,
if (t) { if (t) {
g_string_append (s, t); g_string_append (s, t);
g_free (t); g_free (t);
} else if (G_TYPE_CHECK_VALUE_TYPE (&field->value, G_TYPE_POINTER)) {
gpointer ptr = g_value_get_pointer (&field->value);
if (!ptr)
g_string_append (s, "NULL");
else
g_string_append_printf (s, "%p", ptr);
} else { } else {
if (!G_TYPE_CHECK_VALUE_TYPE (&field->value, G_TYPE_STRING) && if (!G_TYPE_CHECK_VALUE_TYPE (&field->value, G_TYPE_STRING))
!(G_TYPE_CHECK_VALUE_TYPE (&field->value, G_TYPE_POINTER) &&
g_value_get_pointer (&field->value) == NULL))
GST_WARNING ("No value transform to serialize field '%s' of type '%s'", GST_WARNING ("No value transform to serialize field '%s' of type '%s'",
g_quark_to_string (field->name), g_quark_to_string (field->name),
_priv_gst_value_gtype_to_abbr (type)); _priv_gst_value_gtype_to_abbr (type));

View file

@ -274,6 +274,20 @@ GST_START_TEST (test_to_from_string)
gst_structure_free (st1); gst_structure_free (st1);
gst_structure_free (st2); gst_structure_free (st2);
/* pointers are serialized but not deserialized */
st1 = gst_structure_new ("test", "ptr", G_TYPE_POINTER, 0xdeadbeef, NULL);
str = gst_structure_to_string (st1);
/* The way pointers are serialized may be plateform specific so just check
* if it contains the address */
fail_unless (g_strrstr (str, "deadbeef") || g_strrstr (str, "DEADBEEF"),
"Failed to serialize to right string: %s", str);
st2 = gst_structure_from_string (str, NULL);
fail_unless (!st2);
gst_structure_free (st1);
g_free (str);
} }
GST_END_TEST; GST_END_TEST;