diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-10-12 13:50:24 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-10-13 13:02:26 +0200 |
commit | 85451c40f23a7298b5f35744e8588307e124a751 (patch) | |
tree | d507d772fa63c084d64ac1886caa91e23c4864f2 /sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp | |
parent | 6e2eb6917620675b8bbcce53a31204a1ecfb2424 (diff) |
shiboken2: Use an AbstractMetaType for "void"
Previously, nullptr for an AbstractMetaType meant "void", particularly
for function return types. The problem with this is that it
causes unexpected crashes when dealing with template types
like QFuture<void> due to one of the instantiations of the
AbstractMetaType being nullptr. Use an AbstractMetaType based
on the existing "void" type entry for this.
Task-number: PYSIDE-1202
Change-Id: Ib06035cc7903480fd509f7e927d9114c55d51b62
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp')
-rw-r--r-- | sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp | 60 |
1 files changed, 28 insertions, 32 deletions
diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp index 6b72d6b71..b06376866 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp +++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp @@ -1300,7 +1300,7 @@ void AbstractMetaBuilderPrivate::traverseFunctions(ScopeModelItem scopeItem, QPropertySpec *read = nullptr; if (!metaFunction->isSignal() && (read = metaClass->propertySpecForRead(metaFunction->name()))) { // Property reader must be in the form "<type> name()" - if (metaFunction->type() && (read->typeEntry() == metaFunction->type()->typeEntry()) + if (read->typeEntry() == metaFunction->type()->typeEntry() && metaFunction->arguments().isEmpty()) { *metaFunction += AbstractMetaAttributes::PropertyReader; metaFunction->setPropertySpec(read); @@ -1309,14 +1309,14 @@ void AbstractMetaBuilderPrivate::traverseFunctions(ScopeModelItem scopeItem, // Property setter must be in the form "void name(<type>)" // Make sure the function was created with all arguments; some argument can be // missing during the parsing because of errors in the typesystem. - if ((!metaFunction->type()) && (metaFunction->arguments().size() == 1) + if (metaFunction->isVoid() && metaFunction->arguments().size() == 1 && (write->typeEntry() == metaFunction->arguments().at(0)->type()->typeEntry())) { *metaFunction += AbstractMetaAttributes::PropertyWriter; metaFunction->setPropertySpec(write); } } else if (QPropertySpec *reset = metaClass->propertySpecForReset(metaFunction->name())) { // Property resetter must be in the form "void name()" - if ((!metaFunction->type()) && metaFunction->arguments().isEmpty()) { + if (metaFunction->isVoid() && metaFunction->arguments().isEmpty()) { *metaFunction += AbstractMetaAttributes::PropertyResetter; metaFunction->setPropertySpec(reset); } @@ -1520,16 +1520,13 @@ AbstractMetaFunction* AbstractMetaBuilderPrivate::traverseFunction(const AddedFu { QString errorMessage; - AbstractMetaType *returnType = nullptr; - if (addedFunc->returnType().name != QLatin1String("void")) { - returnType = translateType(addedFunc->returnType(), &errorMessage); - if (!returnType) { - qCWarning(lcShiboken, "%s", - qPrintable(msgAddedFunctionInvalidReturnType(addedFunc->name(), - addedFunc->returnType().name, - errorMessage))); - return nullptr; - } + AbstractMetaType *returnType = translateType(addedFunc->returnType(), &errorMessage); + if (!returnType) { + qCWarning(lcShiboken, "%s", + qPrintable(msgAddedFunctionInvalidReturnType(addedFunc->name(), + addedFunc->returnType().name, + errorMessage))); + return nullptr; } auto metaFunction = new AbstractMetaFunction(addedFunc); @@ -1810,10 +1807,12 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(const Functio QString errorMessage; switch (metaFunction->functionType()) { case AbstractMetaFunction::DestructorFunction: + metaFunction->setType(AbstractMetaType::createVoid()); break; case AbstractMetaFunction::ConstructorFunction: metaFunction->setExplicit(functionItem->isExplicit()); metaFunction->setName(currentClass->name()); + metaFunction->setType(AbstractMetaType::createVoid()); break; default: { TypeInfo returnType = functionItem->type(); @@ -1824,17 +1823,14 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(const Functio return nullptr; } - AbstractMetaType *type = nullptr; - if (!returnType.isVoid()) { - type = translateType(returnType, currentClass, {}, &errorMessage); - if (!type) { - const QString reason = msgUnmatchedReturnType(functionItem, errorMessage); - qCWarning(lcShiboken, "%s", - qPrintable(msgSkippingFunction(functionItem, originalQualifiedSignatureWithReturn, reason))); - m_rejectedFunctions.insert(originalQualifiedSignatureWithReturn, AbstractMetaBuilder::UnmatchedReturnType); - delete metaFunction; - return nullptr; - } + AbstractMetaType *type = translateType(returnType, currentClass, {}, &errorMessage); + if (!type) { + const QString reason = msgUnmatchedReturnType(functionItem, errorMessage); + qCWarning(lcShiboken, "%s", + qPrintable(msgSkippingFunction(functionItem, originalQualifiedSignatureWithReturn, reason))); + m_rejectedFunctions.insert(originalQualifiedSignatureWithReturn, AbstractMetaBuilder::UnmatchedReturnType); + delete metaFunction; + return nullptr; } metaFunction->setType(type); @@ -1972,7 +1968,7 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateType(const AddedFunction: QString typeName = typeInfo.name; if (typeName == QLatin1String("void")) - return nullptr; + return AbstractMetaType::createVoid(); type = typeDb->findType(typeName); if (!type) @@ -2022,12 +2018,9 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateType(const AddedFunction: metaType->setConstant(typeInfo.isConstant); if (isTemplate) { for (const QString& templateArg : qAsConst(templateArgs)) { - AbstractMetaType *metaArgType = nullptr; - if (templateArg != QLatin1String("void")) { - metaArgType = translateType(AddedFunction::TypeInfo::fromSignature(templateArg), errorMessage); - if (!metaArgType) - return nullptr; - } + AbstractMetaType *metaArgType = translateType(AddedFunction::TypeInfo::fromSignature(templateArg), errorMessage); + if (!metaArgType) + return nullptr; metaType->addInstantiation(metaArgType); } metaType->setTypeUsagePattern(AbstractMetaType::ContainerPattern); @@ -2113,6 +2106,9 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateTypeStatic(const TypeInfo TranslateTypeFlags flags, QString *errorMessageIn) { + if (_typei.isVoid()) + return AbstractMetaType::createVoid(); + // 1. Test the type info without resolving typedefs in case this is present in the // type system const bool resolveType = !flags.testFlag(AbstractMetaBuilder::DontResolveType); @@ -2685,7 +2681,7 @@ bool AbstractMetaBuilderPrivate::inheritTemplate(AbstractMetaClass *subclass, QScopedPointer<AbstractMetaFunction> f(function->copy()); f->setArguments(AbstractMetaArgumentList()); - if (function->type()) { // Non-void + if (!function->isVoid()) { AbstractMetaType *returnType = inheritTemplateType(templateTypes, function->type()); if (!returnType) continue; |