diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-04-12 10:09:04 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-04-12 11:59:01 +0200 |
commit | 4a04afc95d348c8f26919a2f084ee80fa404e7d9 (patch) | |
tree | 19c6a2fff7a0bcdcc1ff097ae41739808c3beea3 /sources/shiboken6/generator/shiboken/cppgenerator.cpp | |
parent | 5a38771ba936584fe84537a4b01b4e8a0efc8505 (diff) |
shiboken6: Add a placeholder for the base class to polymorphic-id-expression
Add %B for base class in addition to %1 for the class itself, which
is not useful and may lead to undefined behavior.
As a drive-by fix up the hitherto unused "polymorphic-base" which
is a boolean indicating the base class.
Pick-to: 6.7
Task-number: PYSIDE-2675
Change-Id: I078191dc7b4c686b196fe58d6df9a249cdf2b151
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken6/generator/shiboken/cppgenerator.cpp')
-rw-r--r-- | sources/shiboken6/generator/shiboken/cppgenerator.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index 26caef9c4..05afde69f 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -5720,6 +5720,24 @@ void CppGenerator::writeInitQtMetaTypeFunctionBody(TextStream &s, const Generato } } +void CppGenerator::replacePolymorphicIdPlaceHolders(const AbstractMetaClassCPtr &metaClass, + QString *id) +{ + if (id->contains("%1"_L1)) { + QString replacement = " reinterpret_cast< "_L1 + m_gsp + metaClass->qualifiedCppName() + + " *>(cptr)"_L1; + id->replace("%1"_L1, replacement); + } + if (id->contains("%B"_L1)) { + 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); + } +} + void CppGenerator::writeTypeDiscoveryFunction(TextStream &s, const AbstractMetaClassCPtr &metaClass) { @@ -5731,9 +5749,7 @@ void CppGenerator::writeTypeDiscoveryFunction(TextStream &s, << sbkUnusedVariableCast("instanceType"); if (!polymorphicExpr.isEmpty()) { - polymorphicExpr.replace(u"%1"_s, " reinterpret_cast< "_L1 - + m_gsp + metaClass->qualifiedCppName() - + " *>(cptr)"_L1); + replacePolymorphicIdPlaceHolders(metaClass, &polymorphicExpr); s << " if (" << polymorphicExpr << ")\n" << indent << "return cptr;\n" << outdent; } else if (metaClass->isPolymorphic()) { |