aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2019-01-03 16:00:46 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2019-01-04 09:39:39 +0000
commitb628c1643cadb2a4a6fb88d336ebd4aace3bb06a (patch)
tree574839ada486ac5f8298750c983a46afe6361eec /sources/shiboken2
parente254c3c2aa140016e298107a0297885234abfde7 (diff)
Fix crash when mixing static overloads with instance methods in derived classes
Use METH_STATIC only when there are no instance methods in the same class. Unearthed by a clash of QPlainTextEdit::find() and static QWidget::find(WId). Change-Id: I891c678e004a0abc3937437b0cac26e8094853de Fixes: PYSIDE-886 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken2')
-rw-r--r--sources/shiboken2/generator/shiboken2/cppgenerator.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
index 9df0d61c5..76f902c07 100644
--- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
+++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
@@ -448,6 +448,7 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext)
for (FunctionGroupMapIt it = functionGroups.cbegin(), end = functionGroups.cend(); it != end; ++it) {
AbstractMetaFunctionList overloads;
QSet<QString> seenSignatures;
+ bool staticEncountered = false;
for (AbstractMetaFunction *func : it.value()) {
if (!func->isAssignmentOperator()
&& !func->usesRValueReferences()
@@ -460,6 +461,19 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext)
// But when a function is both in a class and inherited in a subclass,
// then we need to search through all subclasses and collect the new signatures.
overloads << getFunctionAndInheritedOverloads(func, &seenSignatures);
+ if (func->isStatic())
+ staticEncountered = true;
+ }
+ }
+ // PYSIDE-886: If the method does not have any static overloads declared
+ // in the class in question, remove all inherited static methods as setting
+ // METH_STATIC in that case can cause crashes for the instance methods.
+ // Manifested as crash when calling QPlainTextEdit::find() (clash with
+ // static QWidget::find(WId)).
+ if (!staticEncountered) {
+ for (int i = overloads.size() - 1; i >= 0; --i) {
+ if (overloads.at(i)->isStatic())
+ delete overloads.takeAt(i);
}
}