diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-09-10 11:29:19 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-09-11 08:36:40 +0000 |
commit | a4311711eb89e3f9833a05edf3debdf7563a104f (patch) | |
tree | 257a50545359f81f7c17437003dc70f4ba74b835 /sources | |
parent | 327cd3aa4da7d4a9c4ce593751fd3e385abba3f0 (diff) |
Define SbkObjectType to be a PyTypeObject
SbkObjectType was a struct embedding a PyTypeObject
after fec1611e9f42c1f0a13eb33474df2ed8ee480842.
Remove that and make the types equvivalent, which allows for
removing many reinterpret_casts.
SbkObjectType is left as a typedef for client code snippets.
[ChangeLog][shiboken6] SbkObjectType is now a typedef for PyTypeObject.
Task-number: PYSIDE-535
Change-Id: I44812311ccbbe0988c38e34c47d16f6874f8d1cf
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources')
25 files changed, 100 insertions, 149 deletions
diff --git a/sources/pyside6/PySide6/QtQml/pysideqmlregistertype.h b/sources/pyside6/PySide6/QtQml/pysideqmlregistertype.h index 2a90a07e0..0dbfb6e5a 100644 --- a/sources/pyside6/PySide6/QtQml/pysideqmlregistertype.h +++ b/sources/pyside6/PySide6/QtQml/pysideqmlregistertype.h @@ -42,8 +42,6 @@ #include <sbkpython.h> -struct SbkObjectType; - namespace PySide { diff --git a/sources/pyside6/PySide6/QtQuick/pysidequickregistertype.h b/sources/pyside6/PySide6/QtQuick/pysidequickregistertype.h index 1955413b2..ee4b60866 100644 --- a/sources/pyside6/PySide6/QtQuick/pysidequickregistertype.h +++ b/sources/pyside6/PySide6/QtQuick/pysidequickregistertype.h @@ -42,8 +42,6 @@ #include <sbkpython.h> -struct SbkObjectType; - namespace PySide { void initQuickSupport(PyObject *module); diff --git a/sources/pyside6/PySide6/glue/qtcore.cpp b/sources/pyside6/PySide6/glue/qtcore.cpp index d749c17c1..ad5eb447f 100644 --- a/sources/pyside6/PySide6/glue/qtcore.cpp +++ b/sources/pyside6/PySide6/glue/qtcore.cpp @@ -150,8 +150,7 @@ return %out; static QMetaType QVariant_resolveMetaType(PyTypeObject *type) { if (PyObject_TypeCheck(type, SbkObjectType_TypeF())) { - auto sbkType = reinterpret_cast<SbkObjectType *>(type); - const char *typeName = Shiboken::ObjectType::getOriginalName(sbkType); + const char *typeName = Shiboken::ObjectType::getOriginalName(type); if (!typeName) return {}; const bool valueType = '*' != typeName[qstrlen(typeName) - 1]; @@ -1316,7 +1315,7 @@ auto *ptr = reinterpret_cast<uchar *>(Shiboken::Buffer::getPointer(%PYARG_1, &si // %FUNCTION_NAME() - disable generation of c++ function call (void) %2; // remove warning about unused variable Shiboken::AutoDecRef emptyTuple(PyTuple_New(0)); -auto *timerType = reinterpret_cast<PyTypeObject *>(Shiboken::SbkType<QTimer>()); +auto *timerType = Shiboken::SbkType<QTimer>(); auto *pyTimer = timerType->tp_new(Shiboken::SbkType<QTimer>(), emptyTuple, nullptr); timerType->tp_init(pyTimer, emptyTuple, nullptr); @@ -1339,7 +1338,7 @@ timer->start(%1); // @snippet qtimer-singleshot-2 // %FUNCTION_NAME() - disable generation of c++ function call Shiboken::AutoDecRef emptyTuple(PyTuple_New(0)); -auto *timerType = reinterpret_cast<PyTypeObject *>(Shiboken::SbkType<QTimer>()); +auto *timerType = Shiboken::SbkType<QTimer>(); auto *pyTimer = timerType->tp_new(Shiboken::SbkType<QTimer>(), emptyTuple, nullptr); timerType->tp_init(pyTimer, emptyTuple, nullptr); QTimer * timer = %CONVERTTOCPP[QTimer *](pyTimer); diff --git a/sources/pyside6/PySide6/glue/qtwidgets.cpp b/sources/pyside6/PySide6/glue/qtwidgets.cpp index d2b7872d4..802a3c172 100644 --- a/sources/pyside6/PySide6/glue/qtwidgets.cpp +++ b/sources/pyside6/PySide6/glue/qtwidgets.cpp @@ -56,7 +56,7 @@ Shiboken::Object::releaseOwnership(%PYARG_0); // @snippet qgraphicsitem PyObject *userTypeConstant = PyLong_FromLong(QGraphicsItem::UserType); -PyDict_SetItemString(reinterpret_cast<PyTypeObject *>(Sbk_QGraphicsItem_TypeF())->tp_dict, "UserType", userTypeConstant); +PyDict_SetItemString(Sbk_QGraphicsItem_TypeF()->tp_dict, "UserType", userTypeConstant); // @snippet qgraphicsitem // @snippet qgraphicsitem-scene-return-parenting diff --git a/sources/pyside6/libpyside/dynamicqmetaobject.cpp b/sources/pyside6/libpyside/dynamicqmetaobject.cpp index 5269067e7..fb8762a0a 100644 --- a/sources/pyside6/libpyside/dynamicqmetaobject.cpp +++ b/sources/pyside6/libpyside/dynamicqmetaobject.cpp @@ -473,7 +473,7 @@ void MetaObjectBuilderPrivate::parsePythonType(PyTypeObject *type) basesToCheck.reserve(1u + basesCount); basesToCheck.push_back(type); - auto sbkObjTypeF = reinterpret_cast<PyTypeObject *>(SbkObject_TypeF()); + auto sbkObjTypeF = SbkObject_TypeF(); auto baseObjType = reinterpret_cast<PyTypeObject *>(&PyBaseObject_Type); for (Py_ssize_t i = 0; i < basesCount; ++i) { auto baseType = reinterpret_cast<PyTypeObject *>(PyTuple_GET_ITEM(mro, i)); diff --git a/sources/pyside6/libpyside/pyside.cpp b/sources/pyside6/libpyside/pyside.cpp index 990b45694..59b7f54e9 100644 --- a/sources/pyside6/libpyside/pyside.cpp +++ b/sources/pyside6/libpyside/pyside.cpp @@ -240,14 +240,9 @@ void initDynamicMetaObject(SbkObjectType *type, const QMetaObject *base, std::si PySide::PyName::qtStaticMetaObject(), pyMetaObject); } -TypeUserData *retrieveTypeUserData(SbkObjectType *sbkTypeObj) -{ - return reinterpret_cast<TypeUserData *>(Shiboken::ObjectType::getTypeUserData(sbkTypeObj)); -} - TypeUserData *retrieveTypeUserData(PyTypeObject *pyTypeObj) { - return retrieveTypeUserData(reinterpret_cast<SbkObjectType *>(pyTypeObj)); + return reinterpret_cast<TypeUserData *>(Shiboken::ObjectType::getTypeUserData(pyTypeObj)); } TypeUserData *retrieveTypeUserData(PyObject *pyObj) diff --git a/sources/pyside6/libpyside/pyside.h b/sources/pyside6/libpyside/pyside.h index 0c9ad92cf..b74cc8414 100644 --- a/sources/pyside6/libpyside/pyside.h +++ b/sources/pyside6/libpyside/pyside.h @@ -51,8 +51,6 @@ #include <QtCore/QMetaType> #include <QtCore/QHash> -struct SbkObjectType; - namespace PySide { diff --git a/sources/pyside6/libpyside/pyside_p.h b/sources/pyside6/libpyside/pyside_p.h index 1084a40a1..a5183c907 100644 --- a/sources/pyside6/libpyside/pyside_p.h +++ b/sources/pyside6/libpyside/pyside_p.h @@ -44,8 +44,6 @@ #include <dynamicqmetaobject.h> -struct SbkObjectType; - namespace PySide { @@ -59,7 +57,6 @@ struct TypeUserData std::size_t cppObjSize; }; -TypeUserData *retrieveTypeUserData(SbkObjectType *sbkTypeObj); TypeUserData *retrieveTypeUserData(PyTypeObject *pyTypeObj); TypeUserData *retrieveTypeUserData(PyObject *pyObj); // For QML diff --git a/sources/pyside6/libpyside/pysidesignal.cpp b/sources/pyside6/libpyside/pysidesignal.cpp index 95acb1bad..3a3b52c2a 100644 --- a/sources/pyside6/libpyside/pysidesignal.cpp +++ b/sources/pyside6/libpyside/pysidesignal.cpp @@ -942,7 +942,7 @@ static typename T::value_type join(T t, const char *sep) static void _addSignalToWrapper(SbkObjectType *wrapperType, const char *signalName, PySideSignal *signal) { - auto typeDict = reinterpret_cast<PyTypeObject *>(wrapperType)->tp_dict; + auto typeDict = wrapperType->tp_dict; PyObject *homonymousMethod; if ((homonymousMethod = PyDict_GetItemString(typeDict, signalName))) { Py_INCREF(homonymousMethod); diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index 9929bdd78..32c82f2cb 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -1908,9 +1908,9 @@ void CppGenerator::writeConstructorWrapper(TextStream &s, const OverloadData &ov s << "SbkObject *sbkSelf = reinterpret_cast<SbkObject *>(self);\n"; if (metaClass->isAbstract() || metaClass->baseClassNames().size() > 1) { - s << "SbkObjectType *type = reinterpret_cast<SbkObjectType *>(self->ob_type);\n" - << "SbkObjectType *myType = reinterpret_cast<SbkObjectType *>(" - << cpythonTypeNameExt(metaClass->typeEntry()) << ");\n"; + s << "PyTypeObject *type = self->ob_type;\n" + << "PyTypeObject *myType = " + << cpythonTypeNameExt(metaClass->typeEntry()) << ";\n"; } if (metaClass->isAbstract()) { @@ -3846,9 +3846,9 @@ void CppGenerator::writeMethodCall(TextStream &s, const AbstractMetaFunctionCPtr && !func->injectedCodeHasReturnValueAttribution(TypeSystem::TargetLangCode)) { s << PYTHON_RETURN_VAR << " = "; if (func->type().isObjectTypeUsedAsValueType()) { - s << "Shiboken::Object::newObject(reinterpret_cast<SbkObjectType *>(" + s << "Shiboken::Object::newObject(" << cpythonTypeNameExt(func->type().typeEntry()) - << "), " << CPP_RETURN_VAR << ", true, true)"; + << ", " << CPP_RETURN_VAR << ", true, true)"; } else { writeToPythonConversion(s, func->type(), func->ownerClass(), QLatin1String(CPP_RETURN_VAR)); } @@ -4042,8 +4042,7 @@ void CppGenerator::writeSpecialCastFunction(TextStream &s, const AbstractMetaCla for (const AbstractMetaClass *baseClass : allAncestors) { if (!firstClass) s << "else "; - s << "if (desiredType == reinterpret_cast<SbkObjectType *>(" - << cpythonTypeNameExt(baseClass->typeEntry()) << "))\n"; + s << "if (desiredType == " << cpythonTypeNameExt(baseClass->typeEntry()) << ")\n"; Indentation indent(s); s << "return static_cast< ::" << baseClass->qualifiedCppName() << " *>(me);\n"; firstClass = false; @@ -4223,9 +4222,8 @@ void CppGenerator::writeExtendedConverterInitialization(TextStream &s, const Typ s << "// Extended implicit conversions for " << externalType->qualifiedTargetLangName() << ".\n"; for (const AbstractMetaClass *sourceClass : conversions) { - const QString converterVar = QLatin1String("reinterpret_cast<SbkObjectType *>(") - + cppApiVariableName(externalType->targetLangPackage()) + QLatin1Char('[') - + getTypeIndexVariableName(externalType) + QLatin1String("])"); + const QString converterVar = cppApiVariableName(externalType->targetLangPackage()) + QLatin1Char('[') + + getTypeIndexVariableName(externalType) + u']'; QString sourceTypeName = fixedCppTypeName(sourceClass->typeEntry()); QString targetTypeName = fixedCppTypeName(externalType); QString toCpp = pythonToCppFunctionName(sourceTypeName, targetTypeName); @@ -4328,7 +4326,7 @@ void CppGenerator::writeClassDefinition(TextStream &s, } if (!metaClass->baseClass()) - baseClassName = QLatin1String("reinterpret_cast<PyTypeObject *>(SbkObject_TypeF())"); + baseClassName = QLatin1String("SbkObject_TypeF()"); bool onlyPrivCtor = !metaClass->hasNonPrivateConstructor(); @@ -4683,7 +4681,7 @@ void CppGenerator::writeTpTraverseFunction(TextStream &s, const AbstractMetaClas QString baseName = cpythonBaseName(metaClass); s << "static int " << baseName << "_traverse(PyObject *self, visitproc visit, void *arg)\n{\n" << indent - << "return reinterpret_cast<PyTypeObject *>(SbkObject_TypeF())->tp_traverse(self, visit, arg);\n" + << "return SbkObject_TypeF()->tp_traverse(self, visit, arg);\n" << outdent << "}\n"; } @@ -4769,9 +4767,9 @@ void CppGenerator::writeGetterFunction(TextStream &s, { Indentation indent(s); s << "pyOut = reinterpret_cast<PyObject *>(Shiboken::Object::findColocatedChild(" - << "reinterpret_cast<SbkObject *>(self), reinterpret_cast<SbkObjectType *>(" + << "reinterpret_cast<SbkObject *>(self), " << cpythonTypeNameExt(fieldType) - << ")));\n"; + << "));\n"; s << "if (pyOut) {\n"; { Indentation indent(s); @@ -4792,8 +4790,8 @@ void CppGenerator::writeGetterFunction(TextStream &s, s << "}\n"; // Create and register new wrapper s << "pyOut = " - << "Shiboken::Object::newObject(reinterpret_cast<SbkObjectType *>(" << cpythonTypeNameExt(fieldType) - << "), " << cppField << ", false, true);\n" + << "Shiboken::Object::newObject(" << cpythonTypeNameExt(fieldType) + << ", " << cppField << ", false, true);\n" << "Shiboken::Object::setParent(self, pyOut)"; } else { s << "pyOut = "; @@ -5280,9 +5278,9 @@ void CppGenerator::writeEnumInitialization(TextStream &s, const AbstractMetaEnum { Indentation indent(s); s << "PyObject *anonEnumItem = PyLong_FromLong(" << enumValueText << ");\n" - << "if (PyDict_SetItemString(reinterpret_cast<PyTypeObject *>(reinterpret_cast<SbkObjectType *>(" + << "if (PyDict_SetItemString(reinterpret_cast<PyTypeObject *>(" << enclosingObjectVariable - << "))->tp_dict, \"" << mangledName << "\", anonEnumItem) < 0)\n"; + << ")->tp_dict, \"" << mangledName << "\", anonEnumItem) < 0)\n"; { Indentation indent(s); s << returnStatement(m_currentErrorCode) << '\n'; @@ -5624,8 +5622,7 @@ void CppGenerator::writeClassRegister(TextStream &s, } } if (base) { - s << "reinterpret_cast<SbkObjectType *>(" - << cpythonTypeNameExt(base->typeEntry()) << "),\n"; + s << cpythonTypeNameExt(base->typeEntry()) << ",\n"; } else { s << "0,\n"; } @@ -5658,7 +5655,7 @@ void CppGenerator::writeClassRegister(TextStream &s, s << cpythonTypeNameExt(classTypeEntry) << '\n'; else s << cpythonTypeNameExt(classContext.preciseType()) << '\n'; - s << " = reinterpret_cast<PyTypeObject *>(" << pyTypeName << ");\n\n"; + s << " = " << pyTypeName << ";\n\n"; // Register conversions for the type. writeConverterRegister(s, metaClass, classContext); @@ -5679,8 +5676,8 @@ void CppGenerator::writeClassRegister(TextStream &s, if (miClass == metaClass) { s << multipleInheritanceInitializerFunctionName(miClass) << ";\n"; } else { - s << "Shiboken::ObjectType::getMultipleInheritanceFunction(reinterpret_cast<SbkObjectType *>(" - << cpythonTypeNameExt(miClass->typeEntry()) << "));\n"; + s << "Shiboken::ObjectType::getMultipleInheritanceFunction(" + << cpythonTypeNameExt(miClass->typeEntry()) << ");\n"; } s << "Shiboken::ObjectType::setMultipleInheritanceFunction(" << cpythonTypeName(metaClass) << ", func);\n" @@ -5830,8 +5827,8 @@ void CppGenerator::writeTypeDiscoveryFunction(TextStream &s, const AbstractMetaC if (ancestor->baseClass()) continue; if (ancestor->isPolymorphic()) { - s << "if (instanceType == reinterpret_cast<SbkObjectType *>(Shiboken::SbkType< ::" - << ancestor->qualifiedCppName() << " >()))\n"; + s << "if (instanceType == Shiboken::SbkType< ::" + << ancestor->qualifiedCppName() << " >())\n"; Indentation indent(s); s << "return dynamic_cast< ::" << metaClass->qualifiedCppName() << " *>(reinterpret_cast< ::"<< ancestor->qualifiedCppName() << " *>(cptr));\n"; diff --git a/sources/shiboken6/generator/shiboken/headergenerator.cpp b/sources/shiboken6/generator/shiboken/headergenerator.cpp index 2b9074fd8..0f3dd9fba 100644 --- a/sources/shiboken6/generator/shiboken/headergenerator.cpp +++ b/sources/shiboken6/generator/shiboken/headergenerator.cpp @@ -709,5 +709,5 @@ void HeaderGenerator::writeSbkTypeFunction(TextStream &s, const AbstractMetaClas void HeaderGenerator::writeSbkTypeFunction(TextStream &s, const AbstractMetaType &metaType) { s << "template<> inline PyTypeObject *SbkType< ::" << metaType.cppSignature() << " >() " - << "{ return reinterpret_cast<PyTypeObject *>(" << cpythonTypeNameExt(metaType) << "); }\n"; + << "{ return " << cpythonTypeNameExt(metaType) << "; }\n"; } diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp index 1ddbba48e..16d4107d8 100644 --- a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp +++ b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp @@ -782,7 +782,7 @@ QString ShibokenGenerator::converterObject(const TypeEntry *type) return QString::fromLatin1("Shiboken::Conversions::PrimitiveTypeConverter<%1>()") .arg(type->qualifiedCppName()); if (type->isWrapperType()) - return QString::fromLatin1("PepType_SOTP(reinterpret_cast<SbkObjectType *>(%1))->converter") + return QString::fromLatin1("PepType_SOTP(reinterpret_cast<PyTypeObject *>(%1))->converter") .arg(cpythonTypeNameExt(type)); if (type->isEnum()) return QString::fromLatin1("PepType_SETP(reinterpret_cast<SbkEnumType *>(%1))->converter") @@ -1026,9 +1026,9 @@ QString ShibokenGenerator::cpythonCheckFunction(AbstractMetaType metaType, if (type.isPointerToWrapperType()) { typeCheck += u"checkSequenceTypes("_qs + cpythonTypeNameExt(type) + u", "_qs; } else if (type.isWrapperType()) { - typeCheck += QLatin1String("convertibleSequenceTypes(reinterpret_cast<SbkObjectType *>("); + typeCheck += QLatin1String("convertibleSequenceTypes("); typeCheck += cpythonTypeNameExt(type); - typeCheck += QLatin1String("), "); + typeCheck += QLatin1String(", "); } else { typeCheck += u"convertibleSequenceTypes("_qs + converterObject(type) + u", "_qs; @@ -1139,8 +1139,8 @@ QString ShibokenGenerator::cpythonIsConvertibleFunction(const TypeEntry *type) result += isValue ? QLatin1String("isPythonToCppValueConvertible") : QLatin1String("isPythonToCppPointerConvertible"); - result += QLatin1String("(reinterpret_cast<SbkObjectType *>(") - + cpythonTypeNameExt(type) + QLatin1String("), "); + result += QLatin1String("(") + + cpythonTypeNameExt(type) + QLatin1String(", "); return result; } return QString::fromLatin1("Shiboken::Conversions::isPythonToCppConvertible(%1, ") @@ -1164,8 +1164,7 @@ QString ShibokenGenerator::cpythonIsConvertibleFunction(AbstractMetaType metaTyp result += QLatin1String("isPythonToCppReferenceConvertible"); else result += QLatin1String("isPythonToCppValueConvertible"); - result += QLatin1String("(reinterpret_cast<SbkObjectType *>(") - + cpythonTypeNameExt(metaType) + QLatin1String("), "); + result += u'(' + cpythonTypeNameExt(metaType) + u", "_qs; return result; } result += QLatin1String("isPythonToCppConvertible(") + converterObject(metaType); @@ -1189,8 +1188,8 @@ QString ShibokenGenerator::cpythonIsConvertibleFunction(const AbstractMetaArgume QString ShibokenGenerator::cpythonToCppConversionFunction(const AbstractMetaClass *metaClass) { - return QLatin1String("Shiboken::Conversions::pythonToCppPointer(reinterpret_cast<SbkObjectType *>(") - + cpythonTypeNameExt(metaClass->typeEntry()) + QLatin1String("), "); + return QLatin1String("Shiboken::Conversions::pythonToCppPointer(") + + cpythonTypeNameExt(metaClass->typeEntry()) + QLatin1String(", "); } QString ShibokenGenerator::cpythonToCppConversionFunction(const AbstractMetaType &type, @@ -1199,8 +1198,7 @@ QString ShibokenGenerator::cpythonToCppConversionFunction(const AbstractMetaType if (type.isWrapperType()) { return QLatin1String("Shiboken::Conversions::pythonToCpp") + (type.isPointer() ? QLatin1String("Pointer") : QLatin1String("Copy")) - + QLatin1String("(reinterpret_cast<SbkObjectType *>(") - + cpythonTypeNameExt(type) + QLatin1String("), "); + + u'(' + cpythonTypeNameExt(type) + QLatin1String(", "); } return QStringLiteral("Shiboken::Conversions::pythonToCppCopy(%1, ") .arg(converterObject(type)); @@ -1220,8 +1218,8 @@ QString ShibokenGenerator::cpythonToPythonConversionFunction(const AbstractMetaT conversion = QLatin1String("pointer"); } QString result = QLatin1String("Shiboken::Conversions::") + conversion - + QLatin1String("ToPython(reinterpret_cast<SbkObjectType *>(") - + cpythonTypeNameExt(type) + QLatin1String("), "); + + QLatin1String("ToPython(") + + cpythonTypeNameExt(type) + QLatin1String(", "); if (conversion != QLatin1String("pointer")) result += QLatin1Char('&'); return result; @@ -1241,8 +1239,8 @@ QString ShibokenGenerator::cpythonToPythonConversionFunction(const TypeEntry *ty if (type->isWrapperType()) { const QString conversion = type->isValue() ? QLatin1String("copy") : QLatin1String("pointer"); QString result = QLatin1String("Shiboken::Conversions::") + conversion - + QLatin1String("ToPython(reinterpret_cast<SbkObjectType *>(") + cpythonTypeNameExt(type) - + QLatin1String("), "); + + QLatin1String("ToPython(") + cpythonTypeNameExt(type) + + QLatin1String(", "); if (conversion != QLatin1String("pointer")) result += QLatin1Char('&'); return result; @@ -1517,7 +1515,7 @@ void ShibokenGenerator::processClassCodeSnip(QString &code, const GeneratorConte // Replace template variable by the Python Type object // for the class context in which the variable is used. code.replace(QLatin1String("%PYTHONTYPEOBJECT"), - cpythonTypeName(metaClass) + QLatin1String("->type")); + u"(*"_qs + cpythonTypeName(metaClass) + u')'); const QString className = context.useWrapper() ? context.wrapperName() : metaClass->qualifiedCppName(); code.replace(QLatin1String("%TYPE"), className); @@ -1754,7 +1752,7 @@ void ShibokenGenerator::writeCodeSnips(TextStream &s, // class implementing the method in which the code snip is written if (func->isStatic()) { code.replace(QLatin1String("%PYTHONTYPEOBJECT"), - cpythonTypeName(func->implementingClass()) + QLatin1String("->type")); + u"(*"_qs + cpythonTypeName(func->implementingClass()) + u')'); } else { code.replace(QLatin1String("%PYTHONTYPEOBJECT."), pySelf + QLatin1String("->ob_type->")); code.replace(QLatin1String("%PYTHONTYPEOBJECT"), pySelf + QLatin1String("->ob_type")); diff --git a/sources/shiboken6/libshiboken/basewrapper.cpp b/sources/shiboken6/libshiboken/basewrapper.cpp index 809f4c25d..4ee2eda23 100644 --- a/sources/shiboken6/libshiboken/basewrapper.cpp +++ b/sources/shiboken6/libshiboken/basewrapper.cpp @@ -259,7 +259,7 @@ SbkObjectType *SbkObject_TypeF(void) type->tp_weaklistoffset = offsetof(SbkObject, weakreflist); type->tp_dictoffset = offsetof(SbkObject, ob_dict); } - return reinterpret_cast<SbkObjectType *>(type); + return type; } static int mainThreadDeletionHandler(void *) @@ -273,7 +273,6 @@ static void SbkDeallocWrapperCommon(PyObject *pyObj, bool canDelete) { auto *sbkObj = reinterpret_cast<SbkObject *>(pyObj); PyTypeObject *pyType = Py_TYPE(pyObj); - auto *sbkType = reinterpret_cast<SbkObjectType *>(pyType); // Need to decref the type if this is the dealloc func; if type // is subclassed, that dealloc func will decref (see subtype_dealloc @@ -319,7 +318,7 @@ static void SbkDeallocWrapperCommon(PyObject *pyObj, bool canDelete) PyObject_ClearWeakRefs(pyObj); // If I have ownership and is valid delete C++ pointer - auto *sotp = PepType_SOTP(sbkType); + auto *sotp = PepType_SOTP(pyType); canDelete &= sbkObj->d->hasOwnership && sbkObj->d->validCppObject; if (canDelete) { if (sotp->delete_in_main_thread && Shiboken::currentThreadId() != Shiboken::mainThreadId()) { @@ -391,11 +390,10 @@ void SbkDeallocWrapperWithPrivateDtor(PyObject *self) SbkDeallocWrapperCommon(self, false); } -void SbkObjectTypeDealloc(PyTypeObject *type) +void SbkObjectTypeDealloc(PyTypeObject *sbkType) { - SbkObjectType *sbkType = reinterpret_cast<SbkObjectType *>(type); SbkObjectTypePrivate *sotp = PepType_SOTP(sbkType); - auto pyObj = reinterpret_cast<PyObject *>(type); + auto pyObj = reinterpret_cast<PyObject *>(sbkType); PyObject_GC_UnTrack(pyObj); #ifndef Py_LIMITED_API @@ -408,7 +406,7 @@ void SbkObjectTypeDealloc(PyTypeObject *type) } free(sotp->original_name); sotp->original_name = nullptr; - if (!Shiboken::ObjectType::isUserType(type)) + if (!Shiboken::ObjectType::isUserType(sbkType)) Shiboken::Conversions::deleteConverter(sotp->converter); PepType_SOTP_delete(sbkType); } @@ -505,7 +503,7 @@ static PyObject *SbkObjectTypeTpNew(PyTypeObject *metatype, PyObject *args, PyOb PyObject_GetAttr(reinterpret_cast<PyObject *>(&PyType_Type), Shiboken::PyName::mro())); auto hold = PyMethodDescr_TypePtr->tp_flags; PyMethodDescr_TypePtr->tp_flags &= ~Py_TPFLAGS_METHOD_DESCRIPTOR; - auto *newType = reinterpret_cast<SbkObjectType *>(type_new(metatype, args, kwds)); + auto *newType = reinterpret_cast<PyTypeObject *>(type_new(metatype, args, kwds)); PyMethodDescr_TypePtr->tp_flags = hold; if (!newType) @@ -513,7 +511,7 @@ static PyObject *SbkObjectTypeTpNew(PyTypeObject *metatype, PyObject *args, PyOb SbkObjectTypePrivate *sotp = PepType_SOTP(newType); - const auto bases = Shiboken::getCppBaseClasses(&newType->type); + const auto bases = Shiboken::getCppBaseClasses(newType); if (bases.size() == 1) { SbkObjectTypePrivate *parentType = PepType_SOTP(bases.front()); sotp->mi_offsets = parentType->mi_offsets; @@ -558,7 +556,7 @@ static PyObject *SbkObjectTypeTpNew(PyTypeObject *metatype, PyObject *args, PyOb static PyObject *_setupNew(SbkObject *self, PyTypeObject *subtype) { auto *obSubtype = reinterpret_cast<PyObject *>(subtype); - auto *sbkSubtype = reinterpret_cast<SbkObjectType *>(subtype); + auto *sbkSubtype = subtype; auto *obSelf = reinterpret_cast<PyObject *>(self); Py_INCREF(obSubtype); @@ -712,9 +710,8 @@ bool walkThroughClassHierarchy(PyTypeObject *currentType, HierarchyVisitor *visi for (int i = 0; !result && i < numBases; ++i) { auto type = reinterpret_cast<PyTypeObject *>(PyTuple_GET_ITEM(bases, i)); if (PyType_IsSubtype(type, reinterpret_cast<PyTypeObject *>(SbkObject_TypeF()))) { - auto sbkType = reinterpret_cast<SbkObjectType *>(type); - result = PepType_SOTP(sbkType)->is_user_type - ? walkThroughClassHierarchy(type, visitor) : visitor->visit(sbkType); + result = PepType_SOTP(type)->is_user_type + ? walkThroughClassHierarchy(type, visitor) : visitor->visit(type); } } return result; @@ -740,7 +737,7 @@ bool BaseAccumulatorVisitor::visit(SbkObjectType *node) bool GetIndexVisitor::visit(SbkObjectType *node) { m_index++; - return PyType_IsSubtype(reinterpret_cast<PyTypeObject *>(node), m_desiredType); + return PyType_IsSubtype(node, m_desiredType); } bool DtorAccumulatorVisitor::visit(SbkObjectType *node) @@ -774,7 +771,7 @@ void init() if (PyType_Ready(SbkObjectType_TypeF()) < 0) Py_FatalError("[libshiboken] Failed to initialize Shiboken.BaseWrapperType metatype."); - if (PyType_Ready(reinterpret_cast<PyTypeObject *>(SbkObject_TypeF())) < 0) + if (PyType_Ready(SbkObject_TypeF()) < 0) Py_FatalError("[libshiboken] Failed to initialize Shiboken.BaseWrapper type."); VoidPtr::init(); @@ -785,7 +782,7 @@ void init() // PYSIDE-1415: Publish Shiboken objects. void initSignature(PyObject *module) { - auto type = reinterpret_cast<PyTypeObject *>(SbkObject_TypeF()); + auto *type = SbkObject_TypeF(); if (InitSignatureStrings(type, SbkObject_SignatureStrings) < 0) return; @@ -807,7 +804,7 @@ public: bool visit(SbkObjectType *node) override { - return reinterpret_cast<PyTypeObject *>(node) == m_typeToFind; + return node == m_typeToFind; } private: @@ -844,13 +841,12 @@ namespace ObjectType bool checkType(PyTypeObject *type) { - return PyType_IsSubtype(type, reinterpret_cast<PyTypeObject *>(SbkObject_TypeF())) != 0; + return PyType_IsSubtype(type, SbkObject_TypeF()) != 0; } bool isUserType(PyTypeObject *type) { - auto *objType = reinterpret_cast<SbkObjectType *>(type); - return checkType(type) && PepType_SOTP(objType)->is_user_type; + return checkType(type) && PepType_SOTP(type)->is_user_type; } bool canCallConstructor(PyTypeObject *myType, PyTypeObject *ctorType) @@ -871,8 +867,7 @@ bool hasCast(SbkObjectType *type) void *cast(SbkObjectType *sourceType, SbkObject *obj, PyTypeObject *pyTargetType) { auto *sotp = PepType_SOTP(sourceType); - auto *targetType = reinterpret_cast<SbkObjectType *>(pyTargetType); - return sotp->mi_specialcast(Object::cppPointer(obj, pyTargetType), targetType); + return sotp->mi_specialcast(Object::cppPointer(obj, pyTargetType), pyTargetType); } void setCastFunction(SbkObjectType *type, SpecialCastFunction func) @@ -938,16 +933,18 @@ introduceWrapperType(PyObject *enclosingObject, PyObject *heaptype = SbkType_FromSpecWithBases(typeSpec, baseTypes); Py_TYPE(heaptype) = SbkObjectType_TypeF(); Py_INCREF(Py_TYPE(heaptype)); - auto *type = reinterpret_cast<SbkObjectType *>(heaptype); + auto *type = reinterpret_cast<PyTypeObject *>(heaptype); if (baseType) { if (baseTypes) { - for (int i = 0; i < PySequence_Fast_GET_SIZE(baseTypes); ++i) - BindingManager::instance().addClassInheritance(reinterpret_cast<SbkObjectType *>(PySequence_Fast_GET_ITEM(baseTypes, i)), type); + for (int i = 0; i < PySequence_Fast_GET_SIZE(baseTypes); ++i) { + auto *st = reinterpret_cast<PyTypeObject *>(PySequence_Fast_GET_ITEM(baseTypes, i)); + BindingManager::instance().addClassInheritance(st, type); + } } else { BindingManager::instance().addClassInheritance(baseType, type); } } - if (PyType_Ready(reinterpret_cast<PyTypeObject *>(type)) < 0) + if (PyType_Ready(type) < 0) return nullptr; auto sotp = PepType_SOTP(type); @@ -995,7 +992,7 @@ SbkObjectType *typeForTypeName(const char *typeName) SbkObjectType *result{}; if (typeName) { if (PyTypeObject *pyType = Shiboken::Conversions::getPythonTypeObject(typeName)) - result = reinterpret_cast<SbkObjectType *>(pyType); + result = pyType; } return result; } @@ -1092,8 +1089,7 @@ void callCppDestructors(SbkObject *pyObj) return; } PyTypeObject *type = Py_TYPE(pyObj); - auto *sbkType = reinterpret_cast<SbkObjectType *>(type); - auto *sotp = PepType_SOTP(sbkType); + auto *sotp = PepType_SOTP(type); if (sotp->is_multicpp) { Shiboken::DtorAccumulatorVisitor visitor(pyObj); Shiboken::walkThroughClassHierarchy(type, &visitor); @@ -1152,7 +1148,7 @@ void getOwnership(PyObject *pyObj) void releaseOwnership(SbkObject *self) { // skip if the ownership have already moved to c++ - auto *selfType = reinterpret_cast<SbkObjectType *>(Py_TYPE(self)); + auto *selfType = Py_TYPE(self); if (!self->d->hasOwnership || Shiboken::Conversions::pythonTypeIsValueType(PepType_SOTP(selfType)->converter)) return; @@ -1258,8 +1254,7 @@ void makeValid(SbkObject *self) void *cppPointer(SbkObject *pyObj, PyTypeObject *desiredType) { PyTypeObject *pyType = Py_TYPE(pyObj); - auto *type = reinterpret_cast<SbkObjectType *>(pyType); - auto *sotp = PepType_SOTP(type); + auto *sotp = PepType_SOTP(pyType); int idx = 0; if (sotp->is_multicpp) idx = getTypeIndexOnHierarchy(pyType, desiredType); @@ -1281,9 +1276,8 @@ std::vector<void *> cppPointers(SbkObject *pyObj) bool setCppPointer(SbkObject *sbkObj, PyTypeObject *desiredType, void *cptr) { PyTypeObject *type = Py_TYPE(sbkObj); - auto *sbkType = reinterpret_cast<SbkObjectType *>(type); int idx = 0; - if (PepType_SOTP(sbkType)->is_multicpp) + if (PepType_SOTP(type)->is_multicpp) idx = getTypeIndexOnHierarchy(type, desiredType); const bool alreadyInitialized = sbkObj->d->cptr[idx] != nullptr; @@ -1346,7 +1340,7 @@ bool isValid(SbkObject *pyObj, bool throwPyError) bool isValid(PyObject *pyObj, bool throwPyError) { if (!pyObj || pyObj == Py_None || - !PyType_IsSubtype(Py_TYPE(pyObj), reinterpret_cast<PyTypeObject *>(SbkObject_TypeF()))) { + !PyType_IsSubtype(Py_TYPE(pyObj), SbkObject_TypeF())) { return true; } return isValid(reinterpret_cast<SbkObject *>(pyObj), throwPyError); @@ -1422,7 +1416,7 @@ PyObject *newObject(SbkObjectType *instanceType, } if (shouldCreate) { - self = reinterpret_cast<SbkObject *>(SbkObjectTpNew(reinterpret_cast<PyTypeObject *>(instanceType), nullptr, nullptr)); + self = reinterpret_cast<SbkObject *>(SbkObjectTpNew(instanceType, nullptr, nullptr)); self->d->cptr[0] = cptr; self->d->hasOwnership = hasOwnership; self->d->validCppObject = 1; @@ -1607,8 +1601,7 @@ void deallocData(SbkObject *self, bool cleanup) void setTypeUserData(SbkObject *wrapper, void *userData, DeleteUserDataFunc d_func) { auto *type = Py_TYPE(wrapper); - auto *sbkType = reinterpret_cast<SbkObjectType *>(type); - auto *sotp = PepType_SOTP(sbkType); + auto *sotp = PepType_SOTP(type); if (sotp->user_data) sotp->d_func(sotp->user_data); @@ -1619,8 +1612,7 @@ void setTypeUserData(SbkObject *wrapper, void *userData, DeleteUserDataFunc d_fu void *getTypeUserData(SbkObject *wrapper) { auto *type = Py_TYPE(wrapper); - auto *sbkType = reinterpret_cast<SbkObjectType *>(type); - return PepType_SOTP(sbkType)->user_data; + return PepType_SOTP(type)->user_data; } static inline bool isNone(const PyObject *o) @@ -1695,13 +1687,11 @@ std::string info(SbkObject *self) if (ObjectType::isUserType(Py_TYPE(self))) bases = getCppBaseClasses(Py_TYPE(self)); else - bases.push_back(reinterpret_cast<SbkObjectType *>(Py_TYPE(self))); + bases.push_back(Py_TYPE(self)); s << "C++ address....... "; - for (size_t i = 0, size = bases.size(); i < size; ++i) { - auto base = reinterpret_cast<PyTypeObject *>(bases[i]); - s << base->tp_name << '/' << self->d->cptr[i] << ' '; - } + for (size_t i = 0, size = bases.size(); i < size; ++i) + s << bases[i]->tp_name << '/' << self->d->cptr[i] << ' '; s << "\n"; } else { diff --git a/sources/shiboken6/libshiboken/basewrapper.h b/sources/shiboken6/libshiboken/basewrapper.h index 2406d5288..9e2183ec8 100644 --- a/sources/shiboken6/libshiboken/basewrapper.h +++ b/sources/shiboken6/libshiboken/basewrapper.h @@ -72,8 +72,6 @@ LIBSHIBOKEN_API void SbkDeallocWrapper(PyObject *pyObj); LIBSHIBOKEN_API void SbkDeallocQAppWrapper(PyObject *pyObj); LIBSHIBOKEN_API void SbkDeallocWrapperWithPrivateDtor(PyObject *self); -struct SbkObjectType; - /// Function signature for the multiple inheritance information initializers that should be provided by classes with multiple inheritance. typedef int *(*MultipleInheritanceInitFunction)(const void *); @@ -119,10 +117,6 @@ extern LIBSHIBOKEN_API SbkObjectType *SbkObject_TypeF(void); struct SbkObjectTypePrivate; /// PyTypeObject extended with C++ multiple inheritance information. -struct LIBSHIBOKEN_API SbkObjectType -{ - PyTypeObject type; -}; LIBSHIBOKEN_API PyObject *SbkObjectTpNew(PyTypeObject *subtype, PyObject *, PyObject *); diff --git a/sources/shiboken6/libshiboken/basewrapper_p.h b/sources/shiboken6/libshiboken/basewrapper_p.h index 478a7d52e..c565e32c5 100644 --- a/sources/shiboken6/libshiboken/basewrapper_p.h +++ b/sources/shiboken6/libshiboken/basewrapper_p.h @@ -49,7 +49,6 @@ #include <vector> struct SbkObject; -struct SbkObjectType; struct SbkConverter; namespace Shiboken diff --git a/sources/shiboken6/libshiboken/bindingmanager.cpp b/sources/shiboken6/libshiboken/bindingmanager.cpp index 37ef39a15..13b33942b 100644 --- a/sources/shiboken6/libshiboken/bindingmanager.cpp +++ b/sources/shiboken6/libshiboken/bindingmanager.cpp @@ -79,10 +79,10 @@ public: file << "digraph D {\n"; for (auto i = m_edges.begin(), end = m_edges.end(); i != end; ++i) { - auto node1 = reinterpret_cast<const PyTypeObject *>(i->first); + auto *node1 = i->first; const NodeList &nodeList = i->second; for (const SbkObjectType *o : nodeList) { - auto node2 = reinterpret_cast<const PyTypeObject *>(o); + auto *node2 = o; file << '"' << node2->tp_name << "\" -> \"" << node1->tp_name << "\"\n"; } @@ -213,7 +213,7 @@ bool BindingManager::hasWrapper(const void *cptr) void BindingManager::registerWrapper(SbkObject *pyObj, void *cptr) { - auto *instanceType = reinterpret_cast<SbkObjectType *>(Py_TYPE(pyObj)); + auto *instanceType = Py_TYPE(pyObj); auto *d = PepType_SOTP(instanceType); if (!d) @@ -234,7 +234,7 @@ void BindingManager::registerWrapper(SbkObject *pyObj, void *cptr) void BindingManager::releaseWrapper(SbkObject *sbkObj) { - auto *sbkType = reinterpret_cast<SbkObjectType *>(Py_TYPE(sbkObj)); + auto *sbkType = Py_TYPE(sbkObj); auto *d = PepType_SOTP(sbkType); int numBases = ((d && d->is_multicpp) ? getNumberOfCppBaseClasses(Py_TYPE(sbkObj)) : 1); diff --git a/sources/shiboken6/libshiboken/bindingmanager.h b/sources/shiboken6/libshiboken/bindingmanager.h index 5b2246685..ab0ad79de 100644 --- a/sources/shiboken6/libshiboken/bindingmanager.h +++ b/sources/shiboken6/libshiboken/bindingmanager.h @@ -45,7 +45,6 @@ #include "shibokenmacros.h" struct SbkObject; -struct SbkObjectType; namespace Shiboken { diff --git a/sources/shiboken6/libshiboken/pep384impl.h b/sources/shiboken6/libshiboken/pep384impl.h index d326141d6..cd62fbdc6 100644 --- a/sources/shiboken6/libshiboken/pep384impl.h +++ b/sources/shiboken6/libshiboken/pep384impl.h @@ -161,11 +161,10 @@ LIBSHIBOKEN_API PyObject *_PepType_Lookup(PyTypeObject *type, PyObject *name); * */ -struct SbkObjectType; struct SbkObjectTypePrivate; -LIBSHIBOKEN_API SbkObjectTypePrivate *PepType_SOTP(SbkObjectType *type); -LIBSHIBOKEN_API void PepType_SOTP_delete(SbkObjectType *type); +LIBSHIBOKEN_API SbkObjectTypePrivate *PepType_SOTP(PyTypeObject *type); +LIBSHIBOKEN_API void PepType_SOTP_delete(PyTypeObject *type); struct SbkEnumType; struct SbkEnumTypePrivate; diff --git a/sources/shiboken6/libshiboken/sbkconverter.cpp b/sources/shiboken6/libshiboken/sbkconverter.cpp index 87b4bda63..983a1deb5 100644 --- a/sources/shiboken6/libshiboken/sbkconverter.cpp +++ b/sources/shiboken6/libshiboken/sbkconverter.cpp @@ -134,7 +134,7 @@ SbkConverter *createConverter(SbkObjectType *type, CppToPythonFunc copyToPythonFunc) { SbkConverter *converter = - createConverterObject(reinterpret_cast<PyTypeObject *>(type), + createConverterObject(type, toCppPointerConvFunc, toCppPointerCheckFunc, pointerToPythonFunc, copyToPythonFunc); PepType_SOTP(type)->converter = converter; @@ -306,7 +306,7 @@ void *cppPointer(PyTypeObject *desiredType, SbkObject *pyIn) assert(pyIn); if (!ObjectType::checkType(desiredType)) return pyIn; - auto *inType = reinterpret_cast<SbkObjectType *>(Py_TYPE(pyIn)); + auto *inType = Py_TYPE(pyIn); if (ObjectType::hasCast(inType)) return ObjectType::cast(inType, pyIn, desiredType); return Object::cppPointer(pyIn, desiredType); @@ -319,7 +319,7 @@ void pythonToCppPointer(SbkObjectType *type, PyObject *pyIn, void *cppOut) assert(cppOut); *reinterpret_cast<void **>(cppOut) = pyIn == Py_None ? nullptr - : cppPointer(reinterpret_cast<PyTypeObject *>(type), reinterpret_cast<SbkObject *>(pyIn)); + : cppPointer(type, reinterpret_cast<SbkObject *>(pyIn)); } void pythonToCppPointer(const SbkConverter *converter, PyObject *pyIn, void *cppOut) @@ -329,7 +329,7 @@ void pythonToCppPointer(const SbkConverter *converter, PyObject *pyIn, void *cpp assert(cppOut); *reinterpret_cast<void **>(cppOut) = pyIn == Py_None ? nullptr - : cppPointer(reinterpret_cast<PyTypeObject *>(converter->pythonType), reinterpret_cast<SbkObject *>(pyIn)); + : cppPointer(converter->pythonType, reinterpret_cast<SbkObject *>(pyIn)); } static void _pythonToCppCopy(const SbkConverter *converter, PyObject *pyIn, void *cppOut) diff --git a/sources/shiboken6/libshiboken/sbkconverter.h b/sources/shiboken6/libshiboken/sbkconverter.h index 5bf006738..43f0643b4 100644 --- a/sources/shiboken6/libshiboken/sbkconverter.h +++ b/sources/shiboken6/libshiboken/sbkconverter.h @@ -50,7 +50,6 @@ #include <string> struct SbkObject; -struct SbkObjectType; /** * This is a convenience macro identical to Python's PyObject_TypeCheck, diff --git a/sources/shiboken6/libshiboken/sbkenum.cpp b/sources/shiboken6/libshiboken/sbkenum.cpp index 648254b4d..3789fe298 100644 --- a/sources/shiboken6/libshiboken/sbkenum.cpp +++ b/sources/shiboken6/libshiboken/sbkenum.cpp @@ -494,12 +494,12 @@ PyTypeObject *createGlobalEnum(PyObject *module, const char *name, const char *f PyTypeObject *createScopedEnum(SbkObjectType *scope, const char *name, const char *fullName, const char *cppName, PyTypeObject *flagsType) { PyTypeObject *enumType = createEnum(fullName, cppName, flagsType); - if (enumType && PyDict_SetItemString(reinterpret_cast<PyTypeObject *>(scope)->tp_dict, name, + if (enumType && PyDict_SetItemString(scope->tp_dict, name, reinterpret_cast<PyObject *>(enumType)) < 0) { Py_DECREF(enumType); return nullptr; } - if (flagsType && PyDict_SetItemString(reinterpret_cast<PyTypeObject *>(scope)->tp_dict, + if (flagsType && PyDict_SetItemString(scope->tp_dict, PepType_GetNameStr(flagsType), reinterpret_cast<PyObject *>(flagsType)) < 0) { Py_DECREF(enumType); @@ -534,16 +534,11 @@ bool createScopedEnumItem(PyTypeObject *enumType, PyTypeObject *scope, PyObject *enumItem = createEnumItem(enumType, itemName, itemValue); if (!enumItem) return false; - int ok = PyDict_SetItemString(reinterpret_cast<PyTypeObject *>(scope)->tp_dict, itemName, enumItem); + int ok = PyDict_SetItemString(scope->tp_dict, itemName, enumItem); Py_DECREF(enumItem); return ok >= 0; } -bool createScopedEnumItem(PyTypeObject *enumType, SbkObjectType *scope, const char *itemName, long itemValue) -{ - return createScopedEnumItem(enumType, reinterpret_cast<PyTypeObject *>(scope), itemName, itemValue); -} - PyObject * newItem(PyTypeObject *enumType, long itemValue, const char *itemName) { diff --git a/sources/shiboken6/libshiboken/sbkenum.h b/sources/shiboken6/libshiboken/sbkenum.h index fd0fcb904..f97997ae0 100644 --- a/sources/shiboken6/libshiboken/sbkenum.h +++ b/sources/shiboken6/libshiboken/sbkenum.h @@ -50,7 +50,6 @@ extern "C" LIBSHIBOKEN_API void init_enum(); extern LIBSHIBOKEN_API PyTypeObject *SbkEnumType_TypeF(void); -struct SbkObjectType; struct SbkConverter; struct SbkEnumType; struct SbkEnumTypePrivate; @@ -102,7 +101,6 @@ namespace Enum /// This function does the same as createGlobalEnumItem, but adds the enum to a Shiboken type or namespace. LIBSHIBOKEN_API bool createScopedEnumItem(PyTypeObject *enumType, PyTypeObject *scope, const char *itemName, long itemValue); - LIBSHIBOKEN_API bool createScopedEnumItem(PyTypeObject *enumType, SbkObjectType *scope, const char *itemName, long itemValue); LIBSHIBOKEN_API PyObject *newItem(PyTypeObject *enumType, long itemValue, const char *itemName = nullptr); diff --git a/sources/shiboken6/libshiboken/sbkfeature_base.cpp b/sources/shiboken6/libshiboken/sbkfeature_base.cpp index e015ac0c8..6b2037ecd 100644 --- a/sources/shiboken6/libshiboken/sbkfeature_base.cpp +++ b/sources/shiboken6/libshiboken/sbkfeature_base.cpp @@ -162,26 +162,22 @@ int SbkObject_GenericSetAttr(PyObject *obj, PyObject *name, PyObject *value) // Caching the select Id. int SbkObjectType_GetReserved(PyTypeObject *type) { - auto *sbkType = reinterpret_cast<SbkObjectType *>(type); - return PepType_SOTP(sbkType)->pyside_reserved_bits; + return PepType_SOTP(type)->pyside_reserved_bits; } void SbkObjectType_SetReserved(PyTypeObject *type, int value) { - auto *sbkType = reinterpret_cast<SbkObjectType *>(type); - PepType_SOTP(sbkType)->pyside_reserved_bits = value; + PepType_SOTP(type)->pyside_reserved_bits = value; } const char **SbkObjectType_GetPropertyStrings(PyTypeObject *type) { - auto *sbkType = reinterpret_cast<SbkObjectType *>(type); - return PepType_SOTP(sbkType)->propertyStrings; + return PepType_SOTP(type)->propertyStrings; } void SbkObjectType_SetPropertyStrings(PyTypeObject *type, const char **strings) { - auto *sbkType = reinterpret_cast<SbkObjectType *>(type); - PepType_SOTP(sbkType)->propertyStrings = strings; + PepType_SOTP(type)->propertyStrings = strings; } // PYSIDE-1626: Enforcing a context switch without further action. diff --git a/sources/shiboken6/libshiboken/sbkpython.h b/sources/shiboken6/libshiboken/sbkpython.h index 60997814f..d74918b62 100644 --- a/sources/shiboken6/libshiboken/sbkpython.h +++ b/sources/shiboken6/libshiboken/sbkpython.h @@ -107,4 +107,6 @@ extern "C" { #undef Py_TPFLAGS_HAVE_VERSION_TAG #define Py_TPFLAGS_HAVE_VERSION_TAG (0) +using SbkObjectType = PyTypeObject; // FIXME PYSIDE 7 remove + #endif diff --git a/sources/shiboken6/libshiboken/voidptr.cpp b/sources/shiboken6/libshiboken/voidptr.cpp index 6a69c39fd..a7eeb359c 100644 --- a/sources/shiboken6/libshiboken/voidptr.cpp +++ b/sources/shiboken6/libshiboken/voidptr.cpp @@ -332,7 +332,7 @@ static int voidPointerInitialized = false; void init() { - if (PyType_Ready(reinterpret_cast<PyTypeObject *>(SbkVoidPtrTypeF())) < 0) + if (PyType_Ready(SbkVoidPtrTypeF()) < 0) Py_FatalError("[libshiboken] Failed to initialize Shiboken.VoidPtr type."); else voidPointerInitialized = true; |