diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-01-13 12:56:22 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-02-04 16:41:07 +0100 |
commit | 242f0fa7269e9baf331679dc413c28471b1f7d05 (patch) | |
tree | 009b5f9483f0e0e41e2258e3654f02bdc7551c0c /sources | |
parent | 174dcd4f6c0159f29189f01bc38f42d804886c57 (diff) |
shiboken: Fix shared pointer return value in virtual function
Smart pointer values did not have a minimal constructor defined,
add that. Also add a special case to the return type warning, since
that does not have the instantiated type.
Fixes: PYSIDE-1188
Change-Id: Ibadd7273f839eb19e1eeb5c912f124e3798207df
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources')
-rw-r--r-- | sources/shiboken2/generator/generator.cpp | 6 | ||||
-rw-r--r-- | sources/shiboken2/generator/shiboken2/cppgenerator.cpp | 10 | ||||
-rw-r--r-- | sources/shiboken2/tests/libsmart/smart_obj.h | 2 |
3 files changed, 14 insertions, 4 deletions
diff --git a/sources/shiboken2/generator/generator.cpp b/sources/shiboken2/generator/generator.cpp index 585102b01..3cc625488 100644 --- a/sources/shiboken2/generator/generator.cpp +++ b/sources/shiboken2/generator/generator.cpp @@ -692,6 +692,9 @@ DefaultValue Generator::minimalConstructor(const AbstractMetaType *type) const if (Generator::isPointer(type)) return DefaultValue(DefaultValue::Pointer, QLatin1String("::") + type->typeEntry()->qualifiedCppName()); + if (type->typeEntry()->isSmartPointer()) + return minimalConstructor(type->typeEntry()); + if (type->typeEntry()->isComplex()) { auto cType = static_cast<const ComplexTypeEntry *>(type->typeEntry()); if (cType->hasDefaultConstructor()) @@ -746,6 +749,9 @@ DefaultValue Generator::minimalConstructor(const TypeEntry *type) const : DefaultValue(DefaultValue::Custom, ctor); } + if (type->isSmartPointer()) + return DefaultValue(DefaultValue::DefaultConstructor, type->qualifiedCppName()); + if (type->isComplex()) return minimalConstructor(AbstractMetaClass::findClass(classes(), type)); diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp index e0fe88775..8b7ecfd4a 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp @@ -746,11 +746,14 @@ QString CppGenerator::getVirtualFunctionReturnTypeName(const AbstractMetaFunctio return QLatin1Char('"') + func->typeReplaced(0) + QLatin1Char('"'); // SbkType would return null when the type is a container. - if (func->type()->typeEntry()->isContainer()) { + auto typeEntry = func->type()->typeEntry(); + if (typeEntry->isContainer()) { return QLatin1Char('"') - + reinterpret_cast<const ContainerTypeEntry *>(func->type()->typeEntry())->typeName() + + reinterpret_cast<const ContainerTypeEntry *>(typeEntry)->typeName() + QLatin1Char('"'); } + if (typeEntry->isSmartPointer()) + return QLatin1Char('"') + typeEntry->qualifiedCppName() + QLatin1Char('"'); if (avoidProtectedHack()) { const AbstractMetaEnum *metaEnum = findAbstractMetaEnum(func->type()); @@ -761,7 +764,8 @@ QString CppGenerator::getVirtualFunctionReturnTypeName(const AbstractMetaFunctio if (func->type()->isPrimitive()) return QLatin1Char('"') + func->type()->name() + QLatin1Char('"'); - return QString::fromLatin1("reinterpret_cast<PyTypeObject *>(Shiboken::SbkType< %1 >())->tp_name").arg(func->type()->typeEntry()->qualifiedCppName()); + return QLatin1String("reinterpret_cast<PyTypeObject *>(Shiboken::SbkType< ") + + typeEntry->qualifiedCppName() + QLatin1String(" >())->tp_name"); } void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaFunction *func) diff --git a/sources/shiboken2/tests/libsmart/smart_obj.h b/sources/shiboken2/tests/libsmart/smart_obj.h index e5709a071..8fe45993f 100644 --- a/sources/shiboken2/tests/libsmart/smart_obj.h +++ b/sources/shiboken2/tests/libsmart/smart_obj.h @@ -48,7 +48,7 @@ public: Integer takeInteger(Integer val); SharedPtr<Obj> giveSharedPtrToObj(); std::vector<SharedPtr<Obj> > giveSharedPtrToObjList(int size); - SharedPtr<Integer> giveSharedPtrToInteger(); + virtual SharedPtr<Integer> giveSharedPtrToInteger(); // virtual for PYSIDE-1188 SharedPtr<const Integer> giveSharedPtrToConstInteger(); int takeSharedPtrToConstInteger(SharedPtr<const Integer> pInt); SharedPtr<Smart::Integer2> giveSharedPtrToInteger2(); |