aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/generator
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-07-13 14:53:36 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-07-14 12:07:59 +0200
commit871a7e2ea74e093d862f954b7ddca374c02cd5b8 (patch)
tree086a42937d751de3ceb1e3eee9ba8a11edd9cbbb /sources/shiboken2/generator
parent805cc07cb18c972eceaea7dc3d48f840f4795243 (diff)
shiboken2: Handle default parameters of const pointers
Occurs in Qt 6: QKeyEvent(..., const QInputDevice *device = QInputDevice::primaryKeyboard()); We need a const-cast here since shiboken needs a QInputDevice * for type conversion. Change-Id: Iea1137eac44a26b7bc9cf0e1908c0e42ba2de39f Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken2/generator')
-rw-r--r--sources/shiboken2/generator/shiboken2/cppgenerator.cpp13
-rw-r--r--sources/shiboken2/generator/shiboken2/shibokengenerator.cpp6
-rw-r--r--sources/shiboken2/generator/shiboken2/shibokengenerator.h2
3 files changed, 19 insertions, 2 deletions
diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
index b071ae181..65e12c7bc 100644
--- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
+++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
@@ -2424,8 +2424,17 @@ void CppGenerator::writePythonToCppTypeConversion(QTextStream &s,
s << ' ' << cppOut;
} else if (treatAsPointer || isPointerOrObjectType) {
s << " *" << cppOut;
- if (!defaultValue.isEmpty())
- s << " = " << defaultValue;
+ if (!defaultValue.isEmpty()) {
+ const bool needsConstCast = !isNullPtr(defaultValue)
+ && type->indirections() == 1 && type->isConstant()
+ && type->referenceType() == NoReference;
+ s << " = ";
+ if (needsConstCast)
+ s << "const_cast<" << typeName << " *>(";
+ s << defaultValue;
+ if (needsConstCast)
+ s << ')';
+ }
} else if (type->referenceType() == LValueReference && !typeEntry->isPrimitive() && isNotContainerEnumOrFlags) {
s << " *" << cppOut << " = &" << cppOutAux;
} else {
diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp
index 6abaef698..43ebefe14 100644
--- a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp
+++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp
@@ -1145,6 +1145,12 @@ bool ShibokenGenerator::visibilityModifiedToPrivate(const AbstractMetaFunction *
return false;
}
+bool ShibokenGenerator::isNullPtr(const QString &value)
+{
+ return value == QLatin1String("0") || value == QLatin1String("nullptr")
+ || value == QLatin1String("NULLPTR") || value == QLatin1String("{}");
+}
+
QString ShibokenGenerator::cpythonCheckFunction(const AbstractMetaType *metaType, bool genericNumberType)
{
QString customCheck;
diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.h b/sources/shiboken2/generator/shiboken2/shibokengenerator.h
index d8259d245..da0c16851 100644
--- a/sources/shiboken2/generator/shiboken2/shibokengenerator.h
+++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.h
@@ -301,6 +301,8 @@ protected:
static bool visibilityModifiedToPrivate(const AbstractMetaFunction *func);
+ static bool isNullPtr(const QString &value);
+
QString converterObject(const AbstractMetaType *type);
QString converterObject(const TypeEntry *type);