aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/generator/shiboken/cppgenerator.cpp
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2021-04-18 18:58:18 +0200
committerChristian Tismer <tismer@stackless.com>2021-09-29 17:34:58 +0200
commit7e5539dfa9f648580fe9bef60b193f368c4db3f0 (patch)
treed40dfce6ec119663785fb7f3435cefc8228066f6 /sources/shiboken6/generator/shiboken/cppgenerator.cpp
parent096cc9c3703f40f1f596cf79a680dabfaad232bd (diff)
Shiboken: simplify and refactor more after PyTypeObject change
After the move to general PyTypeObject usage, some refactoring is possible: In pysidesignal.cpp, the function `getTypeName` is refactored. The name "type" should be used for PyTypeObject if possible. In cppgenerator.cpp, a lot of reinterpret_cast calls can be avoided, also the local variable `pyType` can be used conveniently in function `writeConverterRegister`. In basewrapper.cpp, the function `introduceWrapperType` is simplified, and the part relevant for PyPy is clearly separated. Task-number: PYSIDE-535 Change-Id: If0fffbad7ee04f92d25111a8620263c8973a7bf0 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/shiboken6/generator/shiboken/cppgenerator.cpp')
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.cpp22
1 files changed, 9 insertions, 13 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
index c7fa2126a..412546767 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
@@ -1447,8 +1447,7 @@ void CppGenerator::writeConverterFunctions(TextStream &s, const AbstractMetaClas
writePythonToCppFunction(s, c.toString(), sourceTypeName, targetTypeName);
// "Is convertible" function for the Python object to C++ pointer conversion.
- const QString pyTypeCheck = QLatin1String("PyObject_TypeCheck(pyIn, reinterpret_cast<PyTypeObject *>(")
- + cpythonType + QLatin1String("))");
+ const QString pyTypeCheck = u"PyObject_TypeCheck(pyIn, "_qs + cpythonType + u")"_qs;
writeIsPythonConvertibleToCppFunction(s, sourceTypeName, targetTypeName, pyTypeCheck, QString(), true);
s << '\n';
@@ -1644,8 +1643,7 @@ void CppGenerator::writeConverterRegister(TextStream &s, const AbstractMetaClass
if (metaClass->isNamespace())
return;
s << "// Register Converter\n"
- << "SbkConverter *converter = Shiboken::Conversions::createConverter("
- << cpythonTypeName(metaClass) << ',' << '\n';
+ << "SbkConverter *converter = Shiboken::Conversions::createConverter(pyType,\n";
{
Indentation indent(s);
QString sourceTypeName = metaClass->name();
@@ -5338,7 +5336,7 @@ void CppGenerator::writeSignalInitialization(TextStream &s, const AbstractMetaCl
}
}
- s << "PySide::Signal::registerSignals(" << cpythonTypeName(metaClass) << ", &::"
+ s << "PySide::Signal::registerSignals(pyType, &::"
<< metaClass->qualifiedCppName() << "::staticMetaObject);\n";
}
@@ -5633,18 +5631,17 @@ void CppGenerator::writeClassRegister(TextStream &s,
else
s << wrapperFlags.join(" | ");
}
- s << ");\nauto pyType = reinterpret_cast<PyTypeObject *>(" << typePtr << ");\n"
+ s << ");\nauto *pyType = " << typePtr << ";\n"
<< "InitSignatureStrings(pyType, " << initFunctionName << "_SignatureStrings);\n";
if (usePySideExtensions())
- s << "SbkObjectType_SetPropertyStrings(reinterpret_cast<PyTypeObject *>(" << typePtr << "), "
+ s << "SbkObjectType_SetPropertyStrings(pyType, "
<< chopType(pyTypeName) << "_PropertyStrings);\n";
if (!classContext.forSmartPointer())
- s << cpythonTypeNameExt(classTypeEntry) << '\n';
+ s << cpythonTypeNameExt(classTypeEntry) << " = pyType;\n\n";
else
- s << cpythonTypeNameExt(classContext.preciseType()) << '\n';
- s << " = " << pyTypeName << ";\n\n";
+ s << cpythonTypeNameExt(classContext.preciseType()) << " = pyType;\n\n";
// Register conversions for the type.
writeConverterRegister(s, metaClass, classContext);
@@ -5705,9 +5702,8 @@ void CppGenerator::writeClassRegister(TextStream &s,
}
if (usePySideExtensions() && metaClass->isQObject()) {
- s << "Shiboken::ObjectType::setSubTypeInitHook(" << pyTypeName
- << ", &PySide::initQObjectSubType);\n"
- << "PySide::initDynamicMetaObject(" << pyTypeName << ", &::"
+ s << "Shiboken::ObjectType::setSubTypeInitHook(pyType, &PySide::initQObjectSubType);\n"
+ << "PySide::initDynamicMetaObject(pyType, &::"
<< metaClass->qualifiedCppName() << "::staticMetaObject, sizeof(";
if (shouldGenerateCppWrapper(metaClass))
s << wrapperName(metaClass);