diff options
Diffstat (limited to 'sources')
5 files changed, 60 insertions, 1 deletions
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> Obj::giveSharedPtrToObj() return o; } +std::vector<SharedPtr<Obj> > Obj::giveSharedPtrToObjList(int size) +{ + std::vector<SharedPtr<Obj> > r; + for (int i=0; i < size; i++) + r.push_back(giveSharedPtrToObj()); + return r; +} + + SharedPtr<Integer> Obj::giveSharedPtrToInteger() { SharedPtr<Integer> 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<Obj> giveSharedPtrToObj(); + std::vector<SharedPtr<Obj> > giveSharedPtrToObjList(int size); SharedPtr<Integer> giveSharedPtrToInteger(); SharedPtr<Smart::Integer2> giveSharedPtrToInteger2(); int takeSharedPtrToObj(SharedPtr<Obj> 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 @@ <primitive-type name="float" /> <primitive-type name="bool" /> + <template name="cpplist_to_pylist_convertion"> + PyObject *%out = PyList_New(int(%in.size())); + int idx = 0; + for (const auto &cppItem : %in) + PyList_SET_ITEM(%out, idx++, %CONVERTTOPYTHON[%INTYPE_0](cppItem)); + return %out; + </template> + <template name="pyseq_to_cpplist_convertion"> + Shiboken::AutoDecRef seq(PySequence_Fast(%in, 0)); + for (int i = 0, size = PySequence_Fast_GET_SIZE(seq.object()); i < size; ++i) { + PyObject* pyItem = PySequence_Fast_GET_ITEM(seq.object(), i); + %OUTTYPE_0 cppItem = %CONVERTTOCPP[%OUTTYPE_0](pyItem); + %out.push_back(cppItem); + } + </template> + <container-type name="std::vector" type="list"> + <include file-name="list" location="global"/> + <conversion-rule> + <native-to-target> + <insert-template name="cpplist_to_pylist_convertion"/> + </native-to-target> + <target-to-native> + <add-conversion type="PySequence"> + <insert-template name="pyseq_to_cpplist_convertion"/> + </add-conversion> + </target-to-native> + </conversion-rule> + </container-type> + + <!-- Used in tests to check what C++ objects are allocated. --> <object-type name="Registry" /> |