aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/tests/minimalbinding
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-02-25 16:03:31 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2022-03-10 12:37:30 +0100
commite48b696ffab552785d38d72dff6c9dda796c9628 (patch)
tree804a5d8a4fc77a99bb609404d56191f556e68b6a /sources/shiboken6/tests/minimalbinding
parent5ace7efe56aac73b42cc040e4036f2ba72ecb2c9 (diff)
shiboken6: Handle pointers to containers
Opaque containers were disabled for functions taking a pointer to a container since the number of indirections generated was incorrect. Functions taking a pointer to a container where no opaque container exists caused a crash since shiboken generated a value conversion to an uninitialized pointer. Change e4c2272dc60e1ff5e2d0933238fe4508af5f7f60 fixed the number of indirections used for arguments. With this, enable opaque containers also for functions taking a pointer. Use the same code path also for the case of a function taking a container by pointer since it provides a local variable to store the value. As a drive by, this also allows for a virtual function reimplemented in Python to return an opaque container. Change writePythonToCppTypeConversion() to return the number of indirections in case of return types. Remove flag CppGenerator::PythonToCppTypeConversionFlag. [ChangeLog][shiboken6] Code generation for functions taking a pointer to a container has been fixed. Pick-to: 6.2 Task-number: PYSIDE-1605 Task-number: PYSIDE-1790 Change-Id: Ifa0bafb1316d7edfe1efc2183459b1ee6924f5a1 Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken6/tests/minimalbinding')
-rw-r--r--sources/shiboken6/tests/minimalbinding/listuser_test.py37
1 files changed, 35 insertions, 2 deletions
diff --git a/sources/shiboken6/tests/minimalbinding/listuser_test.py b/sources/shiboken6/tests/minimalbinding/listuser_test.py
index a1fc48c08..a31a5aab2 100644
--- a/sources/shiboken6/tests/minimalbinding/listuser_test.py
+++ b/sources/shiboken6/tests/minimalbinding/listuser_test.py
@@ -44,7 +44,10 @@ from minimal import ListUser, Val, Obj, StdIntList
class ExtListUser(ListUser):
def __init__(self):
- ListUser.__init__(self)
+ super().__init__()
+ self._stdIntList = StdIntList()
+ self._stdIntList.append(1)
+ self._stdIntList.append(2)
def createIntList(self, num):
return list(range(0, num * 2, 2))
@@ -78,6 +81,9 @@ class ExtListUser(ListUser):
def sumListOfIntLists(self, intListList):
return sum([sum(line) for line in intListList]) * 2
+ def returnIntListByPtr(self):
+ return self._stdIntList
+
class IntListConversionTest(unittest.TestCase):
@@ -356,7 +362,34 @@ class ListOfIntListConversionTest(unittest.TestCase):
self.assertEqual(len(const_l), 4)
self.assertRaises(TypeError, const_l.append, 6)
+ def testListByPtrOpaque(self):
+ """Test a function taking C++ list by pointer for which an opaque
+ container exists."""
+ lu = ListUser()
+ python_list = [1, 2]
+ self.assertEqual(lu.modifyIntListPtr(python_list), 2)
+
+ # Pass an opaque container and verify whether it is modified by C++
+ cpp_list = StdIntList()
+ cpp_list.append(1)
+ cpp_list.append(2)
+ self.assertEqual(lu.modifyIntListPtr(cpp_list), 2)
+ self.assertEqual(len(cpp_list), 3)
+
+ def testListByPtr(self):
+ """Test a function taking C++ list by pointer for which no opaque
+ container exists."""
+ lu = ListUser()
+ python_list = [1.1, 22.2]
+ self.assertEqual(lu.modifyDoubleListPtr(python_list), 2)
+
+ def testReturnListByPtr(self):
+ """Test that a virtual function returning a list by pointer can be
+ reimplemented by a Python function returning an opaque container."""
+ lu = ExtListUser()
+ size = lu.callReturnIntListByPtr() # Call virtual from C++
+ self.assertEqual(size, 2)
+
if __name__ == '__main__':
unittest.main()
-