From 2e7fea6165537d879abed7c127db4e19919b9198 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 14 Dec 2022 15:25:19 +0100 Subject: shiboken6: Fix the smartpointer code generation for CMake UNITY_BUILD (jumbo) Generate the getter names into the code instead of creating a variable. The compiler will automatically remove duplicate string constants. Task-number: PYSIDE-2155 Change-Id: I70e740741c6cdf8daf3fa97723d279fa8fc53bd2 Reviewed-by: Cristian Maureira-Fredes --- .../shiboken6/generator/shiboken/cppgenerator.cpp | 23 +++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'sources/shiboken6/generator/shiboken/cppgenerator.cpp') diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index 5d48bbc3b..3c3579731 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -947,10 +947,6 @@ void CppGenerator::generateSmartPointerClass(TextStream &s, const GeneratorConte s << '\n'; - // Create string literal for smart pointer getter method. - QString rawGetter = typeEntry->getter(); - s << "static const char " << SMART_POINTER_GETTER << "[] = \"" << rawGetter << "\";"; - // class inject-code native/beginning if (!typeEntry->codeSnips().isEmpty()) { writeClassCodeSnips(s, typeEntry->codeSnips(), @@ -995,7 +991,7 @@ void CppGenerator::generateSmartPointerClass(TextStream &s, const GeneratorConte writeMethodWrapper(s, md, signatureStream, resets, classContext); } - auto it = functionGroups.constFind(rawGetter); + auto it = functionGroups.constFind(typeEntry->getter()); if (it == functionGroups.cend() || it.value().size() != 1) throw Exception(msgCannotFindSmartPointerGetter(typeEntry)); @@ -6386,14 +6382,22 @@ static const char smartPtrComment[] = "// Try to find the 'name' attribute, by retrieving the PyObject for " "the corresponding C++ object held by the smart pointer.\n"; +static QString smartPointerGetter(const GeneratorContext &context) +{ + const auto te = context.metaClass()->typeEntry(); + Q_ASSERT(te->isSmartPointer()); + return qSharedPointerCast(te)->getter(); +} + void CppGenerator::writeSmartPointerSetattroFunction(TextStream &s, const GeneratorContext &context) const { Q_ASSERT(context.forSmartPointer()); writeSetattroDefinition(s, context.metaClass()); s << smartPtrComment - << "if (auto *rawObj = PyObject_CallMethod(self, " << SMART_POINTER_GETTER - << ", 0)) {\n" << indent + << "if (auto *rawObj = PyObject_CallMethod(self, \"" + << smartPointerGetter(context) + << "\", 0)) {\n" << indent << "if (PyObject_HasAttr(rawObj, name) != 0)\n" << indent << "return PyObject_GenericSetAttr(rawObj, name, value);\n" << outdent << "Py_DECREF(rawObj);\n" << outdent @@ -6510,8 +6514,9 @@ return nullptr; // This generates the code which dispatches access to member functions // and fields from the smart pointer to its pointee. s << smartPtrComment - << "if (auto *rawObj = PyObject_CallMethod(self, " - << SMART_POINTER_GETTER << ", 0)) {\n" << indent + << "if (auto *rawObj = PyObject_CallMethod(self, \"" + << smartPointerGetter(context) + << "\", 0)) {\n" << indent << "if (auto *attribute = PyObject_GetAttr(rawObj, name))\n" << indent << "tmp = attribute;\n" << outdent << "Py_DECREF(rawObj);\n" << outdent -- cgit v1.2.3