From 3e5d7d115a8ee0e7429b4285a874a9661af325f7 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 28 Mar 2022 11:14:59 +0200 Subject: 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. Pick-to: 6.2 Change-Id: I8363f16162da55a8844d4e4117e9ea7b41abb440 Reviewed-by: Christian Tismer --- .../shiboken6/generator/shiboken/cppgenerator.cpp | 26 ++++++++++++++++------ .../shiboken6/generator/shiboken/cppgenerator.h | 1 + 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index 4be8f5608..f972771e3 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -1933,6 +1933,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, ErrorReturn errorReturn) const @@ -1981,9 +1993,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; @@ -2101,9 +2115,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" @@ -2149,7 +2161,7 @@ void CppGenerator::writeConstructorWrapper(TextStream &s, const OverloadData &ov } s << "\n\nreturn 1;\n"; - if (errHandlerNeeded) + if (needsArgumentErrorHandling(overloadData)) writeErrorSection(s, overloadData, errorReturn); s<< outdent << "}\n\n"; } @@ -2258,7 +2270,7 @@ void CppGenerator::writeMethodWrapper(TextStream &s, const OverloadData &overloa s << "Py_RETURN_NONE;\n"; } - if (maxArgs > 0) + if (needsArgumentErrorHandling(overloadData)) writeErrorSection(s, overloadData, ErrorReturn::Default); s<< outdent << "}\n\n"; diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.h b/sources/shiboken6/generator/shiboken/cppgenerator.h index 287aa1706..a45374dbb 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.h +++ b/sources/shiboken6/generator/shiboken/cppgenerator.h @@ -119,6 +119,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, ErrorReturn errorReturn = ErrorReturn::Default) const; -- cgit v1.2.3