aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2024-04-12 08:15:09 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2024-04-12 09:12:53 +0000
commit46ea5407a9b06dc89e81d35871d79e18df83ac53 (patch)
tree5a2066ab9bb79fe54732de791935f05eab628ee6
parent3b2ad15ec75b082699dbde6c695c19b467eb0008 (diff)
shiboken6: Add a way of disable lazy initialization per class
Task-number: PYSIDE-2675 Task-number: PYSIDE-2404 Change-Id: I11400172b0f0045fadd3183d4f0b16688b4119b6 Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> (cherry picked from commit f86293210f657f3c33f06018a846e80791aec560) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.cpp15
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.h2
2 files changed, 12 insertions, 5 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
index 1972b0dfb..05539eb55 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
@@ -5942,16 +5942,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;