From ea02836aa048cfdd853122273f25a5a2c2d7d493 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 13 Nov 2019 11:00:23 +0100 Subject: 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 --- sources/shiboken2/ApiExtractor/messages.cpp | 12 ++++++++++++ sources/shiboken2/ApiExtractor/messages.h | 3 +++ sources/shiboken2/generator/generator.cpp | 9 ++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) 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 &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 &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; -- cgit v1.2.3