aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2024-04-11 13:06:05 +0200
committerChristian Tismer <tismer@stackless.com>2024-04-11 15:16:08 +0200
commit556bc8d158b06546343ae2f51b05f555d47442c0 (patch)
tree8d0edf88d087780d9116996f62b0033911b59645 /sources/shiboken6
parent39449c4d63f125c65bb0559d732a3c2859d9878b (diff)
Lazy Import: Ensure type creation functions being idempotent
Under circumstances it was possible to create a type twice. There would be many more changes necessary to ensure that this can never happen. Very simple to prevent this was by checking that a second call of the creation function does nothing, IOW making the functions idempotent. Tested with and without laziness. Task-number: PYSIDE-2404 Change-Id: I70e3335a12f0cbe1111febaace7275e87c843bd4 Fixes: PYSIDE-2674 Pick-to: 6.7 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/shiboken6')
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
index 1972b0dfb..e8b1af8f5 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
@@ -5420,6 +5420,12 @@ void CppGenerator::writeClassRegister(TextStream &s,
s << "PyTypeObject *init_" << initFunctionName
<< "(PyObject *" << enclosingObjectVariable << ")\n{\n" << indent;
+ const QString globalTypeVarExpr = !classContext.forSmartPointer()
+ ? cpythonTypeNameExtSet(classTypeEntry)
+ : cpythonTypeNameExtSet(classContext.preciseType());
+ s << "if (" << globalTypeVarExpr << " != nullptr)\n" << indent
+ << "return " << globalTypeVarExpr << ";\n\n" << outdent;
+
// Multiple inheritance
QString pyTypeBasesVariable = chopType(pyTypeName) + u"_Type_bases"_s;
const auto &baseClasses = metaClass->typeSystemBaseClasses();
@@ -5510,11 +5516,7 @@ void CppGenerator::writeClassRegister(TextStream &s,
if (usePySideExtensions() && !classContext.forSmartPointer())
s << "SbkObjectType_SetPropertyStrings(pyType, "
<< chopType(pyTypeName) << "_PropertyStrings);\n";
-
- if (!classContext.forSmartPointer())
- s << cpythonTypeNameExtSet(classTypeEntry) << " = pyType;\n\n";
- else
- s << cpythonTypeNameExtSet(classContext.preciseType()) << " = pyType;\n\n";
+ s << globalTypeVarExpr << " = pyType;\n\n";
// Register conversions for the type.
writeConverterRegister(s, metaClass, classContext);