diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-04-12 08:15:09 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-04-12 10:06:56 +0200 |
commit | f86293210f657f3c33f06018a846e80791aec560 (patch) | |
tree | 3232818c8a082af58d5f070d0295613811475227 /sources/shiboken6/generator | |
parent | a0d68856d67ce6e178e3cfc2fccc236707e02fcd (diff) |
shiboken6: Add a way of disable lazy initialization per class
Task-number: PYSIDE-2675
Task-number: PYSIDE-2404
Pick-to: 6.7
Change-Id: I11400172b0f0045fadd3183d4f0b16688b4119b6
Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken6/generator')
-rw-r--r-- | sources/shiboken6/generator/shiboken/cppgenerator.cpp | 15 | ||||
-rw-r--r-- | sources/shiboken6/generator/shiboken/cppgenerator.h | 2 |
2 files changed, 12 insertions, 5 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index e8b1af8f5..26caef9c4 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -5944,16 +5944,23 @@ void CppGenerator::writeNbBoolFunction(const GeneratorContext &context, void CppGenerator::writeInitFunc(TextStream &declStr, TextStream &callStr, const QString &initFunctionName, const TypeEntryCPtr &enclosingEntry, - const QString &pythonName) + const QString &pythonName, bool lazy) { + const QString functionName = "init_"_L1 + initFunctionName; const bool hasParent = enclosingEntry && enclosingEntry->type() != TypeEntry::TypeSystemType; - declStr << "PyTypeObject *init_" << initFunctionName << "(PyObject *" + declStr << "PyTypeObject *" << functionName << "(PyObject *" << (hasParent ? "enclosingClass" : "module") << ");\n"; - if (hasParent) { + + if (!lazy) { + const QString enclosing = hasParent + ? "reinterpret_cast<PyObject *>("_L1 + cpythonTypeNameExt(enclosingEntry) + u')' + : "module"_L1; + callStr << functionName << '(' << enclosing << ");\n"; + } else if (hasParent) { const QString &enclosingName = enclosingEntry->name(); const auto parts = QStringView{enclosingName}.split(u"::", Qt::SkipEmptyParts); callStr << "Shiboken::Module::AddTypeCreationFunction(" - << "module, \"" << pythonName << "\", " << "init_" << initFunctionName << ", \""; + << "module, \"" << pythonName << "\", " << functionName << ", \""; for (qsizetype i = 0; i < parts.size(); ++i) { if (i > 0) callStr << "\", \""; diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.h b/sources/shiboken6/generator/shiboken/cppgenerator.h index 4c2493094..94ad87bbe 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.h +++ b/sources/shiboken6/generator/shiboken/cppgenerator.h @@ -63,7 +63,7 @@ private: static void writeInitFunc(TextStream &declStr, TextStream &callStr, const QString &initFunctionName, const TypeEntryCPtr &enclosingEntry, - const QString &pythonName); + const QString &pythonName, bool lazy = true); static void writeCacheResetNative(TextStream &s, const GeneratorContext &classContext); void writeConstructorNative(TextStream &s, const GeneratorContext &classContext, const AbstractMetaFunctionCPtr &func) const; |