Blame SOURCES/0002-Empty-dict-created-by-_by_lang-in-python-api-causes-segfault.patch

41a0e7
From 257df5670310775a9c279f5f34e3d088966759b1 Mon Sep 17 00:00:00 2001
41a0e7
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
41a0e7
Date: Mon, 7 Oct 2019 12:14:22 +0200
41a0e7
Subject: [PATCH 1/3] Update couple of tests
41a0e7
41a0e7
- list indices cannot by of type float
41a0e7
- remove unnecessary print
41a0e7
- update print with parenthesis which are now required in python
41a0e7
---
41a0e7
 libcomps/src/python/tests/__test.py           | 2 +-
41a0e7
 libcomps/src/python/tests/test_libcomps.py    | 1 -
41a0e7
 libcomps/src/python/tests/test_merge_comps.py | 4 ++--
41a0e7
 3 files changed, 3 insertions(+), 4 deletions(-)
41a0e7
41a0e7
diff --git a/libcomps/src/python/tests/__test.py b/libcomps/src/python/tests/__test.py
41a0e7
index c9b4dd4..c7529f3 100644
41a0e7
--- a/libcomps/src/python/tests/__test.py
41a0e7
+++ b/libcomps/src/python/tests/__test.py
41a0e7
@@ -225,7 +225,7 @@ def test_union3(self):
41a0e7
     def test_hash(self):
41a0e7
         s = set()
41a0e7
         for x in range(6):
41a0e7
-            s.add(self.obj_constructor(**self.obj_data[x/2]))
41a0e7
+            s.add(self.obj_constructor(**self.obj_data[int(x/2)]))
41a0e7
         self.assertTrue(len(s) == 3)
41a0e7
         self.assertTrue(hash(self.obj_constructor(**self.obj_data[0])) ==\
41a0e7
                         hash(self.obj_constructor(**self.obj_data[0])))
41a0e7
diff --git a/libcomps/src/python/tests/test_libcomps.py b/libcomps/src/python/tests/test_libcomps.py
41a0e7
index 2a18984..71311ef 100755
41a0e7
--- a/libcomps/src/python/tests/test_libcomps.py
41a0e7
+++ b/libcomps/src/python/tests/test_libcomps.py
41a0e7
@@ -19,7 +19,6 @@
41a0e7
 class TestLibcomps(unittest.TestCase):
41a0e7
 
41a0e7
     def setUp(self):
41a0e7
-        print (dir(libcomps))
41a0e7
         self.comps = libcomps.Comps()
41a0e7
         self.comps.fromxml_f("comps/comps-f21.xml")
41a0e7
         self.tmp_dir = tempfile.mkdtemp()
41a0e7
diff --git a/libcomps/src/python/tests/test_merge_comps.py b/libcomps/src/python/tests/test_merge_comps.py
41a0e7
index beef2cf..73e743f 100755
41a0e7
--- a/libcomps/src/python/tests/test_merge_comps.py
41a0e7
+++ b/libcomps/src/python/tests/test_merge_comps.py
41a0e7
@@ -7,10 +7,10 @@
41a0e7
 
41a0e7
 try:
41a0e7
     import _libpycomps as libcomps
41a0e7
-    print "local tests"
41a0e7
+    print("local tests")
41a0e7
 except ImportError:
41a0e7
     import libcomps
41a0e7
-    print "global tests"
41a0e7
+    print("global tests")
41a0e7
 
41a0e7
 
41a0e7
 class TestMergeComps(unittest.TestCase):
41a0e7
41a0e7
From 1b7add27595b12b9f47e54c3e5f1bda2177da346 Mon Sep 17 00:00:00 2001
41a0e7
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
41a0e7
Date: Mon, 7 Oct 2019 12:50:21 +0200
41a0e7
Subject: [PATCH 2/3] Fix segfault when converting empty dict to string
41a0e7
 (RhBug:1757959)
41a0e7
41a0e7
Handle all elements in single loop consistently, instead of handling
41a0e7
last element separately which caused problems with empty dictionary.
41a0e7
41a0e7
https://bugzilla.redhat.com/show_bug.cgi?id=1757959
41a0e7
---
41a0e7
 libcomps/src/python/src/pycomps_dict.c | 20 +-------------------
41a0e7
 1 file changed, 1 insertion(+), 19 deletions(-)
