aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/generator/shiboken/cppgenerator.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-12-14 15:25:19 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2022-12-15 08:23:19 +0100
commit2e7fea6165537d879abed7c127db4e19919b9198 (patch)
tree855255bb5e0aecb9d714b11ee790f165578ef74b /sources/shiboken6/generator/shiboken/cppgenerator.cpp
parent83f7993e9e6dd0a6d515d08ee6448b82c12ff1b1 (diff)
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 <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken6/generator/shiboken/cppgenerator.cpp')
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.cpp23
1 files changed, 14 insertions, 9 deletions
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<const SmartPointerTypeEntry>(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