From 2dd12f480d35194eaa2c97638cf972a09803c68a Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Mon, 18 Feb 2019 14:43:41 -0300 Subject: Fix conversions of list of smart pointers to python While converting smart pointers do not initialize the object with default/minimal constructor. Change-Id: Ie9400d8487accc0c90b0f0b31b855038ae698b5c Task-Id: PYSIDE-947 Reviewed-by: Friedemann Kleint --- .../generator/shiboken2/shibokengenerator.cpp | 2 +- sources/shiboken2/tests/libsmart/smart.cpp | 9 +++++++ sources/shiboken2/tests/libsmart/smart.h | 1 + .../tests/smartbinding/smart_pointer_test.py | 19 ++++++++++++++ .../tests/smartbinding/typesystem_smart.xml | 30 ++++++++++++++++++++++ 5 files changed, 60 insertions(+), 1 deletion(-) diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp index ca5dab54e..ec0d466f7 100644 --- a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp @@ -2683,7 +2683,7 @@ void ShibokenGenerator::writeMinimalConstructorExpression(QTextStream& s, const s << " = " << defaultCtor; return; } - if (isCppPrimitive(type)) + if (isCppPrimitive(type) || type->isSmartPointer()) return; const auto ctor = minimalConstructor(type); if (ctor.isValid()) { diff --git a/sources/shiboken2/tests/libsmart/smart.cpp b/sources/shiboken2/tests/libsmart/smart.cpp index 4132c2fc8..8d85d67a1 100644 --- a/sources/shiboken2/tests/libsmart/smart.cpp +++ b/sources/shiboken2/tests/libsmart/smart.cpp @@ -62,6 +62,15 @@ SharedPtr Obj::giveSharedPtrToObj() return o; } +std::vector > Obj::giveSharedPtrToObjList(int size) +{ + std::vector > r; + for (int i=0; i < size; i++) + r.push_back(giveSharedPtrToObj()); + return r; +} + + SharedPtr Obj::giveSharedPtrToInteger() { SharedPtr o(new Integer); diff --git a/sources/shiboken2/tests/libsmart/smart.h b/sources/shiboken2/tests/libsmart/smart.h index 502187a11..2e3c96406 100644 --- a/sources/shiboken2/tests/libsmart/smart.h +++ b/sources/shiboken2/tests/libsmart/smart.h @@ -207,6 +207,7 @@ public: void printObj(); Integer takeInteger(Integer val); SharedPtr giveSharedPtrToObj(); + std::vector > giveSharedPtrToObjList(int size); SharedPtr giveSharedPtrToInteger(); SharedPtr giveSharedPtrToInteger2(); int takeSharedPtrToObj(SharedPtr pObj); diff --git a/sources/shiboken2/tests/smartbinding/smart_pointer_test.py b/sources/shiboken2/tests/smartbinding/smart_pointer_test.py index 62bfc0500..e07856e61 100644 --- a/sources/shiboken2/tests/smartbinding/smart_pointer_test.py +++ b/sources/shiboken2/tests/smartbinding/smart_pointer_test.py @@ -156,5 +156,24 @@ class SmartPointerTests(unittest.TestCase): integer = ptrToInteger.data() self.assertTrue(integer) + def testListOfSmartPointers(self): + # Create the main object + o = Obj() + + # Create a list of shared objects + ptrToObjList = o.giveSharedPtrToObjList(10) + self.assertEqual(len(ptrToObjList), 10) + self.assertEqual(objCount(), 11) + + # Remove one from the list + ptrToObjList.pop() + self.assertEqual(len(ptrToObjList), 9) + self.assertEqual(objCount(), 10) + + # clear and delete all objects in the list + ptrToObjList.clear() + self.assertEqual(len(ptrToObjList), 0) + self.assertEqual(objCount(), 1) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken2/tests/smartbinding/typesystem_smart.xml b/sources/shiboken2/tests/smartbinding/typesystem_smart.xml index b2deb18cb..aea1c2f73 100644 --- a/sources/shiboken2/tests/smartbinding/typesystem_smart.xml +++ b/sources/shiboken2/tests/smartbinding/typesystem_smart.xml @@ -5,6 +5,36 @@ + + + + + + + + + + + + + + + + + -- cgit v1.2.3