aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-06-02 13:31:14 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2021-06-03 22:36:37 +0200
commit4bdbe195d61a20d894d71da09ecf9bfacf5eca0c (patch)
tree6d5687263106da3f36a4f01b895fe3f7b1e40e89
parent039776b1af905ab90ab49f6986214450e8099882 (diff)
shiboken6: Do not generate destructor calls for protected destructors with "disable-wrapper"
Factor out a helper function to return the class name for which Shiboken::callCppDestructor<> is to be called and handle the case. As a drive-by, fix nullptr in class register. Amends 1d044f467070a040713c9566a8a8de3a56c571e7. Task-number: PYSIDE-1568 Pick-to: 6.1 Change-Id: I22e5596c066422274c3c994cc398311fc99f1709 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.cpp35
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.h2
2 files changed, 25 insertions, 12 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
index cb218ee8b..f9e1c5f8d 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
@@ -5352,6 +5352,25 @@ void CppGenerator::writeSignatureStrings(TextStream &s,
s << NULL_PTR << "}; // Sentinel\n" << outdent << '\n';
}
+// Return the class name for which to invoke the destructor
+QString CppGenerator::destructorClassName(const AbstractMetaClass *metaClass,
+ const GeneratorContext &classContext) const
+{
+ if (metaClass->isNamespace() || metaClass->hasPrivateDestructor())
+ return {};
+ if (classContext.forSmartPointer())
+ return classContext.smartPointerWrapperName();
+ const bool isValue = metaClass->typeEntry()->isValue();
+ const bool hasProtectedDestructor = metaClass->hasProtectedDestructor();
+ if (((avoidProtectedHack() && hasProtectedDestructor) || isValue)
+ && classContext.useWrapper()) {
+ return classContext.wrapperName();
+ }
+ if (avoidProtectedHack() && hasProtectedDestructor)
+ return {}; // Cannot call (happens with "disable-wrapper").
+ return metaClass->qualifiedCppName();
+}
+
void CppGenerator::writeClassRegister(TextStream &s,
const AbstractMetaClass *metaClass,
const GeneratorContext &classContext,
@@ -5419,19 +5438,11 @@ void CppGenerator::writeClassRegister(TextStream &s,
s << '&' << chopType(pyTypeName) << "_spec,\n";
// 5:cppObjDtor
- if (!metaClass->isNamespace() && !metaClass->hasPrivateDestructor()) {
- QString dtorClassName = metaClass->qualifiedCppName();
- if (((avoidProtectedHack() && metaClass->hasProtectedDestructor()) || classTypeEntry->isValue())
- && classContext.useWrapper()) {
- dtorClassName = classContext.wrapperName();
- }
- if (classContext.forSmartPointer())
- dtorClassName = classContext.smartPointerWrapperName();
-
+ QString dtorClassName = destructorClassName(metaClass, classContext);
+ if (dtorClassName.isEmpty())
+ s << "nullptr,\n";
+ else
s << "&Shiboken::callCppDestructor< ::" << dtorClassName << " >,\n";
- } else {
- s << "0,\n";
- }
// 6:baseType: Find a type that is not disabled.
auto base = metaClass->isNamespace()
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.h b/sources/shiboken6/generator/shiboken/cppgenerator.h
index 745d60dff..7795b4e11 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator.h
+++ b/sources/shiboken6/generator/shiboken/cppgenerator.h
@@ -288,6 +288,8 @@ private:
const AbstractMetaClass *metaClass,
const GeneratorContext &classContext,
const QString &signatures) const;
+ QString destructorClassName(const AbstractMetaClass *metaClass,
+ const GeneratorContext &classContext) const;
static void writeStaticFieldInitialization(TextStream &s,
const AbstractMetaClass *metaClass);
void writeClassDefinition(TextStream &s,