diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-11-13 11:00:23 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-11-18 15:45:34 +0100 |
commit | ea02836aa048cfdd853122273f25a5a2c2d7d493 (patch) | |
tree | b09c37432409e8fb38bdee669c7747d2c0b89798 | |
parent | 688176a3c35f49c7c087ca2f0e8c841e72133176 (diff) |
shiboken: Fix crash when smartptr template class cannot be found
shiboken currently crashes when naively trying to use std::shared_ptr
since it does not see the template due to system directories being
excluded from clang parsing. Add an error message and bail out.
Task-number: PYSIDE-454
Change-Id: I6627e968061f8f704a90f898879f3861308e1705
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
-rw-r--r-- | sources/shiboken2/ApiExtractor/messages.cpp | 12 | ||||
-rw-r--r-- | sources/shiboken2/ApiExtractor/messages.h | 3 | ||||
-rw-r--r-- | sources/shiboken2/generator/generator.cpp | 9 |
3 files changed, 23 insertions, 1 deletions
diff --git a/sources/shiboken2/ApiExtractor/messages.cpp b/sources/shiboken2/ApiExtractor/messages.cpp index 5b3a57fcc..b571c08b9 100644 --- a/sources/shiboken2/ApiExtractor/messages.cpp +++ b/sources/shiboken2/ApiExtractor/messages.cpp @@ -328,6 +328,18 @@ QString msgConversionTypesDiffer(const QString &varType, const QString &conversi return result; } +QString msgCannotFindSmartPointer(const QString &instantiationType, + const AbstractMetaClassList &pointers) +{ + QString result; + QTextStream str(&result); + str << "Unable to find smart pointer type for " << instantiationType << " (known types:"; + for (auto t : pointers) + str << ' ' << t->fullName(); + str << ")."; + return result; +} + // main.cpp QString msgLeftOverArguments(const QMap<QString, QString> &remainingArgs) diff --git a/sources/shiboken2/ApiExtractor/messages.h b/sources/shiboken2/ApiExtractor/messages.h index 2fee0de8f..4d66a89b8 100644 --- a/sources/shiboken2/ApiExtractor/messages.h +++ b/sources/shiboken2/ApiExtractor/messages.h @@ -117,6 +117,9 @@ QString msgCannotUseEnumAsInt(const QString &name); QString msgConversionTypesDiffer(const QString &varType, const QString &conversionType); +QString msgCannotFindSmartPointer(const QString &instantiationType, + const AbstractMetaClassList &pointers); + QString msgLeftOverArguments(const QMap<QString, QString> &remainingArgs); QString msgInvalidVersion(const QString &package, const QString &version); diff --git a/sources/shiboken2/generator/generator.cpp b/sources/shiboken2/generator/generator.cpp index 7c6e921c7..484b1f641 100644 --- a/sources/shiboken2/generator/generator.cpp +++ b/sources/shiboken2/generator/generator.cpp @@ -430,9 +430,16 @@ bool Generator::generate() return false; } + const auto smartPointers = m_d->apiextractor->smartPointers(); for (const AbstractMetaType *type : qAsConst(m_d->instantiatedSmartPointers)) { AbstractMetaClass *smartPointerClass = - AbstractMetaClass::findClass(m_d->apiextractor->smartPointers(), type->typeEntry()); + AbstractMetaClass::findClass(smartPointers, type->typeEntry()); + if (!smartPointerClass) { + qCWarning(lcShiboken, "%s", + qPrintable(msgCannotFindSmartPointer(type->cppSignature(), + smartPointers))); + return false; + } GeneratorContext context(smartPointerClass, type, true); if (!generateFileForContext(context)) return false; |