aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-03-28 11:14:59 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2022-04-04 09:36:40 +0200
commitdc281d26be84bc161ea1b9db04bb16e94d640b5c (patch)
treec775751a57c8b9dcef86eb2379430503927453ca
parentec72a4c4c29c116c1b89b34a574b74891be423f1 (diff)
shiboken6: Only generate argument error handling when needed
Add a function to check whether argument error handling is needed (function has arguments or is a QObject constructor) and do not generate the variables if that is not the case. Change-Id: I8363f16162da55a8844d4e4117e9ea7b41abb440 Reviewed-by: Christian Tismer <tismer@stackless.com> (cherry picked from commit 3e5d7d115a8ee0e7429b4285a874a9661af325f7) Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.cpp26
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.h1
2 files changed, 20 insertions, 7 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
index 073f80303..15f2012ab 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
@@ -1859,6 +1859,18 @@ void CppGenerator::writeSmartPointerConverterFunctions(TextStream &s,
}
}
+bool CppGenerator::needsArgumentErrorHandling(const OverloadData &overloadData) const
+{
+ if (overloadData.maxArgs() > 0)
+ return true;
+ // QObject constructors need error handling when passing properties as kwarg.
+ if (!usePySideExtensions())
+ return false;
+ auto rfunc = overloadData.referenceFunction();
+ return rfunc->functionType() == AbstractMetaFunction::ConstructorFunction
+ && rfunc->ownerClass()->isQObject();
+}
+
void CppGenerator::writeMethodWrapperPreamble(TextStream &s,const OverloadData &overloadData,
const GeneratorContext &context) const
{
@@ -1907,9 +1919,11 @@ void CppGenerator::writeMethodWrapperPreamble(TextStream &s,const OverloadData &
initPythonArguments = minArgs != maxArgs || maxArgs > 1;
}
- s << R"(Shiboken::AutoDecRef errInfo{};
-static const char *fullName = ")" << fullPythonFunctionName(rfunc, true)
- << "\";\nSBK_UNUSED(fullName)\n";
+ if (needsArgumentErrorHandling(overloadData)) {
+ s << R"(Shiboken::AutoDecRef errInfo{};
+static const char fullName[] = ")" << fullPythonFunctionName(rfunc, true)
+ << "\";\nSBK_UNUSED(fullName)\n";
+ }
if (maxArgs > 0) {
s << "int overloadId = -1;\n"
<< PYTHON_TO_CPPCONVERSION_STRUCT << ' ' << PYTHON_TO_CPP_VAR;
@@ -2031,9 +2045,7 @@ void CppGenerator::writeConstructorWrapper(TextStream &s, const OverloadData &ov
s << "}\nShiboken::BindingManager::instance().registerWrapper(sbkSelf, cptr);\n";
// Create metaObject and register signal/slot
- bool errHandlerNeeded = overloadData.maxArgs() > 0;
if (needsMetaObject) {
- errHandlerNeeded = true;
s << "\n// QObject setup\n"
<< "PySide::Signal::updateSourceObject(self);\n"
<< "metaObject = cptr->metaObject(); // <- init python qt properties\n"
@@ -2079,7 +2091,7 @@ void CppGenerator::writeConstructorWrapper(TextStream &s, const OverloadData &ov
}
s << "\n\nreturn 1;\n";
- if (errHandlerNeeded)
+ if (needsArgumentErrorHandling(overloadData))
writeErrorSection(s, overloadData);
s<< outdent << "}\n\n";
}
@@ -2187,7 +2199,7 @@ void CppGenerator::writeMethodWrapper(TextStream &s, const OverloadData &overloa
s << "Py_RETURN_NONE;\n";
}
- if (maxArgs > 0)
+ if (needsArgumentErrorHandling(overloadData))
writeErrorSection(s, overloadData);
s<< outdent << "}\n\n";
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.h b/sources/shiboken6/generator/shiboken/cppgenerator.h
index 1741d5092..b5de61eab 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator.h
+++ b/sources/shiboken6/generator/shiboken/cppgenerator.h
@@ -109,6 +109,7 @@ private:
void writeSmartPointerConverterFunctions(TextStream &s,
const AbstractMetaType &smartPointerType) const;
+ bool needsArgumentErrorHandling(const OverloadData &overloadData) const;
void writeMethodWrapperPreamble(TextStream &s, const OverloadData &overloadData,
const GeneratorContext &context) const;
void writeConstructorWrapper(TextStream &s, const OverloadData &overloadData,