Blame SOURCES/rest-0.8.0-fix-the-XML-test.patch

3aa738
From a09ea6bd74d6234be8456e7039403bc1c1d078bd Mon Sep 17 00:00:00 2001
3aa738
From: Christophe Fergeau <cfergeau@redhat.com>
3aa738
Date: Mon, 20 Jun 2016 12:05:48 +0200
3aa738
Subject: [PATCH 1/4] xml-node: Use GString in rest_xml_node_print()
3aa738
3aa738
The current code is using xml = g_strconcat (xml, ...) which is causing
3aa738
some leaks as g_strconcat returns a newly allocated string. Using
3aa738
GString avoids this issue without constantly freeing the intermediate
3aa738
strings.
3aa738
3aa738
This fixes multiple leaks like:
3aa738
3aa738
==16611== 18 bytes in 1 blocks are definitely lost in loss record 124 of 301
3aa738
==16611==    at 0x4C2BBAD: malloc (vg_replace_malloc.c:299)
3aa738
==16611==    by 0x5F5CE58: g_malloc (gmem.c:94)
3aa738
==16611==    by 0x5F75B8E: g_strconcat (gstrfuncs.c:585)
3aa738
==16611==    by 0x4E450CF: rest_xml_node_print (rest-xml-node.c:287)
3aa738
==16611==    by 0x4E451DA: rest_xml_node_print (rest-xml-node.c:305)
3aa738
==16611==    by 0x4E450F8: rest_xml_node_print (rest-xml-node.c:292)
3aa738
==16611==    by 0x4009A0: main (xml.c:40)
3aa738
---
3aa738
 rest/rest-xml-node.c | 21 ++++++++++++---------
3aa738
 1 file changed, 12 insertions(+), 9 deletions(-)
3aa738
3aa738
diff --git a/rest/rest-xml-node.c b/rest/rest-xml-node.c
3aa738
index 57a942667f06..a8156dbbd432 100644
3aa738
--- a/rest/rest-xml-node.c
3aa738
+++ b/rest/rest-xml-node.c
3aa738
@@ -283,38 +283,41 @@ rest_xml_node_print (RestXmlNode *node)
3aa738
 {
3aa738
   GHashTableIter iter;
3aa738
   gpointer       key, value;
3aa738
-  char          *xml = g_strconcat ("<", node->name, NULL);
3aa738
+  GString        *xml = g_string_new (NULL);
3aa738
   RestXmlNode   *n;
3aa738
 
3aa738
+  g_string_append (xml, "<");
3aa738
+  g_string_append (xml, node->name);
3aa738
+
3aa738
   g_hash_table_iter_init (&iter, node->attrs);
3aa738
   while (g_hash_table_iter_next (&iter, &key, &value))
3aa738
-    xml = g_strconcat (xml, " ", key, "=\'", value, "\'", NULL);
3aa738
+    g_string_append_printf (xml, " %s =\'%s\'", (char *)key, (char *)value);
3aa738
 
3aa738
-  xml = g_strconcat (xml, ">", NULL);
3aa738
+  g_string_append (xml, ">");
3aa738
 
3aa738
   g_hash_table_iter_init (&iter, node->children);
3aa738
   while (g_hash_table_iter_next (&iter, &key, &value))
3aa738
     {
3aa738
       char *child = rest_xml_node_print ((RestXmlNode *) value);
3aa738
 
3aa738
-      xml = g_strconcat (xml, child, NULL);
3aa738
+      g_string_append (xml, child);
3aa738
       g_free (child);
3aa738
     }
3aa738
 
3aa738
   if (node->content)
3aa738
-    xml = g_strconcat (xml, node->content, "</", node->name, ">", NULL);
3aa738
-  else
3aa738
-    xml = g_strconcat (xml, "</", node->name, ">", NULL);
3aa738
+    g_string_append (xml, node->content);
3aa738
+
3aa738
+  g_string_append_printf (xml, "</%s>", node->name);
3aa738
 
3aa738
   for (n = node->next; n; n = n->next)
3aa738
     {
3aa738
       char *sibling = rest_xml_node_print (n);
3aa738
 
3aa738
-      xml = g_strconcat (xml, sibling, NULL);
3aa738
+      g_string_append (xml, sibling);
3aa738
       g_free (sibling);
3aa738
     }
3aa738
 
3aa738
-  return xml;
3aa738
+  return g_string_free (xml, FALSE);
3aa738
 }
