aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2024-05-10 15:18:10 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2024-05-11 16:46:44 +0200
commit0b5f6093ae15912544444af98b9fb552e7dcfefa (patch)
tree0b952e4b5ff0c1396bb44e7b60a4d925b76a0f5f
parentaf71b84085195afd4ef5e97b1c9dcf372fc72afd (diff)
shiboken6: Avoid type name lookup in pointer converters for classes with non-virtual destructors
A lookup by typeid().name() will return the instance type name for classes with non-virtual destructors; so there is no need to do it. Change-Id: I911e3133abae37123dc47dda6be479416058668b Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
index 6c9cc5fec..419704153 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
@@ -1598,11 +1598,17 @@ static void writePointerToPythonConverter(TextStream &c,
c << "auto *pyOut = reinterpret_cast<PyObject *>(Shiboken::BindingManager::instance().retrieveWrapper(cppIn));\n"
<< "if (pyOut) {\n" << indent
<< "Py_INCREF(pyOut);\nreturn pyOut;\n" << outdent
- << "}\n"
- << "auto *tCppIn = reinterpret_cast<const " << typeName << R"( *>(cppIn);
-const char *typeName = )";
+ << "}\n";
const QString nameFunc = metaClass->typeEntry()->polymorphicNameFunction();
+ if (nameFunc.isEmpty() && !metaClass->hasVirtualDestructor()) {
+ c << "return Shiboken::Object::newObjectWithHeuristics("
+ << cpythonType << ", const_cast<void *>(cppIn), false);\n";
+ return;
+ }
+
+ c << "auto *tCppIn = reinterpret_cast<const " << typeName << R"( *>(cppIn);
+const char *typeName = )";
if (nameFunc.isEmpty())
c << "typeid(*tCppIn).name();\n";
else