aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/generator/shiboken/cppgenerator.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-11-23 13:44:23 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2021-11-24 15:15:57 +0100
commit6c8c0142a99aa0c170998b3449ea20e5a526d80d (patch)
treec7615f0d4dfc11e39c6734f3cf1e03f2799eff7e /sources/shiboken6/generator/shiboken/cppgenerator.cpp
parenteef987d0faaf1122f191a6ad92343d98f197715d (diff)
shiboken6: Handle None as a shared pointer parameter
Add checks for None to the copy converters. Pick-to: 6.2 Task-number: PYSIDE-454 Change-Id: I03954189e26572d248e22118954115bf8281b0f9 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken6/generator/shiboken/cppgenerator.cpp')
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.cpp29
1 files changed, 21 insertions, 8 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
index 7a22c83f2..386254ce8 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
@@ -1569,18 +1569,31 @@ return result;)";
c.clear();
QString pyInVariable = QLatin1String("pyIn");
- QString wrappedCPtrExpression;
- if (!classContext.forSmartPointer())
- wrappedCPtrExpression = cpythonWrapperCPtr(metaClass->typeEntry(), pyInVariable);
- else
- wrappedCPtrExpression = cpythonWrapperCPtr(classContext.preciseType(), pyInVariable);
+ const QString outPtr = u"reinterpret_cast<"_qs + typeName + u" *>(cppOut)"_qs;
+ if (!classContext.forSmartPointer()) {
+ c << '*' << outPtr << " = *"
+ << cpythonWrapperCPtr(metaClass->typeEntry(), pyInVariable) << ';';
+ } else {
+ auto *ste = static_cast<const SmartPointerTypeEntry *>(metaClass->typeEntry());
+ const QString resetMethod = ste->resetMethod();
+ c << "auto *ptr = " << outPtr << ";\n";
+ c << "if (" << pyInVariable << " == Py_None)\n" << indent;
+ if (resetMethod.isEmpty())
+ c << "*ptr = {};\n";
+ else
+ c << "ptr->" << resetMethod << "();\n";
+ c << outdent << "else\n" << indent
+ << "*ptr = *"
+ << cpythonWrapperCPtr(classContext.preciseType(), pyInVariable) << ';';
+ }
- c << "*reinterpret_cast<" << typeName << " *>(cppOut) = *"
- << wrappedCPtrExpression << ';';
writePythonToCppFunction(s, c.toString(), sourceTypeName, targetTypeName);
// "Is convertible" function for the Python object to C++ value copy conversion.
- writeIsPythonConvertibleToCppFunction(s, sourceTypeName, targetTypeName, pyTypeCheck);
+ QString copyTypeCheck = pyTypeCheck;
+ if (classContext.forSmartPointer())
+ copyTypeCheck.prepend(pyInVariable + u" == Py_None || "_qs);
+ writeIsPythonConvertibleToCppFunction(s, sourceTypeName, targetTypeName, copyTypeCheck);
s << '\n';
// User provided implicit conversions.