3aa738
 
3aa738
 /**
3aa738
-- 
3aa738
2.14.2
3aa738
3aa738
3aa738
From a34d02947c4f102e6d16b9d328941a4b2946c8e8 Mon Sep 17 00:00:00 2001
3aa738
From: Debarshi Ray <debarshir@gnome.org>
3aa738
Date: Fri, 13 Oct 2017 18:53:39 +0200
3aa738
Subject: [PATCH 2/4] xml-node: Remove stray blank space
3aa738
3aa738
This had broken tests/xml.c.
3aa738
3aa738
Fallout from 61a7b231bd8b9d1b8d02dca120389e79d38b428d
3aa738
3aa738
https://bugzilla.gnome.org/show_bug.cgi?id=788960
3aa738
---
3aa738
 rest/rest-xml-node.c | 2 +-
3aa738
 1 file changed, 1 insertion(+), 1 deletion(-)
3aa738
3aa738
diff --git a/rest/rest-xml-node.c b/rest/rest-xml-node.c
3aa738
index a8156dbbd432..d3a7c995affd 100644
3aa738
--- a/rest/rest-xml-node.c
3aa738
+++ b/rest/rest-xml-node.c
3aa738
@@ -291,7 +291,7 @@ rest_xml_node_print (RestXmlNode *node)
3aa738
 
3aa738
   g_hash_table_iter_init (&iter, node->attrs);
3aa738
   while (g_hash_table_iter_next (&iter, &key, &value))
3aa738
-    g_string_append_printf (xml, " %s =\'%s\'", (char *)key, (char *)value);
3aa738
+    g_string_append_printf (xml, " %s=\'%s\'", (char *)key, (char *)value);
3aa738
 
3aa738
   g_string_append (xml, ">");
3aa738
 
3aa738
-- 
3aa738
2.14.2
3aa738
3aa738
3aa738
From f184db2bff0618b99c4de3316082fe80439f124c Mon Sep 17 00:00:00 2001
3aa738
From: Debarshi Ray <debarshir@gnome.org>
3aa738
Date: Fri, 13 Oct 2017 19:14:16 +0200
3aa738
Subject: [PATCH 3/4] xml-node: Define the order in which attributes & children
3aa738
 are printed
3aa738
3aa738
The order in which GHashTable returns its key-value pairs is undefined.
3aa738
Therefore the output of rest_xml_node_print can change based on the
3aa738
GHashTable implementation. While not strictly necessary, it would be
3aa738
nice to avoid that. Having a stable order, even if it is not
3aa738
documented and depends on the current RestXmlNode code, is handy for
3aa738
testing.
3aa738
3aa738
This was the main reason behind the tests/xml.c breakage.
3aa738
3aa738
https://bugzilla.gnome.org/show_bug.cgi?id=788960
3aa738
---
3aa738
 rest/rest-xml-node.c | 23 ++++++++++++++++++++++-
3aa738
 1 file changed, 22 insertions(+), 1 deletion(-)
3aa738
3aa738
diff --git a/rest/rest-xml-node.c b/rest/rest-xml-node.c
3aa738
index d3a7c995affd..973ebcf6c3fa 100644
3aa738
--- a/rest/rest-xml-node.c
3aa738
+++ b/rest/rest-xml-node.c
3aa738
@@ -283,6 +283,9 @@ rest_xml_node_print (RestXmlNode *node)
3aa738
 {
3aa738
   GHashTableIter iter;
3aa738
   gpointer       key, value;
3aa738
+  GList          *attrs = NULL;
3aa738
+  GList          *children = NULL;
3aa738
+  GList          *l;
3aa738
   GString        *xml = g_string_new (NULL);
3aa738
   RestXmlNode   *n;
3aa738
 
3aa738
@@ -291,13 +294,29 @@ rest_xml_node_print (RestXmlNode *node)
3aa738
 
3aa738
   g_hash_table_iter_init (&iter, node->attrs);
3aa738
   while (g_hash_table_iter_next (&iter, &key, &value))
3aa738
-    g_string_append_printf (xml, " %s=\'%s\'", (char *)key, (char *)value);
3aa738
+    {
3aa738
+      char *attr = g_strdup_printf ("%s=\'%s\'", (char *)key, (char *)value);
3aa738
+      attrs = g_list_prepend (attrs, attr);
3aa738
+    }
3aa738
+
3aa738
+  attrs = g_list_sort (attrs, (GCompareFunc) g_strcmp0);
3aa738
+  for (l = attrs; l; l = l->next)
3aa738
+    {
3aa738
+      const char *attr = (const char *) l->data;
3aa738
+      g_string_append_printf (xml, " %s", attr);
3aa738
+    }
3aa738
 
3aa738
   g_string_append (xml, ">");
3aa738
 
3aa738
   g_hash_table_iter_init (&iter, node->children);
3aa738
   while (g_hash_table_iter_next (&iter, &key, &value))
3aa738
+    children = g_list_prepend (children, key);
3aa738
+
3aa738
+  children = g_list_sort (children, (GCompareFunc) g_strcmp0);
3aa738
+  for (l = children; l; l = l->next)
3aa738
     {
3aa738
+      const char *name = (const char *) l->data;
3aa738
+      RestXmlNode *value = (RestXmlNode *) g_hash_table_lookup (node->children, name);
3aa738
       char *child = rest_xml_node_print ((RestXmlNode *) value);
3aa738
 
3aa738
       g_string_append (xml, child);
3aa738
@@ -317,6 +336,8 @@ rest_xml_node_print (RestXmlNode *node)
3aa738
       g_free (sibling);
3aa738
     }
3aa738
 
3aa738
+  g_list_free_full (attrs, g_free);
3aa738
+  g_list_free (children);
3aa738
   return g_string_free (xml, FALSE);
3aa738
 }
3aa738
 
3aa738
-- 
3aa738
2.14.2
3aa738
3aa738
3aa738
From e5ee6ef751ee5a38d7b9fadcd631cf6ecec7b240 Mon Sep 17 00:00:00 2001
3aa738
From: Debarshi Ray <debarshir@gnome.org>
3aa738
Date: Fri, 13 Oct 2017 19:16:55 +0200
3aa738
Subject: [PATCH 4/4] tests: Re-enable the XML test
3aa738
3aa738
This reverts commit 2d1dbfe7073b1e153ff881426b40a9a517fb796b
3aa738
3aa738
https://bugzilla.gnome.org/show_bug.cgi?id=788960
3aa738
---
3aa738
 tests/Makefile.am | 2 --
3aa738
 1 file changed, 2 deletions(-)
3aa738
3aa738
diff --git a/tests/Makefile.am b/tests/Makefile.am
3aa738
index 5d77f9cf5445..5ffdd4634e9a 100644
3aa738
--- a/tests/Makefile.am
3aa738
+++ b/tests/Makefile.am
3aa738
@@ -1,6 +1,4 @@
3aa738
 TESTS = proxy proxy-continuous threaded oauth oauth-async oauth2 flickr lastfm xml custom-serialize
3aa738
-# TODO: fix this test case
3aa738
-XFAIL_TESTS = xml
3aa738
 
3aa738
 AM_CPPFLAGS = $(SOUP_CFLAGS) -I$(top_srcdir) $(GCOV_CFLAGS)
3aa738
 AM_LDFLAGS = $(SOUP_LIBS) $(GCOV_LDFLAGS) \
3aa738
-- 
3aa738
2.14.2
3aa738