aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/libpyside/pysidesignal.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/pyside6/libpyside/pysidesignal.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/pyside6/libpyside/pysidesignal.cpp')
-rw-r--r--sources/pyside6/libpyside/pysidesignal.cpp37
1 files changed, 17 insertions, 20 deletions
diff --git a/sources/pyside6/libpyside/pysidesignal.cpp b/sources/pyside6/libpyside/pysidesignal.cpp
index 383f1a64e..2a8635666 100644
--- a/sources/pyside6/libpyside/pysidesignal.cpp
+++ b/sources/pyside6/libpyside/pysidesignal.cpp
@@ -759,36 +759,33 @@ void updateSourceObject(PyObject *source)
Py_XDECREF(objType);
}
-QByteArray getTypeName(PyObject *type)
+QByteArray getTypeName(PyObject *obType)
{
- if (PyType_Check(type)) {
- if (PyType_IsSubtype(reinterpret_cast<PyTypeObject *>(type),
- reinterpret_cast<PyTypeObject *>(SbkObject_TypeF()))) {
- auto objType = reinterpret_cast<PyTypeObject *>(type);
- return Shiboken::ObjectType::getOriginalName(objType);
- }
- // Translate python types to Qt names
- auto objType = reinterpret_cast<PyTypeObject *>(type);
- if (Shiboken::String::checkType(objType))
+ if (PyType_Check(obType)) {
+ auto *type = reinterpret_cast<PyTypeObject *>(obType);
+ if (PyType_IsSubtype(type, SbkObject_TypeF()))
+ return Shiboken::ObjectType::getOriginalName(type);
+ // Translate Python types to Qt names
+ if (Shiboken::String::checkType(type))
return QByteArrayLiteral("QString");
- if (objType == &PyLong_Type)
+ if (type == &PyLong_Type)
return QByteArrayLiteral("int");
- if (objType == &PyLong_Type)
+ if (type == &PyLong_Type)
return QByteArrayLiteral("long");
- if (objType == &PyFloat_Type)
+ if (type == &PyFloat_Type)
return QByteArrayLiteral("double");
- if (objType == &PyBool_Type)
+ if (type == &PyBool_Type)
return QByteArrayLiteral("bool");
- if (objType == &PyList_Type)
+ if (type == &PyList_Type)
return QByteArrayLiteral("QVariantList");
- if (Py_TYPE(objType) == SbkEnumType_TypeF())
- return Shiboken::Enum::getCppName(objType);
+ if (Py_TYPE(type) == SbkEnumType_TypeF())
+ return Shiboken::Enum::getCppName(type);
return QByteArrayLiteral("PyObject");
}
- if (type == Py_None) // Must be checked before as Shiboken::String::check accepts Py_None
+ if (obType == Py_None) // Must be checked before as Shiboken::String::check accepts Py_None
return voidType();
- if (Shiboken::String::check(type)) {
- QByteArray result = Shiboken::String::toCString(type);
+ if (Shiboken::String::check(obType)) {
+ QByteArray result = Shiboken::String::toCString(obType);
if (result == "qreal")
result = sizeof(qreal) == sizeof(double) ? "double" : "float";
return result;