diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-03-17 16:33:59 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-03-18 09:23:26 +0100 |
commit | e1710b0c0fddf5d7dc452d277243bdedc2a99e19 (patch) | |
tree | 7c90dd91b5ba15c732a1b81513720bff8078d8a4 | |
parent | f81168387be7879f9167405b28d29ba26e7b3f14 (diff) |
shiboken6: Allow for several smart pointer types
When adding conversions for smart pointers to base classes,
verify that it is actually the correct smart pointer type.
Amends 24cd62c9d18850707574ba7eb637ff24bee353a1.
Pick-to: 6.2
Task-number: PYSIDE-1397
Task-number: PYSIDE-454
Change-Id: I5a2ca903fd97be23eeb82c5f78b4946dea1a7ec6
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
-rw-r--r-- | sources/shiboken6/generator/shiboken/cppgenerator.cpp | 33 | ||||
-rw-r--r-- | sources/shiboken6/generator/shiboken/cppgenerator.h | 4 |
2 files changed, 22 insertions, 15 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index f240d0e89..e768ef397 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -330,10 +330,11 @@ AbstractMetaFunctionCPtr CppGenerator::boolCast(const AbstractMetaClass *metaCla } std::optional<AbstractMetaType> - CppGenerator::findSmartPointerInstantiation(const TypeEntry *entry) const + CppGenerator::findSmartPointerInstantiation(const SmartPointerTypeEntry *pointer, + const TypeEntry *pointee) const { for (const auto &i : instantiatedSmartPointers()) { - if (i.instantiations().at(0).typeEntry() == entry) + if (i.typeEntry() == pointer && i.instantiations().at(0).typeEntry() == pointee) return i; } return {}; @@ -1824,12 +1825,15 @@ void CppGenerator::writeSmartPointerConverterFunctions(TextStream &s, s << "// Register smartpointer conversion for all derived classes\n"; const auto classes = targetClass->typeSystemBaseClasses(); - for (auto k : classes) { - if (smartPointerTypeEntry->matchesInstantiation(k->typeEntry())) { - if (auto smartTargetType = findSmartPointerInstantiation(k->typeEntry())) { + for (auto base : classes) { + auto *baseTe = base->typeEntry(); + if (smartPointerTypeEntry->matchesInstantiation(baseTe)) { + if (auto opt = findSmartPointerInstantiation(smartPointerTypeEntry, baseTe)) { + const auto smartTargetType = opt.value(); s << "// SmartPointer derived class: " - << smartTargetType->cppSignature() << "\n"; - writePythonToCppConversionFunctions(s, smartPointerType, smartTargetType.value(), {}, {}, {}); + << smartTargetType.cppSignature() << "\n"; + writePythonToCppConversionFunctions(s, smartPointerType, + smartTargetType, {}, {}, {}); } } } @@ -4213,17 +4217,20 @@ void CppGenerator::writeSmartPointerConverterInitialization(TextStream &s, const if (classes.isEmpty()) return; + auto *smartPointerTypeEntry = static_cast<const SmartPointerTypeEntry *>(type.typeEntry()); + s << "// Register SmartPointer converter for type '" << cppSignature << "'." << '\n' << "///////////////////////////////////////////////////////////////////////////////////////\n\n"; - for (auto k : classes) { - auto smartTargetType = findSmartPointerInstantiation(k->typeEntry()); - if (smartTargetType.has_value()) { + for (auto *base : classes) { + auto *baseTe = base->typeEntry(); + if (auto opt = findSmartPointerInstantiation(smartPointerTypeEntry, baseTe)) { + const auto smartTargetType = opt.value(); s << "// Convert to SmartPointer derived class: [" - << smartTargetType->cppSignature() << "]\n"; + << smartTargetType.cppSignature() << "]\n"; const QString converter = u"Shiboken::Conversions::getConverter(\""_qs - + smartTargetType->cppSignature() + u"\")"_qs; - writeConversionRegister(type, fixedCppTypeName(smartTargetType.value()), converter); + + smartTargetType.cppSignature() + u"\")"_qs; + writeConversionRegister(type, fixedCppTypeName(smartTargetType), converter); } else { s << "// Class not found:" << type.instantiations().at(0).cppSignature(); } diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.h b/sources/shiboken6/generator/shiboken/cppgenerator.h index da6828aa9..cf6f7875c 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.h +++ b/sources/shiboken6/generator/shiboken/cppgenerator.h @@ -489,8 +489,8 @@ private: { return !boolCast(metaClass).isNull(); } std::optional<AbstractMetaType> - findSmartPointerInstantiation(const TypeEntry *entry) const; - + findSmartPointerInstantiation(const SmartPointerTypeEntry *pointer, + const TypeEntry *pointee) const; void clearTpFuncs(); QHash<QString, QString> m_tpFuncs; |