gst_structure_to_string: display actual value of pointers
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Thu, 15 Mar 2018 11:43:56 +0000 (12:43 +0100)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Fri, 15 Jun 2018 09:37:24 +0000 (11:37 +0200)
We used to always display "NULL" which was pretty confusing when
debugging.

https://bugzilla.gnome.org/show_bug.cgi?id=794355

gst/gststructure.c
tests/check/gst/gststructure.c

index 3b4d5b8..5f7aad2 100644 (file)
@@ -1823,10 +1823,15 @@ priv_gst_structure_append_to_gstring (const GstStructure * structure,
     if (t) {
       g_string_append (s, 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 {
-      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))
+      if (!G_TYPE_CHECK_VALUE_TYPE (&field->value, G_TYPE_STRING))
         GST_WARNING ("No value transform to serialize field '%s' of type '%s'",
             g_quark_to_string (field->name),
             _priv_gst_value_gtype_to_abbr (type));
index cce6665..07fea67 100644 (file)
@@ -274,6 +274,20 @@ GST_START_TEST (test_to_from_string)
 
   gst_structure_free (st1);
   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;