diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-09-16 14:51:20 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-09-17 09:40:48 +0200 |
commit | b1f8fab93cc0ca5d186730a72ab0b7b9891395c2 (patch) | |
tree | 59bc79b2fbd78ec9e23c85ee64baaccf9519f7a6 | |
parent | dd0dc6caa5dab5f7632869ff74ab1db4a9031de2 (diff) |
shiboken6: Streamline the check function helpers
Move the check for a check function specified in the type system
from guessCPythonCheckFunction() to the calling functions.
Task-number: PYSIDE-1660
Change-Id: I6d4eb30cfd98abe0aef5e49b1a54b5324b81bf7c
Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r-- | sources/shiboken6/ApiExtractor/typesystem.cpp | 6 | ||||
-rw-r--r-- | sources/shiboken6/ApiExtractor/typesystem.h | 1 | ||||
-rw-r--r-- | sources/shiboken6/generator/shiboken/shibokengenerator.cpp | 19 |
3 files changed, 21 insertions, 5 deletions
diff --git a/sources/shiboken6/ApiExtractor/typesystem.cpp b/sources/shiboken6/ApiExtractor/typesystem.cpp index 80ebdb962..91d40cfbf 100644 --- a/sources/shiboken6/ApiExtractor/typesystem.cpp +++ b/sources/shiboken6/ApiExtractor/typesystem.cpp @@ -664,6 +664,12 @@ TypeEntry *CustomTypeEntry::clone() const return new CustomTypeEntry(new CustomTypeEntryPrivate(*d)); } +bool CustomTypeEntry::hasCheckFunction() const +{ + S_D(const CustomTypeEntry); + return !d->m_checkFunction.isEmpty(); +} + QString CustomTypeEntry::checkFunction() const { S_D(const CustomTypeEntry); diff --git a/sources/shiboken6/ApiExtractor/typesystem.h b/sources/shiboken6/ApiExtractor/typesystem.h index 52ad0d435..04e81361c 100644 --- a/sources/shiboken6/ApiExtractor/typesystem.h +++ b/sources/shiboken6/ApiExtractor/typesystem.h @@ -287,6 +287,7 @@ public: TypeEntry *clone() const override; + bool hasCheckFunction() const; QString checkFunction() const; void setCheckFunction(const QString &f); diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp index 3f5b6e5c8..20ae7d76e 100644 --- a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp +++ b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp @@ -995,8 +995,12 @@ bool ShibokenGenerator::isNullPtr(const QString &value) QString ShibokenGenerator::cpythonCheckFunction(AbstractMetaType metaType) const { - if (metaType.typeEntry()->isCustom()) { - auto customCheckResult = guessCPythonCheckFunction(metaType.typeEntry()->name()); + const auto *typeEntry = metaType.typeEntry(); + if (typeEntry->isCustom()) { + const auto *cte = static_cast<const CustomTypeEntry *>(typeEntry); + if (cte->hasCheckFunction()) + return cte->checkFunction(); + auto customCheckResult = guessCPythonCheckFunction(typeEntry->name()); if (!customCheckResult.checkFunction.isEmpty()) return customCheckResult.checkFunction; if (customCheckResult.type.has_value()) @@ -1008,9 +1012,9 @@ QString ShibokenGenerator::cpythonCheckFunction(AbstractMetaType metaType) const return QLatin1String("Shiboken::String::check"); if (metaType.isVoidPointer()) return QLatin1String("PyObject_Check"); - return cpythonCheckFunction(metaType.typeEntry()); + return cpythonCheckFunction(typeEntry); } - auto typeEntry = metaType.typeEntry(); + if (typeEntry->isContainer()) { QString typeCheck = QLatin1String("Shiboken::Conversions::"); ContainerTypeEntry::ContainerKind type = @@ -1061,7 +1065,9 @@ QString ShibokenGenerator::cpythonCheckFunction(AbstractMetaType metaType) const QString ShibokenGenerator::cpythonCheckFunction(const TypeEntry *type) const { if (type->isCustom()) { - AbstractMetaType metaType; + const auto *cte = static_cast<const CustomTypeEntry *>(type); + if (cte->hasCheckFunction()) + return cte->checkFunction(); auto customCheckResult = guessCPythonCheckFunction(type->name()); if (customCheckResult.type.has_value()) return cpythonCheckFunction(customCheckResult.type.value()); @@ -1144,6 +1150,9 @@ QString ShibokenGenerator::cpythonIsConvertibleFunction(const TypeEntry *type) QString ShibokenGenerator::cpythonIsConvertibleFunction(AbstractMetaType metaType) const { if (metaType.typeEntry()->isCustom()) { + const auto *cte = static_cast<const CustomTypeEntry *>(metaType.typeEntry()); + if (cte->hasCheckFunction()) + return cte->checkFunction(); auto customCheckResult = guessCPythonCheckFunction(metaType.typeEntry()->name()); if (!customCheckResult.checkFunction.isEmpty()) return customCheckResult.checkFunction; |