diff options
author | Friedemann Kleint <[email protected]> | 2025-05-27 14:03:43 +0200 |
---|---|---|
committer | Friedemann Kleint <[email protected]> | 2025-06-06 15:54:25 +0200 |
commit | 8d335e046e9ac16737cdf28bde197d6684002205 (patch) | |
tree | 8b58229883a5d27fad99dcf90e49d212d40fab6e | |
parent | 6f996ff3439e69b3938e617135b266974802d5b1 (diff) |
shiboken6: Split TargetToNativeConversion::sourceTypeCheck()
Make sourceTypeCheck() act like a normal property getter and add
sourceTypeCheckFallback() for cases in which the fallback logic is
desired.
Move additional special cases from CppGenerator into
sourceTypeCheckFallback().
Task-number: PYSIDE-3107
Change-Id: Iaebcac46a30302318bbaede373cd9dd4f50ac357
Reviewed-by: Cristian Maureira-Fredes <[email protected]>
-rw-r--r-- | sources/shiboken6/ApiExtractor/customconversion.cpp | 9 | ||||
-rw-r--r-- | sources/shiboken6/ApiExtractor/customconversion.h | 3 | ||||
-rw-r--r-- | sources/shiboken6/generator/shiboken/cppgenerator.cpp | 9 |
3 files changed, 13 insertions, 8 deletions
diff --git a/sources/shiboken6/ApiExtractor/customconversion.cpp b/sources/shiboken6/ApiExtractor/customconversion.cpp index 7b65bcf3a..b022cd692 100644 --- a/sources/shiboken6/ApiExtractor/customconversion.cpp +++ b/sources/shiboken6/ApiExtractor/customconversion.cpp @@ -96,6 +96,11 @@ QString TargetToNativeConversion::sourceTypeName() const QString TargetToNativeConversion::sourceTypeCheck() const { + return m_sourceTypeCheck; +} + +QString TargetToNativeConversion::sourceTypeCheckFallback() const +{ if (!m_sourceTypeCheck.isEmpty()) return m_sourceTypeCheck; @@ -109,6 +114,10 @@ QString TargetToNativeConversion::sourceTypeCheck() const } } + if (m_sourceTypeName == "Py_None"_L1 || m_sourceTypeName == "PyNone"_L1) + return "%in == Py_None"_L1; + if (m_sourceTypeName == "SbkObject"_L1) + return "Shiboken::Object::checkType(%in)"_L1; return {}; } diff --git a/sources/shiboken6/ApiExtractor/customconversion.h b/sources/shiboken6/ApiExtractor/customconversion.h index a75178846..9125d6705 100644 --- a/sources/shiboken6/ApiExtractor/customconversion.h +++ b/sources/shiboken6/ApiExtractor/customconversion.h @@ -25,7 +25,10 @@ public: void setSourceType(const TypeEntryCPtr &sourceType); bool isCustomType() const; QString sourceTypeName() const; + // Check as specified in the type system QString sourceTypeCheck() const; + // Check with fallback bases on sourceType + QString sourceTypeCheckFallback() const; QString conversion() const; void setConversion(const QString &conversion); diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index 9092768a3..f392eef38 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -3595,14 +3595,7 @@ void CppGenerator::writePythonToCppConversionFunctions(TextStream &s, writePythonToCppFunction(s, code, sourceTypeName, targetTypeName); // Python to C++ convertible check function. - QString typeCheck = toNative.sourceTypeCheck(); - if (typeCheck.isEmpty()) { - QString pyTypeName = toNative.sourceTypeName(); - if (pyTypeName == u"Py_None" || pyTypeName == u"PyNone") - typeCheck = u"%in == Py_None"_s; - else if (pyTypeName == u"SbkObject") - typeCheck = u"Shiboken::Object::checkType(%in)"_s; - } + QString typeCheck = toNative.sourceTypeCheckFallback(); if (typeCheck.isEmpty()) { if (!toNative.sourceType() || toNative.sourceType()->isPrimitive()) { QString m; |