diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-04-24 13:51:11 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-04-25 13:02:03 +0200 |
commit | ae23c335e0988111e58feef75df1d50b697359aa (patch) | |
tree | f137cedc2a1b85cf7c030fbee7ea8091e1015464 /sources/shiboken6/generator | |
parent | ce2959ec5135965ef67476274a8b4a57c897f4cf (diff) |
Revert "Lazy Load: Fix polymorphic classes by identifying lazy groups"
This reverts commit 9f09e1dda0f167432110a22db6f9a5accf800734.
Let's try to make the dependency graph lazy.
Revert the change, excluding the test bits.
Task-number: PYSIDE-2404
Task-number: PYSIDE-2675
Pick-to: 6.7
Change-Id: I0d28678f09834a09255dce28862e0970d68ac9fa
Reviewed-by: Adrian Herrmann <adrian.herrmann@qt.io>
Diffstat (limited to 'sources/shiboken6/generator')
-rw-r--r-- | sources/shiboken6/generator/shiboken/cppgenerator.cpp | 66 | ||||
-rw-r--r-- | sources/shiboken6/generator/shiboken/cppgenerator.h | 3 |
2 files changed, 16 insertions, 53 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index 037209dfb..ad4071c35 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -5769,18 +5769,6 @@ void CppGenerator::writeInitQtMetaTypeFunctionBody(TextStream &s, const Generato } } -// Note: This is an incomplete function that does not work without a -// surrounding functionality. It's purpose is to make sure that exactly -// this expression always is used, although the first clause is never true in PySide. -// Without it can create false positives. -static AbstractMetaClassCPtr getPolymorphicBaseClass(const AbstractMetaClassCPtr &metaClass) -{ - auto baseClass = metaClass; - while (!baseClass->typeEntry()->isPolymorphicBase() && baseClass->baseClass()) - baseClass = baseClass->baseClass(); - return baseClass; -} - void CppGenerator::replacePolymorphicIdPlaceHolders(const AbstractMetaClassCPtr &metaClass, QString *id) { @@ -5790,7 +5778,9 @@ void CppGenerator::replacePolymorphicIdPlaceHolders(const AbstractMetaClassCPtr id->replace("%1"_L1, replacement); } if (id->contains("%B"_L1)) { - auto baseClass = getPolymorphicBaseClass(metaClass); + auto baseClass = metaClass; + while (!baseClass->typeEntry()->isPolymorphicBase() && baseClass->baseClass()) + baseClass = baseClass->baseClass(); QString replacement = " reinterpret_cast< "_L1 + m_gsp + baseClass->qualifiedCppName() + " *>(cptr)"_L1; id->replace("%B"_L1, replacement); @@ -6019,15 +6009,19 @@ void CppGenerator::writeNbBoolFunction(const GeneratorContext &context, void CppGenerator::writeInitFunc(TextStream &declStr, TextStream &callStr, const QString &initFunctionName, const TypeEntryCPtr &enclosingEntry, - const QString &pythonName, - const QString &lazyGroup) + const QString &pythonName, bool lazy) { - const QString functionName = "init_"_L1 + initFunctionName; const bool hasParent = enclosingEntry && enclosingEntry->type() != TypeEntry::TypeSystemType; 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(" @@ -6039,13 +6033,9 @@ void CppGenerator::writeInitFunc(TextStream &declStr, TextStream &callStr, } callStr << "\");\n"; } else { - const char *funcName = lazyGroup.isEmpty() - ? "AddTypeCreationFunction" : "AddGroupedTypeCreationFunction"; - callStr << "Shiboken::Module::" << funcName << "(module, \"" - << pythonName << "\", " << functionName; - if (!lazyGroup.isEmpty()) - callStr << ", \"" << lazyGroup << "\""; - callStr << ");\n"; + callStr << "Shiboken::Module::AddTypeCreationFunction(" + << "module, \"" << pythonName << "\", " + << "init_" << initFunctionName << ");\n"; } } @@ -6062,12 +6052,6 @@ static void writeSubModuleHandling(TextStream &s, const QString &moduleName, << indent << "return nullptr;\n" << outdent << outdent << "}\n"; } -static AbstractMetaClassCPtr getLazyGroupBaseClass(const AbstractMetaClassCPtr &metaClass) -{ - return needsTypeDiscoveryFunction(metaClass) && !isQObject(metaClass) - ? getPolymorphicBaseClass(metaClass) : nullptr; -} - bool CppGenerator::finishGeneration() { //Generate CPython wrapper file @@ -6099,18 +6083,6 @@ bool CppGenerator::finishGeneration() s_globalFunctionDef << methodDefinitionEntries(overloadData); } - // Collect the lazy group base classes first, because we need to add - // these base classes into the group, too. - std::set<AbstractMetaClassCPtr> lazyGroupBaseClasses{}; - for (const auto &cls : api().classes()){ - auto te = cls->typeEntry(); - if (shouldGenerate(te)) { - auto lazyGroupCls = getLazyGroupBaseClass(cls); - if (lazyGroupCls) - lazyGroupBaseClasses.insert(lazyGroupCls); - } - } - AbstractMetaClassCList classesWithStaticFields; for (const auto &cls : api().classes()){ auto te = cls->typeEntry(); @@ -6120,17 +6092,9 @@ bool CppGenerator::finishGeneration() s_classInitDecl << te->configCondition() << '\n'; s_classPythonDefines << te->configCondition() << '\n'; } - auto lazyGroupCls = getLazyGroupBaseClass(cls); - if (!lazyGroupCls) { - auto it = lazyGroupBaseClasses.find(cls); - if (it != lazyGroupBaseClasses.end()) - lazyGroupCls = cls; - } writeInitFunc(s_classInitDecl, s_classPythonDefines, getSimpleClassInitFunctionName(cls), - targetLangEnclosingEntry(te), cls->name(), - lazyGroupCls ? lazyGroupCls->typeEntry()->qualifiedTargetLangName() - : QString()); + targetLangEnclosingEntry(te), cls->name()); if (cls->hasStaticFields()) { s_classInitDecl << "PyTypeObject *" << getSimpleClassStaticFieldsInitFunctionName(cls) << "(PyObject *module);\n"; diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.h b/sources/shiboken6/generator/shiboken/cppgenerator.h index 6c20d9d78..1ad576895 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.h +++ b/sources/shiboken6/generator/shiboken/cppgenerator.h @@ -63,8 +63,7 @@ private: static void writeInitFunc(TextStream &declStr, TextStream &callStr, const QString &initFunctionName, const TypeEntryCPtr &enclosingEntry, - const QString &pythonName, - const QString &lazyGroup = {}); + 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; |