diff options
author | Christian Tismer <tismer@stackless.com> | 2018-07-19 21:00:30 +0200 |
---|---|---|
committer | Christian Tismer <tismer@stackless.com> | 2018-07-23 16:32:01 +0000 |
commit | e24392c76e5cfdd2d6d51bd853b106db2bc4cb80 (patch) | |
tree | 985048135d3a6a81da2f5a72b667ff59ed4d0b44 /sources/pyside2/PySide2 | |
parent | 5d21980ba4bd605ccbf4278e75177ae2c144bdd8 (diff) |
Pep 384 Final Cut: Remove PepType
While trying to document the Limited API Project,
it suddenly struck me:
We can make the patch much much simpler and implement it
without the necessity to have an extra PepType!
Now I am happy to continue the documentation, because
it is now no more improvable.
This version will last as long as the layout of
PyTypeObject does not change substantially. When that
happens, then we need to rewrite stuff with the according
PyType_GetSlot() access functions.
These access functions will until then be complete enough
so that we can live without the tricks like inventing a reduced
PyTypeObject as was done in the current implementation.
Task-number: PYSIDE-560
Change-Id: I49849cc377baa6794a5b53292691e21d6e2853ab
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'sources/pyside2/PySide2')
9 files changed, 35 insertions, 35 deletions
diff --git a/sources/pyside2/PySide2/QtCore/glue/qbytearray_mgetitem.cpp b/sources/pyside2/PySide2/QtCore/glue/qbytearray_mgetitem.cpp index f1d5a6bfc..9612f41b0 100644 --- a/sources/pyside2/PySide2/QtCore/glue/qbytearray_mgetitem.cpp +++ b/sources/pyside2/PySide2/QtCore/glue/qbytearray_mgetitem.cpp @@ -82,6 +82,6 @@ if (PyIndex_Check(_key)) { } else { PyErr_Format(PyExc_TypeError, "list indices must be integers or slices, not %.200s", - PepType((Py_TYPE(_key)))->tp_name); + Py_TYPE(_key)->tp_name); return NULL; } diff --git a/sources/pyside2/PySide2/QtCore/glue/qbytearray_msetitem.cpp b/sources/pyside2/PySide2/QtCore/glue/qbytearray_msetitem.cpp index 6745fc964..1349f40f1 100644 --- a/sources/pyside2/PySide2/QtCore/glue/qbytearray_msetitem.cpp +++ b/sources/pyside2/PySide2/QtCore/glue/qbytearray_msetitem.cpp @@ -67,7 +67,7 @@ if (PyIndex_Check(_key)) { PyErr_SetString(PyExc_ValueError, "bytearray must be of size 1"); return -1; } - } else if (PepType(Py_TYPE(_value)) == PepType(SbkPySide2_QtCoreTypes[SBK_QBYTEARRAY_IDX])) { + } else if (reinterpret_cast<PyTypeObject *>(Py_TYPE(_value)) == reinterpret_cast<PyTypeObject *>(SbkPySide2_QtCoreTypes[SBK_QBYTEARRAY_IDX])) { if (PyObject_Length(_value) != 1) { PyErr_SetString(PyExc_ValueError, "QByteArray must be of size 1"); return -1; @@ -109,15 +109,15 @@ if (PyIndex_Check(_key)) { if (_value == NULL || _value == Py_None) { ba = QByteArray(); value_length = 0; - } else if (!(PyBytes_Check(_value) || PyByteArray_Check(_value) || PepType(Py_TYPE(_value)) == PepType(SbkPySide2_QtCoreTypes[SBK_QBYTEARRAY_IDX]))) { - PyErr_Format(PyExc_TypeError, "bytes, bytearray or QByteArray is required, not %.200s", PepType(Py_TYPE(_value))->tp_name); + } else if (!(PyBytes_Check(_value) || PyByteArray_Check(_value) || reinterpret_cast<PyTypeObject *>(Py_TYPE(_value)) == reinterpret_cast<PyTypeObject *>(SbkPySide2_QtCoreTypes[SBK_QBYTEARRAY_IDX]))) { + PyErr_Format(PyExc_TypeError, "bytes, bytearray or QByteArray is required, not %.200s", Py_TYPE(_value)->tp_name); return -1; } else { value_length = PyObject_Length(_value); } if (step != 1 && value_length != slicelength) { - PyErr_Format(PyExc_ValueError, "attempt to assign %s of size %d to extended slice of size %d",PepType(Py_TYPE(_value))->tp_name, value_length, slicelength); + PyErr_Format(PyExc_ValueError, "attempt to assign %s of size %d to extended slice of size %d",Py_TYPE(_value)->tp_name, value_length, slicelength); return -1; } @@ -151,7 +151,7 @@ if (PyIndex_Check(_key)) { } } else { PyErr_Format(PyExc_TypeError, "QBytearray indices must be integers or slices, not %.200s", - PepType(Py_TYPE(_key))->tp_name); + Py_TYPE(_key)->tp_name); return -1; } diff --git a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml index cc63c0b7a..20cb508e8 100644 --- a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml +++ b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml @@ -461,16 +461,16 @@ // tp_base does not always point to the first base class, but rather to the first // that has added any python fields or slots to its object layout. // See https://mail.python.org/pipermail/python-list/2009-January/520733.html - if (PepType(type)->tp_bases) { - for (int i = 0; i < PyTuple_GET_SIZE(PepType(type)->tp_bases); ++i) { - const char *derivedName = QVariant_resolveMetaType((PyTypeObject*)PyTuple_GET_ITEM( - PepType(type)->tp_bases, i), typeId); + if (type->tp_bases) { + for (int i = 0; i < PyTuple_GET_SIZE(type->tp_bases); ++i) { + const char *derivedName = QVariant_resolveMetaType(reinterpret_cast<PyTypeObject *>(PyTuple_GET_ITEM( + type->tp_bases, i)), typeId); if (derivedName) return derivedName; } } - else if (PepType(type)->tp_base) { - return QVariant_resolveMetaType(PepType(type)->tp_base, typeId); + else if (type->tp_base) { + return QVariant_resolveMetaType(type->tp_base, typeId); } } *typeId = 0; @@ -592,7 +592,7 @@ </add-conversion> <add-conversion type="PyTypeObject"> const char *typeName; - if (Shiboken::String::checkType(reinterpret_cast<PyTypeObject*>(%in))) + if (Shiboken::String::checkType(reinterpret_cast<PyTypeObject *>(%in))) typeName = "QString"; else if (%in == reinterpret_cast<PyObject*>(&PyFloat_Type)) typeName = "double"; // float is a UserType in QVariant. @@ -601,7 +601,7 @@ else if (Py_TYPE(%in) == SbkObjectType_TypeF()) typeName = Shiboken::ObjectType::getOriginalName((SbkObjectType*)%in); else - typeName = PepType((reinterpret_cast<PyTypeObject*>(%in)))->tp_name; + typeName = reinterpret_cast<PyTypeObject *>(%in)->tp_name; %out = QVariant::nameToType(typeName); </add-conversion> <add-conversion type="PyString" check="Shiboken::String::check(%in)"> @@ -2687,7 +2687,7 @@ if (aux == NULL) { return NULL; } - QByteArray b(PepType(Py_TYPE(%PYSELF))->tp_name); + QByteArray b(Py_TYPE(%PYSELF)->tp_name); #ifdef IS_PY3K %PYARG_0 = PyUnicode_FromFormat("%s(%R)", b.constData(), aux); #else @@ -3241,8 +3241,8 @@ // %FUNCTION_NAME() - disable generation of c++ function call (void) %2; // remove warning about unused variable Shiboken::AutoDecRef emptyTuple(PyTuple_New(0)); - PyObject *pyTimer = PepType(Shiboken::SbkType<QTimer>())->tp_new(Shiboken::SbkType<QTimer>(), emptyTuple, 0); - PepType(Shiboken::SbkType<QTimer>())->tp_init(pyTimer, emptyTuple, 0); + PyObject *pyTimer = reinterpret_cast<PyTypeObject *>(Shiboken::SbkType<QTimer>())->tp_new(Shiboken::SbkType<QTimer>(), emptyTuple, 0); + reinterpret_cast<PyTypeObject *>(Shiboken::SbkType<QTimer>())->tp_init(pyTimer, emptyTuple, 0); QTimer* timer = %CONVERTTOCPP[QTimer*](pyTimer); Shiboken::AutoDecRef result( @@ -3265,8 +3265,8 @@ <inject-code class="target" position="beginning"> // %FUNCTION_NAME() - disable generation of c++ function call Shiboken::AutoDecRef emptyTuple(PyTuple_New(0)); - PyObject *pyTimer = PepType(Shiboken::SbkType<QTimer>())->tp_new(Shiboken::SbkType<QTimer>(), emptyTuple, 0); - PepType(Shiboken::SbkType<QTimer>())->tp_init(pyTimer, emptyTuple, 0); + PyObject *pyTimer = reinterpret_cast<PyTypeObject *>(Shiboken::SbkType<QTimer>())->tp_new(Shiboken::SbkType<QTimer>(), emptyTuple, 0); + reinterpret_cast<PyTypeObject *>(Shiboken::SbkType<QTimer>())->tp_init(pyTimer, emptyTuple, 0); QTimer* timer = %CONVERTTOCPP[QTimer*](pyTimer); timer->setSingleShot(true); diff --git a/sources/pyside2/PySide2/QtGui/typesystem_gui_common.xml b/sources/pyside2/PySide2/QtGui/typesystem_gui_common.xml index eee22b55c..7715cbe6c 100644 --- a/sources/pyside2/PySide2/QtGui/typesystem_gui_common.xml +++ b/sources/pyside2/PySide2/QtGui/typesystem_gui_common.xml @@ -1752,7 +1752,7 @@ PyErr_Format(PyExc_TypeError, "Invalid return value in function %s, expected %s, got %s.", "QValidator.validate", "PySide2.QtGui.QValidator.State, (PySide2.QtGui.QValidator.State,), (PySide2.QtGui.QValidator.State, unicode) or (PySide2.QtGui.QValidator.State, unicode, int)", - PepType((Py_TYPE(pyResult)))->tp_name); + Py_TYPE(pyResult)->tp_name); return QValidator::State(); } </template> diff --git a/sources/pyside2/PySide2/QtQml/pysideqmlregistertype.cpp b/sources/pyside2/PySide2/QtQml/pysideqmlregistertype.cpp index fa9eb6349..0b427c251 100644 --- a/sources/pyside2/PySide2/QtQml/pysideqmlregistertype.cpp +++ b/sources/pyside2/PySide2/QtQml/pysideqmlregistertype.cpp @@ -120,9 +120,9 @@ int PySide::qmlRegisterType(PyObject *pyObj, const char *uri, int versionMajor, } PyTypeObject *pyObjType = reinterpret_cast<PyTypeObject *>(pyObj); - if (!PySequence_Contains(PepType(pyObjType)->tp_mro, reinterpret_cast<PyObject *>(qobjectType))) { + if (!PySequence_Contains(pyObjType->tp_mro, reinterpret_cast<PyObject *>(qobjectType))) { PyErr_Format(PyExc_TypeError, "A type inherited from %s expected, got %s.", - PepType(qobjectType)->tp_name, PepType(pyObjType)->tp_name); + qobjectType->tp_name, pyObjType->tp_name); return -1; } @@ -229,7 +229,7 @@ void propListTpFree(void* self) PySideProperty* pySelf = reinterpret_cast<PySideProperty*>(self); delete reinterpret_cast<QmlListProperty*>(PySide::Property::userData(pySelf)); // calls base type constructor - PepType(PepType(Py_TYPE(pySelf))->tp_base)->tp_free(self); + Py_TYPE(pySelf)->tp_base->tp_free(self); } static PyType_Slot PropertyListType_slots[] = { @@ -364,7 +364,7 @@ QtQml_VolatileBoolObject_new(PyTypeObject *type, PyObject *args, PyObject *kwds) return Q_NULLPTR; QtQml_VolatileBoolObject *self - = reinterpret_cast<QtQml_VolatileBoolObject *>(PepType(type)->tp_alloc(type, 0)); + = reinterpret_cast<QtQml_VolatileBoolObject *>(type->tp_alloc(type, 0)); if (self != Q_NULLPTR) self->flag = ok; @@ -421,10 +421,10 @@ QtQml_VolatileBoolObject_repr(QtQml_VolatileBoolObject *self) if (self->flag) s = PyBytes_FromFormat("%s(True)", - PepType((Py_TYPE(self)))->tp_name); + Py_TYPE(self)->tp_name); else s = PyBytes_FromFormat("%s(False)", - PepType((Py_TYPE(self)))->tp_name); + Py_TYPE(self)->tp_name); Py_XINCREF(s); return s; } @@ -436,10 +436,10 @@ QtQml_VolatileBoolObject_str(QtQml_VolatileBoolObject *self) if (self->flag) s = PyBytes_FromFormat("%s(True) -> %p", - PepType((Py_TYPE(self)))->tp_name, &(self->flag)); + Py_TYPE(self)->tp_name, &(self->flag)); else s = PyBytes_FromFormat("%s(False) -> %p", - PepType((Py_TYPE(self)))->tp_name, &(self->flag)); + Py_TYPE(self)->tp_name, &(self->flag)); Py_XINCREF(s); return s; } diff --git a/sources/pyside2/PySide2/QtQuick/pysidequickregistertype.cpp b/sources/pyside2/PySide2/QtQuick/pysidequickregistertype.cpp index 67ef53551..bf3ff06a2 100644 --- a/sources/pyside2/PySide2/QtQuick/pysidequickregistertype.cpp +++ b/sources/pyside2/PySide2/QtQuick/pysidequickregistertype.cpp @@ -110,7 +110,7 @@ bool pyTypeObjectInheritsFromClass(PyTypeObject *pyObjType, QByteArray className { className.append('*'); PyTypeObject *classPyType = Shiboken::Conversions::getPythonTypeObject(className.constData()); - bool isDerived = PySequence_Contains(PepType(pyObjType)->tp_mro, + bool isDerived = PySequence_Contains(pyObjType->tp_mro, reinterpret_cast<PyObject *>(classPyType)); return isDerived; } @@ -190,7 +190,7 @@ bool quickRegisterType(PyObject *pyObj, const char *uri, int versionMajor, int v PyTypeObject *pyObjType = reinterpret_cast<PyTypeObject *>(pyObj); PyTypeObject *qQuickItemPyType = Shiboken::Conversions::getPythonTypeObject("QQuickItem*"); - bool isQuickItem = PySequence_Contains(PepType(pyObjType)->tp_mro, + bool isQuickItem = PySequence_Contains(pyObjType->tp_mro, reinterpret_cast<PyObject *>(qQuickItemPyType)); // Register only classes that inherit QQuickItem or its children. diff --git a/sources/pyside2/PySide2/QtScript/typesystem_script.xml b/sources/pyside2/PySide2/QtScript/typesystem_script.xml index dc089a300..d2d3e3182 100644 --- a/sources/pyside2/PySide2/QtScript/typesystem_script.xml +++ b/sources/pyside2/PySide2/QtScript/typesystem_script.xml @@ -85,11 +85,11 @@ <inject-code class="target" position="beginning"> if (%CPPSELF.isVariant() || %CPPSELF.isString()) { QString format = QString().sprintf("%s(\"%s\")", - PepType(Py_TYPE(%PYSELF))->tp_name, + Py_TYPE(%PYSELF)->tp_name, qPrintable(%CPPSELF.toString())); %PYARG_0 = Shiboken::String::fromCString(qPrintable(format)); } else { - %PYARG_0 = Shiboken::String::fromCString(PepType(Py_TYPE(%PYSELF))->tp_name); + %PYARG_0 = Shiboken::String::fromCString(Py_TYPE(%PYSELF)->tp_name); } </inject-code> </add-function> diff --git a/sources/pyside2/PySide2/QtWidgets/typesystem_widgets_common.xml b/sources/pyside2/PySide2/QtWidgets/typesystem_widgets_common.xml index 11e6a9f7a..125d63054 100644 --- a/sources/pyside2/PySide2/QtWidgets/typesystem_widgets_common.xml +++ b/sources/pyside2/PySide2/QtWidgets/typesystem_widgets_common.xml @@ -269,7 +269,7 @@ <enum-type name="PanelModality" since="4.6"/> <inject-code class="target" position="end"> PyObject *userTypeConstant = PyInt_FromLong(QGraphicsItem::UserType); - PyDict_SetItemString(PepType(Sbk_QGraphicsItem_TypeF())->tp_dict, "UserType", userTypeConstant); + PyDict_SetItemString(reinterpret_cast<PyTypeObject *>(Sbk_QGraphicsItem_TypeF())->tp_dict, "UserType", userTypeConstant); </inject-code> <modify-function signature="setParentItem(QGraphicsItem*)"> <modify-argument index="this"> diff --git a/sources/pyside2/PySide2/typesystem_templates.xml b/sources/pyside2/PySide2/typesystem_templates.xml index 103d773cf..b13ab4b63 100644 --- a/sources/pyside2/PySide2/typesystem_templates.xml +++ b/sources/pyside2/PySide2/typesystem_templates.xml @@ -315,11 +315,11 @@ <!-- templates for __repr__ --> <template name="repr_code"> QString format = QString().sprintf("%s(%REPR_FORMAT)", - PepType(Py_TYPE(%PYSELF))->tp_name, %REPR_ARGS); + Py_TYPE(%PYSELF)->tp_name, %REPR_ARGS); %PYARG_0 = Shiboken::String::fromCString(qPrintable(format)); </template> <template name="repr_code_matrix"> - QString format= QString("%1((").arg(PepType(Py_TYPE(%PYSELF))->tp_name); + QString format= QString("%1((").arg(Py_TYPE(%PYSELF)->tp_name); QList< %MATRIX_TYPE > cppArgs; %MATRIX_TYPE data[%MATRIX_SIZE]; |