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

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