41a0e7
41a0e7
diff --git a/libcomps/src/python/src/pycomps_dict.c b/libcomps/src/python/src/pycomps_dict.c
41a0e7
index 1b42909..4a20cf7 100644
41a0e7
--- a/libcomps/src/python/src/pycomps_dict.c
41a0e7
+++ b/libcomps/src/python/src/pycomps_dict.c
41a0e7
@@ -78,7 +78,7 @@ PyObject* PyCOMPSDict_str(PyObject *self) {
41a0e7
     pairlist = comps_objdict_pairs(((PyCOMPS_Dict*)self)->dict);
41a0e7
     char *tmpstr;
41a0e7
 
41a0e7
-    for (it = pairlist->first; it != pairlist->last; it = it->next) {
41a0e7
+    for (it = pairlist->first; it != NULL; it = it->next) {
41a0e7
         tmp = ret;
41a0e7
         tmpkey = __pycomps_lang_decode(((COMPS_ObjRTreePair*)it->data)->key);
41a0e7
         if (!tmpkey) {
41a0e7
@@ -99,24 +99,6 @@ PyObject* PyCOMPSDict_str(PyObject *self) {
41a0e7
         Py_XDECREF(tmpkey);
41a0e7
         Py_XDECREF(tmpval);
41a0e7
     }
41a0e7
-    tmp = ret;
41a0e7
-    tmpkey = __pycomps_lang_decode(((COMPS_RTreePair*)it->data)->key);
41a0e7
-    if (!tmpkey) {
41a0e7
-        goto out;
41a0e7
-    }
41a0e7
-    tmpstr = comps_object_tostr(((COMPS_ObjRTreePair*)it->data)->data);
41a0e7
-    tmpval = __pycomps_lang_decode(tmpstr);
41a0e7
-    free(tmpstr);
41a0e7
-    if (!tmpval) {
41a0e7
-        //PyErr_SetString(PyExc_TypeError, "val convert error");
41a0e7
-        goto out;
41a0e7
-    }
41a0e7
-    tmp2 = PyUnicode_FromFormat("%U = '%U'", tmpkey, tmpval);
41a0e7
-    ret = PyUnicode_Concat(ret, tmp2);
41a0e7
-    Py_XDECREF(tmp);
41a0e7
-    Py_XDECREF(tmp2);
41a0e7
-    Py_XDECREF(tmpkey);
41a0e7
-    Py_XDECREF(tmpval);
41a0e7
     
41a0e7
     tmp = ret;
41a0e7
     tmp2 = PyUnicode_FromString("}");
41a0e7
41a0e7
From 6b4bffb541e70a1715e91ba06de8172b57cd26f0 Mon Sep 17 00:00:00 2001
41a0e7
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
41a0e7
Date: Mon, 7 Oct 2019 12:52:59 +0200
41a0e7
Subject: [PATCH 3/3] Add test for python API with empty *_by_lang dictionary
41a0e7
 input
41a0e7
41a0e7
---
41a0e7
 .../python/tests/comps/comps_empty_by_lang_tags.xml  | 12 ++++++++++++
41a0e7
 libcomps/src/python/tests/test_libcomps.py           | 10 ++++++++++
41a0e7
 2 files changed, 22 insertions(+)
41a0e7
 create mode 100644 libcomps/src/python/tests/comps/comps_empty_by_lang_tags.xml
41a0e7
41a0e7
diff --git a/libcomps/src/python/tests/comps/comps_empty_by_lang_tags.xml b/libcomps/src/python/tests/comps/comps_empty_by_lang_tags.xml
41a0e7
new file mode 100644
41a0e7
index 0000000..2f40a86
41a0e7
--- /dev/null
41a0e7
+++ b/libcomps/src/python/tests/comps/comps_empty_by_lang_tags.xml
41a0e7
@@ -0,0 +1,12 @@
41a0e7
+
41a0e7
+
41a0e7
+<comps>
41a0e7
+  <group>
41a0e7
+   <id>birds</id>
41a0e7
+   <description></description>
41a0e7
+  </group>
41a0e7
+  <category>
41a0e7
+   <id>all</id>
41a0e7
+   <name>all</name>
41a0e7
+  </category>
41a0e7
+</comps>
41a0e7
diff --git a/libcomps/src/python/tests/test_libcomps.py b/libcomps/src/python/tests/test_libcomps.py
41a0e7
index 71311ef..64c2b59 100755
41a0e7
--- a/libcomps/src/python/tests/test_libcomps.py
41a0e7
+++ b/libcomps/src/python/tests/test_libcomps.py
41a0e7
@@ -153,6 +153,16 @@ def test_duplicate_groups(self):
41a0e7
         #print self.comps.xml_str()
41a0e7
         self.comps.fromxml_str(self.comps.xml_str())
41a0e7
 
41a0e7
+    def test_empty_by_lang_tags(self):
41a0e7
+        self.comps = libcomps.Comps()
41a0e7
+        self.comps.fromxml_f("comps/comps_empty_by_lang_tags.xml")
41a0e7
+        for group in self.comps.groups:
41a0e7
+            self.assertEqual("{}", str(group.name_by_lang))
41a0e7
+            self.assertEqual("{}", str(group.desc_by_lang))
41a0e7
+
41a0e7
+        for category in self.comps.categories:
41a0e7
+            self.assertEqual("{}", str(category.name_by_lang))
41a0e7
+            self.assertEqual("{}", str(category.desc_by_lang))
41a0e7
 
41a0e7
 if __name__ == "__main__":
41a0e7
     unittest.main(testRunner = utest.MyRunner)