From 18dc31becdd994c53a9f894087cf1ef99fbd0232 Mon Sep 17 00:00:00 2001 From: Christian Tismer Date: Sun, 17 Dec 2017 19:12:56 +0100 Subject: PEP 384-squash: Implement PEP 384 This is the condensed checkin of 18 commits which created the implementation of PEP 384. Task-number: PYSIDE-560 Change-Id: I834c659af4c2b55b268f8e8dc4cfa53f02502409 Reviewed-by: Qt CI Bot Reviewed-by: Alexandru Croitor --- sources/pyside2/CMakeLists.txt | 41 + .../QtCore/glue/qbytearray_bufferprotocol.cpp | 2 +- .../PySide2/QtCore/glue/qbytearray_mgetitem.cpp | 2 +- .../PySide2/QtCore/glue/qeasingcurve_glue.cpp | 2 +- .../PySide2/QtCore/glue/qeasingcurve_glue.h | 2 +- .../PySide2/QtCore/glue/qobject_connect.cpp | 3 +- .../PySide2/QtCore/glue/qobject_findchild.cpp | 4 +- .../PySide2/QtCore/typesystem_core_common.xml | 59 +- .../PySide2/QtGui/typesystem_gui_common.xml | 2 +- .../PySide2/QtQml/pysideqmlregistertype.cpp | 181 ++-- .../pyside2/PySide2/QtQml/pysideqmlregistertype.h | 6 +- .../PySide2/QtQuick/pysidequickregistertype.cpp | 8 +- .../PySide2/QtQuick/pysidequickregistertype.h | 2 +- .../pyside2/PySide2/QtScript/typesystem_script.xml | 7 +- .../pyside2/PySide2/QtWidgets/glue/qmenu_glue.cpp | 6 +- .../PySide2/QtWidgets/glue/qmenubar_glue.cpp | 5 +- .../QtWidgets/typesystem_widgets_common.xml | 20 +- sources/pyside2/PySide2/typesystem_templates.xml | 5 +- sources/pyside2/libpyside/dynamicqmetaobject.cpp | 10 +- sources/pyside2/libpyside/globalreceiverv2.h | 1 - sources/pyside2/libpyside/pyside.cpp | 8 +- sources/pyside2/libpyside/pysideclassinfo.cpp | 83 +- sources/pyside2/libpyside/pysideclassinfo.h | 2 +- sources/pyside2/libpyside/pysidemetafunction.cpp | 76 +- sources/pyside2/libpyside/pysidemetafunction.h | 2 +- sources/pyside2/libpyside/pysideproperty.cpp | 92 +- sources/pyside2/libpyside/pysideproperty.h | 2 +- sources/pyside2/libpyside/pysideqflags.cpp | 70 +- sources/pyside2/libpyside/pysideqflags.h | 2 +- sources/pyside2/libpyside/pysidesignal.cpp | 301 +++---- sources/pyside2/libpyside/pysidesignal.h | 4 +- sources/pyside2/libpyside/pysidesignal_p.h | 2 +- sources/pyside2/libpyside/pysideslot.cpp | 80 +- sources/pyside2/libpyside/pysideweakref.cpp | 74 +- sources/pyside2/libpyside/signalmanager.cpp.in | 2 +- sources/pyside2/libpyside/signalmanager.h | 1 - sources/pyside2/plugins/customwidget.cpp | 2 +- .../shiboken2/ApiExtractor/abstractmetabuilder.cpp | 2 +- sources/shiboken2/CMakeLists.txt | 67 +- .../shiboken2/generator/shiboken2/cppgenerator.cpp | 447 +++++----- .../generator/shiboken2/shibokengenerator.cpp | 16 +- sources/shiboken2/libshiboken/CMakeLists.txt | 6 + sources/shiboken2/libshiboken/autodecref.h | 2 + sources/shiboken2/libshiboken/basewrapper.cpp | 500 +++++------ sources/shiboken2/libshiboken/basewrapper.h | 38 +- sources/shiboken2/libshiboken/bindingmanager.cpp | 29 +- sources/shiboken2/libshiboken/bufferprocs27.cpp | 397 +++++++++ sources/shiboken2/libshiboken/bufferprocs27.h | 144 ++++ sources/shiboken2/libshiboken/pep384impl.cpp | 924 +++++++++++++++++++++ sources/shiboken2/libshiboken/pep384impl.h | 571 +++++++++++++ sources/shiboken2/libshiboken/python25compat.h | 2 +- sources/shiboken2/libshiboken/qapp_macro.cpp | 4 +- sources/shiboken2/libshiboken/qt_attribution.json | 12 + .../shiboken2/libshiboken/sbkarrayconverter.cpp | 2 +- sources/shiboken2/libshiboken/sbkconverter.cpp | 50 +- sources/shiboken2/libshiboken/sbkconverter.h | 23 +- sources/shiboken2/libshiboken/sbkenum.cpp | 375 +++++---- sources/shiboken2/libshiboken/sbkenum.h | 11 +- sources/shiboken2/libshiboken/sbkpython.h | 11 +- sources/shiboken2/libshiboken/sbkstring.cpp | 4 +- sources/shiboken2/libshiboken/sbkversion.h.in | 3 + sources/shiboken2/libshiboken/shibokenbuffer.cpp | 4 +- sources/shiboken2/libshiboken/signature.cpp | 181 +++- .../tmp-referencetopython/sbkconverter.cpp | 2 +- .../tmp-referencetopython/sbkconverter.h | 2 +- sources/shiboken2/libshiboken/typespec.cpp | 776 +++++++++++++++++ sources/shiboken2/libshiboken/typespec.h | 153 ++++ sources/shiboken2/libshiboken/voidptr.cpp | 166 +--- sources/shiboken2/libshiboken/voidptr.h | 4 +- .../shiboken2/tests/minimalbinding/CMakeLists.txt | 3 +- .../shiboken2/tests/otherbinding/CMakeLists.txt | 3 +- .../shiboken2/tests/samplebinding/CMakeLists.txt | 3 +- .../samplebinding/bytearray_bufferprotocol.cpp | 2 +- .../tests/samplebinding/namespace_test.py | 20 +- .../tests/samplebinding/typesystem_sample.xml | 4 +- .../shiboken2/tests/smartbinding/CMakeLists.txt | 3 +- 76 files changed, 4541 insertions(+), 1596 deletions(-) create mode 100644 sources/shiboken2/libshiboken/bufferprocs27.cpp create mode 100644 sources/shiboken2/libshiboken/bufferprocs27.h create mode 100644 sources/shiboken2/libshiboken/pep384impl.cpp create mode 100644 sources/shiboken2/libshiboken/pep384impl.h create mode 100644 sources/shiboken2/libshiboken/qt_attribution.json create mode 100644 sources/shiboken2/libshiboken/typespec.cpp create mode 100644 sources/shiboken2/libshiboken/typespec.h (limited to 'sources') diff --git a/sources/pyside2/CMakeLists.txt b/sources/pyside2/CMakeLists.txt index 77382480d..08647530c 100644 --- a/sources/pyside2/CMakeLists.txt +++ b/sources/pyside2/CMakeLists.txt @@ -400,12 +400,53 @@ else() endif() message(STATUS "Detected OS: ${AUTO_OS}") +# On Windows, PYTHON_LIBRARIES can be a list. Example: +# optimized;C:/Python36/libs/python36.lib;debug;C:/Python36/libs/python36_d.lib +# On other platforms, this result is not used at all. +execute_process( + COMMAND ${PYTHON_EXECUTABLE} -c "if True: + for lib in '${PYTHON_LIBRARIES}'.split(';'): + if '/' in lib: + prefix, py = lib.rsplit( '/', 1) + if py.startswith('python3'): + print(prefix + '/python3.lib') + break + " + OUTPUT_VARIABLE PYTHON_LIMITED_LIBRARIES + OUTPUT_STRIP_TRAILING_WHITESPACE) + if (WIN32) set(PATH_SEP "\;") else() set(PATH_SEP ":") endif() +option(FORCE_LIMITED_API "Enable the limited API." "no") + +set(PYTHON_LIMITED_API 0) +if(FORCE_LIMITED_API STREQUAL "yes") + # GREATER_EQUAL is available only from cmake 3.7 on. We mean python 3.5 . + if (${PYTHON_VERSION_MAJOR} EQUAL 3 AND ${PYTHON_VERSION_MINOR} GREATER 4) + if (WIN32) + set(SHIBOKEN_PYTHON_LIBRARIES ${PYTHON_LIMITED_LIBRARIES}) + endif() + add_definitions("-DPy_LIMITED_API=0x03050000") + set(PYTHON_LIMITED_API 1) + endif() + if (CMAKE_BUILD_TYPE STREQUAL "Release") + add_definitions("-DNDEBUG") + endif() +endif() + +if (PYTHON_LIMITED_API) + if (WIN32 AND NOT EXISTS "${PYTHON_LIMITED_LIBRARIES}") + message(FATAL_ERROR "The Limited API was enabled, but ${PYTHON_LIMITED_LIBRARIES} was not found!") + endif() + message(STATUS "******************************************************") + message(STATUS "** Limited API enabled ${PYTHON_LIMITED_LIBRARIES}") + message(STATUS "******************************************************") +endif() + # Define supported Qt Version set(SUPPORTED_QT_VERSION "${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}") diff --git a/sources/pyside2/PySide2/QtCore/glue/qbytearray_bufferprotocol.cpp b/sources/pyside2/PySide2/QtCore/glue/qbytearray_bufferprotocol.cpp index 22825a5cb..ed5fef3ae 100644 --- a/sources/pyside2/PySide2/QtCore/glue/qbytearray_bufferprotocol.cpp +++ b/sources/pyside2/PySide2/QtCore/glue/qbytearray_bufferprotocol.cpp @@ -47,7 +47,7 @@ extern "C" { static Py_ssize_t SbkQByteArray_segcountproc(PyObject* self, Py_ssize_t* lenp) { if (lenp) - *lenp = self->ob_type->tp_as_sequence->sq_length(self); + *lenp = Py_TYPE(self)->tp_as_sequence->sq_length(self); return 1; } diff --git a/sources/pyside2/PySide2/QtCore/glue/qbytearray_mgetitem.cpp b/sources/pyside2/PySide2/QtCore/glue/qbytearray_mgetitem.cpp index 6a997c852..f1d5a6bfc 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", - _key->ob_type->tp_name); + PepType((Py_TYPE(_key)))->tp_name); return NULL; } diff --git a/sources/pyside2/PySide2/QtCore/glue/qeasingcurve_glue.cpp b/sources/pyside2/PySide2/QtCore/glue/qeasingcurve_glue.cpp index 5d28fbf41..46a69be31 100644 --- a/sources/pyside2/PySide2/QtCore/glue/qeasingcurve_glue.cpp +++ b/sources/pyside2/PySide2/QtCore/glue/qeasingcurve_glue.cpp @@ -37,7 +37,7 @@ ** ****************************************************************************/ -#include +#include #include #include #include diff --git a/sources/pyside2/PySide2/QtCore/glue/qeasingcurve_glue.h b/sources/pyside2/PySide2/QtCore/glue/qeasingcurve_glue.h index 7053d808c..358ea9eec 100644 --- a/sources/pyside2/PySide2/QtCore/glue/qeasingcurve_glue.h +++ b/sources/pyside2/PySide2/QtCore/glue/qeasingcurve_glue.h @@ -40,7 +40,7 @@ #ifndef __QEASINGCURVE_GLUE__ #define __QEASINGCURVE_GLUE__ -#include +#include #include class PySideEasingCurveFunctor diff --git a/sources/pyside2/PySide2/QtCore/glue/qobject_connect.cpp b/sources/pyside2/PySide2/QtCore/glue/qobject_connect.cpp index ed37cef34..20f3720bf 100644 --- a/sources/pyside2/PySide2/QtCore/glue/qobject_connect.cpp +++ b/sources/pyside2/PySide2/QtCore/glue/qobject_connect.cpp @@ -43,8 +43,7 @@ static bool isDecorator(PyObject* method, PyObject* self) if (!PyObject_HasAttr(self, methodName)) return true; Shiboken::AutoDecRef otherMethod(PyObject_GetAttr(self, methodName)); - return reinterpret_cast(otherMethod.object())->im_func != \ - reinterpret_cast(method)->im_func; + return PyMethod_GET_FUNCTION(otherMethod.object()) != PyMethod_GET_FUNCTION(method); } static bool getReceiver(QObject *source, const char* signal, PyObject* callback, QObject** receiver, PyObject** self, QByteArray* callbackSig) diff --git a/sources/pyside2/PySide2/QtCore/glue/qobject_findchild.cpp b/sources/pyside2/PySide2/QtCore/glue/qobject_findchild.cpp index 464fb68b1..b32d104fd 100644 --- a/sources/pyside2/PySide2/QtCore/glue/qobject_findchild.cpp +++ b/sources/pyside2/PySide2/QtCore/glue/qobject_findchild.cpp @@ -41,7 +41,7 @@ static QObject* _findChildHelper(const QObject* parent, const QString& name, PyT { foreach(QObject* child, parent->children()) { Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QObject*](child)); - if (PyType_IsSubtype(pyChild->ob_type, desiredType) + if (PyType_IsSubtype(Py_TYPE(pyChild), desiredType) && (name.isNull() || name == child->objectName())) { return child; } @@ -71,7 +71,7 @@ static void _findChildrenHelper(const QObject* parent, const T& name, PyTypeObje { foreach(const QObject* child, parent->children()) { Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QObject*](child)); - if (PyType_IsSubtype(pyChild->ob_type, desiredType) && _findChildrenComparator(child, name)) + if (PyType_IsSubtype(Py_TYPE(pyChild), desiredType) && _findChildrenComparator(child, name)) PyList_Append(result, pyChild); _findChildrenHelper(child, name, desiredType, result); } diff --git a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml index f0b6b9640..63c3d50ea 100644 --- a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml +++ b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml @@ -291,12 +291,18 @@ - Py_UNICODE *unicode = PyUnicode_AS_UNICODE(%in); - #if defined(Py_UNICODE_WIDE) + #ifndef Py_LIMITED_API + Py_UNICODE* unicode = PyUnicode_AS_UNICODE(%in); + # if defined(Py_UNICODE_WIDE) // cast as Py_UNICODE can be a different type %out = QString::fromUcs4((const uint*)unicode); - #else + # else %out = QString::fromUtf16((const ushort*)unicode, PyUnicode_GET_SIZE(%in)); + # endif + #else + wchar_t *temp = PyUnicode_AsWideCharString(%in, NULL); + %out = QString::fromWCharArray(temp); + PyMem_Free(temp); #endif @@ -410,7 +416,7 @@ // a class supported by QVariant? int typeCode; - const char *typeName = QVariant_resolveMetaType(%in->ob_type, &typeCode); + const char *typeName = QVariant_resolveMetaType(Py_TYPE(%in), &typeCode); if (!typeCode || !typeName) return; QVariant var(typeCode, (void*)0); @@ -435,9 +441,9 @@ static const char *QVariant_resolveMetaType(PyTypeObject *type, int *typeId) { - if (PyObject_TypeCheck(type, &SbkObjectType_Type)) { - SbkObjectType *sbkType = (SbkObjectType*)type; - const char *typeName = Shiboken::ObjectType::getOriginalName(sbkType); + if (PyObject_TypeCheck(type, SbkObjectType_TypeF())) { + SbkObjectType* sbkType = (SbkObjectType*)type; + const char* typeName = Shiboken::ObjectType::getOriginalName(sbkType); if (!typeName) return 0; bool valueType = '*' != typeName[qstrlen(typeName) - 1]; @@ -456,15 +462,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 (type->tp_bases) { - for (int i = 0; i < PyTuple_GET_SIZE(type->tp_bases); ++i) { - const char *derivedName = QVariant_resolveMetaType((PyTypeObject*)PyTuple_GET_ITEM(type->tp_bases, i), typeId); + 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 (derivedName) return derivedName; } } - else if (type->tp_base) { - return QVariant_resolveMetaType(type->tp_base, typeId); + else if (PepType(type)->tp_base) { + return QVariant_resolveMetaType(PepType(type)->tp_base, typeId); } } *typeId = 0; @@ -563,16 +570,16 @@ const char *typeName; - if (Shiboken::String::checkType((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. else if (%in == reinterpret_cast<PyObject*>(&PyLong_Type)) typeName = "int"; // long is a UserType in QVariant. - else if (%in->ob_type == &SbkObjectType_Type) + else if (Py_TYPE(%in) == SbkObjectType_TypeF()) typeName = Shiboken::ObjectType::getOriginalName((SbkObjectType*)%in); else - typeName = (reinterpret_cast<PyTypeObject*>(%in))->tp_name; + typeName = PepType((reinterpret_cast<PyTypeObject*>(%in)))->tp_name; %out = QVariant::nameToType(typeName); @@ -2589,7 +2596,7 @@ - QByteArray b((reinterpret_cast<PyObject*>(%PYSELF))->ob_type->tp_name); + QByteArray b(PepType(Py_TYPE(%PYSELF))->tp_name); PyObject *aux = Shiboken::String::fromStringAndSize(%CPPSELF.constData(), %CPPSELF.size()); if (PyUnicode_CheckExact(aux)) { PyObject *tmp = PyUnicode_AsASCIIString(aux); @@ -3088,7 +3095,7 @@ Py_ssize_t size; uchar *ptr = reinterpret_cast<uchar*>(Shiboken::Buffer::getPointer(%PYARG_1, &size)); - %RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME(const_cast<const uchar*>(ptr), size); + %RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME(const_cast<const uchar*>(ptr), size); %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); @@ -3114,8 +3121,8 @@ // %FUNCTION_NAME() - disable generation of c++ function call (void) %2; // remove warning about unused variable Shiboken::AutoDecRef emptyTuple(PyTuple_New(0)); - PyObject *pyTimer = Shiboken::SbkType<QTimer>()->tp_new(Shiboken::SbkType<QTimer>(), emptyTuple, 0); - Shiboken::SbkType<QTimer>()->tp_init(pyTimer, emptyTuple, 0); + PyObject *pyTimer = PepType(Shiboken::SbkType<QTimer>())->tp_new(Shiboken::SbkType<QTimer>(), emptyTuple, 0); + PepType(Shiboken::SbkType<QTimer>())->tp_init(pyTimer, emptyTuple, 0); QTimer* timer = %CONVERTTOCPP[QTimer*](pyTimer); Shiboken::AutoDecRef result( @@ -3138,14 +3145,14 @@ // %FUNCTION_NAME() - disable generation of c++ function call Shiboken::AutoDecRef emptyTuple(PyTuple_New(0)); - PyObject *pyTimer = Shiboken::SbkType<QTimer>()->tp_new(Shiboken::SbkType<QTimer>(), emptyTuple, 0); - Shiboken::SbkType<QTimer>()->tp_init(pyTimer, emptyTuple, 0); + PyObject *pyTimer = PepType(Shiboken::SbkType<QTimer>())->tp_new(Shiboken::SbkType<QTimer>(), emptyTuple, 0); + PepType(Shiboken::SbkType<QTimer>())->tp_init(pyTimer, emptyTuple, 0); QTimer* timer = %CONVERTTOCPP[QTimer*](pyTimer); timer->setSingleShot(true); - if (PyObject_TypeCheck(%2, &PySideSignalInstanceType)) { + if (PyObject_TypeCheck(%2, PySideSignalInstanceTypeF())) { PySideSignalInstance *signalInstance = reinterpret_cast<PySideSignalInstance*>(%2); - Shiboken::AutoDecRef signalSignature(Shiboken::String::fromFormat("2%s",PySide::Signal::getSignature(signalInstance))); + Shiboken::AutoDecRef signalSignature(Shiboken::String::fromFormat("2%s", PySide::Signal::getSignature(signalInstance))); Shiboken::AutoDecRef result( PyObject_CallMethod(pyTimer, const_cast<char*>("connect"), @@ -4026,7 +4033,7 @@ s1.addTransition(button.clicked, s1h)</code> - if (PyObject_TypeCheck(%1, &PySideSignalInstanceType)) { + if (PyObject_TypeCheck(%1, PySideSignalInstanceTypeF())) { PyObject *dataSource = PySide::Signal::getObject((PySideSignalInstance*)%PYARG_1); Shiboken::AutoDecRef obType(PyObject_Type(dataSource)); QObject* sender = %CONVERTTOCPP[QObject*](dataSource); @@ -4082,11 +4089,11 @@ s1.addTransition(button.clicked, s1h)</code> // since it refers to a name very tied to the generator implementation. // Check bug #362 for more information on this // http://bugs.openbossa.org/show_bug.cgi?id=362 - if (!PyObject_TypeCheck(%1, &PySideSignalInstanceType)) + if (!PyObject_TypeCheck(%1, PySideSignalInstanceTypeF())) goto Sbk_%TYPEFunc_%FUNCTION_NAME_TypeError; PySideSignalInstance *signalInstance = reinterpret_cast<PySideSignalInstance*>(%1); QObject* sender = %CONVERTTOCPP[QObject*](PySide::Signal::getObject(signalInstance)); - QSignalTransition*%0 = %CPPSELF->%FUNCTION_NAME(sender,PySide::Signal::getSignature(signalInstance),%2); + QSignalTransition *%0 = %CPPSELF->%FUNCTION_NAME(sender, PySide::Signal::getSignature(signalInstance),%2); %PYARG_0 = %CONVERTTOPYTHON[QSignalTransition*](%0); diff --git a/sources/pyside2/PySide2/QtGui/typesystem_gui_common.xml b/sources/pyside2/PySide2/QtGui/typesystem_gui_common.xml index 47bf62992..eee22b55c 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)", - pyResult->ob_type->tp_name); + PepType((Py_TYPE(pyResult)))->tp_name); return QValidator::State(); } diff --git a/sources/pyside2/PySide2/QtQml/pysideqmlregistertype.cpp b/sources/pyside2/PySide2/QtQml/pysideqmlregistertype.cpp index d95ae2259..fa9eb6349 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(pyObj); - if (!PySequence_Contains(pyObjType->tp_mro, reinterpret_cast(qobjectType))) { + if (!PySequence_Contains(PepType(pyObjType)->tp_mro, reinterpret_cast(qobjectType))) { PyErr_Format(PyExc_TypeError, "A type inherited from %s expected, got %s.", - qobjectType->tp_name, pyObjType->tp_name); + PepType(qobjectType)->tp_name, PepType(pyObjType)->tp_name); return -1; } @@ -229,57 +229,34 @@ void propListTpFree(void* self) PySideProperty* pySelf = reinterpret_cast(self); delete reinterpret_cast(PySide::Property::userData(pySelf)); // calls base type constructor - Py_TYPE(pySelf)->tp_base->tp_free(self); + PepType(PepType(Py_TYPE(pySelf))->tp_base)->tp_free(self); } -PyTypeObject PropertyListType = { - PyVarObject_HEAD_INIT(0, 0) - "ListProperty", /*tp_name*/ - sizeof(PySideProperty), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - 0, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash */ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT, /*tp_flags*/ - 0, /*tp_doc */ - 0, /*tp_traverse */ - 0, /*tp_clear */ - 0, /*tp_richcompare */ - 0, /*tp_weaklistoffset */ - 0, /*tp_iter */ - 0, /*tp_iternext */ - 0, /*tp_methods */ - 0, /*tp_members */ - 0, /*tp_getset */ - &PySidePropertyType, /*tp_base */ - 0, /*tp_dict */ - 0, /*tp_descr_get */ - 0, /*tp_descr_set */ - 0, /*tp_dictoffset */ - propListTpInit, /*tp_init */ - 0, /*tp_alloc */ - 0, /*tp_new */ - propListTpFree, /*tp_free */ - 0, /*tp_is_gc */ - 0, /*tp_bases */ - 0, /*tp_mro */ - 0, /*tp_cache */ - 0, /*tp_subclasses */ - 0, /*tp_weaklist */ - 0, /*tp_del */ +static PyType_Slot PropertyListType_slots[] = { + {Py_tp_init, (void *)propListTpInit}, + {Py_tp_free, (void *)propListTpFree}, + {Py_tp_dealloc, (void *)SbkDummyDealloc}, + {0, 0} }; +static PyType_Spec PropertyListType_spec = { + "PySide2.QtQml.ListProperty", + sizeof(PySideProperty), + 0, + Py_TPFLAGS_DEFAULT, + PropertyListType_slots, +}; + + +PyTypeObject *PropertyListTypeF(void) +{ + static PyTypeObject *type = nullptr; + if (!type) { + PyObject *bases = Py_BuildValue("(O)", PySidePropertyTypeF()); + type = (PyTypeObject *)PyType_FromSpecWithBases(&PropertyListType_spec, bases); + Py_XDECREF(bases); + } + return type; +} } // extern "C" @@ -312,7 +289,7 @@ int propListCount(QQmlListProperty *propList) // Check return type int cppResult = 0; - PythonToCppFunc pythonToCpp; + PythonToCppFunc pythonToCpp = 0; if (PyErr_Occurred()) PyErr_Print(); else if ((pythonToCpp = Shiboken::Conversions::isPythonToCppConvertible(Shiboken::Conversions::PrimitiveTypeConverter(), retVal))) @@ -387,7 +364,7 @@ QtQml_VolatileBoolObject_new(PyTypeObject *type, PyObject *args, PyObject *kwds) return Q_NULLPTR; QtQml_VolatileBoolObject *self - = reinterpret_cast(type->tp_alloc(type, 0)); + = reinterpret_cast(PepType(type)->tp_alloc(type, 0)); if (self != Q_NULLPTR) self->flag = ok; @@ -444,10 +421,10 @@ QtQml_VolatileBoolObject_repr(QtQml_VolatileBoolObject *self) if (self->flag) s = PyBytes_FromFormat("%s(True)", - Py_TYPE(self)->tp_name); + PepType((Py_TYPE(self)))->tp_name); else s = PyBytes_FromFormat("%s(False)", - Py_TYPE(self)->tp_name); + PepType((Py_TYPE(self)))->tp_name); Py_XINCREF(s); return s; } @@ -459,87 +436,61 @@ QtQml_VolatileBoolObject_str(QtQml_VolatileBoolObject *self) if (self->flag) s = PyBytes_FromFormat("%s(True) -> %p", - Py_TYPE(self)->tp_name, &(self->flag)); + PepType((Py_TYPE(self)))->tp_name, &(self->flag)); else s = PyBytes_FromFormat("%s(False) -> %p", - Py_TYPE(self)->tp_name, &(self->flag)); + PepType((Py_TYPE(self)))->tp_name, &(self->flag)); Py_XINCREF(s); return s; } -PyTypeObject QtQml_VolatileBoolType = { - PyVarObject_HEAD_INIT(Q_NULLPTR, 0) /*ob_size*/ - "VolatileBool", /*tp_name*/ - sizeof(QtQml_VolatileBoolObject), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - 0, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - reinterpret_cast(QtQml_VolatileBoolObject_repr), /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash */ - 0, /*tp_call*/ - reinterpret_cast(QtQml_VolatileBoolObject_str), /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT, /*tp_flags*/ - "VolatileBool objects contain a C++ volatile bool", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - QtQml_VolatileBoolObject_methods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - QtQml_VolatileBoolObject_new, /* tp_new */ - 0, /* tp_free */ - 0, /* tp_is_gc */ - 0, /* tp_bases */ - 0, /* tp_mro */ - 0, /* tp_cache */ - 0, /* tp_subclasses */ - 0, /* tp_weaklist */ - 0, /* tp_del */ - 0, /* tp_version_tag */ -#if PY_MAJOR_VERSION > 3 || PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 4 - 0 /* tp_finalize */ -#endif +static PyType_Slot QtQml_VolatileBoolType_slots[] = { + {Py_tp_repr, (void *)reinterpret_cast(QtQml_VolatileBoolObject_repr)}, + {Py_tp_str, (void *)reinterpret_cast(QtQml_VolatileBoolObject_str)}, + {Py_tp_methods, (void *)QtQml_VolatileBoolObject_methods}, + {Py_tp_new, (void *)QtQml_VolatileBoolObject_new}, + {Py_tp_dealloc, (void *)SbkDummyDealloc}, + {0, 0} }; +static PyType_Spec QtQml_VolatileBoolType_spec = { + "PySide2.QtQml.VolatileBool", + sizeof(QtQml_VolatileBoolObject), + 0, + Py_TPFLAGS_DEFAULT, + QtQml_VolatileBoolType_slots, +}; + + +PyTypeObject *QtQml_VolatileBoolTypeF(void) +{ + static PyTypeObject *type = nullptr; + if (!type) + type = (PyTypeObject *)PyType_FromSpec(&QtQml_VolatileBoolType_spec); + return type; +} void PySide::initQmlSupport(PyObject* module) { ElementFactory::init(); // Export QmlListProperty type - if (PyType_Ready(&PropertyListType) < 0) { + if (PyType_Ready(PropertyListTypeF()) < 0) { + PyErr_Print(); qWarning() << "Error initializing PropertyList type."; return; } - Py_INCREF(reinterpret_cast(&PropertyListType)); - PyModule_AddObject(module, PropertyListType.tp_name, - reinterpret_cast(&PropertyListType)); + Py_INCREF(reinterpret_cast(PropertyListTypeF())); + PyModule_AddObject(module, PepType_GetNameStr(PropertyListTypeF()), + reinterpret_cast(PropertyListTypeF())); - if (PyType_Ready(&QtQml_VolatileBoolType) < 0) { + if (PyType_Ready(QtQml_VolatileBoolTypeF()) < 0) { + PyErr_Print(); qWarning() << "Error initializing VolatileBool type."; return; } - Py_INCREF(&QtQml_VolatileBoolType); - PyModule_AddObject(module, QtQml_VolatileBoolType.tp_name, - reinterpret_cast(&QtQml_VolatileBoolType)); + Py_INCREF(QtQml_VolatileBoolTypeF()); + PyModule_AddObject(module, PepType_GetNameStr(QtQml_VolatileBoolTypeF()), + reinterpret_cast(QtQml_VolatileBoolTypeF())); } diff --git a/sources/pyside2/PySide2/QtQml/pysideqmlregistertype.h b/sources/pyside2/PySide2/QtQml/pysideqmlregistertype.h index a4ee7309a..0ef6539a5 100644 --- a/sources/pyside2/PySide2/QtQml/pysideqmlregistertype.h +++ b/sources/pyside2/PySide2/QtQml/pysideqmlregistertype.h @@ -40,7 +40,7 @@ #ifndef PYSIDEQMLREGISTERTYPE_H #define PYSIDEQMLREGISTERTYPE_H -#include +#include struct SbkObjectType; @@ -78,8 +78,8 @@ typedef struct { volatile bool flag; } QtQml_VolatileBoolObject; -PyAPI_DATA(PyTypeObject) QtQml_VolatileBoolType; +PyAPI_FUNC(PyTypeObject *) QtQml_VolatileBoolTypeF(void); -#define VolatileBool_Check(op) (Py_TYPE(op) == &QtQml_VolatileBoolType) +#define VolatileBool_Check(op) (Py_TYPE(op) == QtQml_VolatileBoolTypeF()) #endif diff --git a/sources/pyside2/PySide2/QtQuick/pysidequickregistertype.cpp b/sources/pyside2/PySide2/QtQuick/pysidequickregistertype.cpp index 594fa8015..67ef53551 100644 --- a/sources/pyside2/PySide2/QtQuick/pysidequickregistertype.cpp +++ b/sources/pyside2/PySide2/QtQuick/pysidequickregistertype.cpp @@ -106,11 +106,11 @@ struct ElementFactory<0> : ElementFactoryBase<0> typePointerName, typeListName, \ typeMetaObject, type, registered) -bool pyTypeObjectInheritsFromClass(const PyTypeObject *pyObjType, QByteArray className) +bool pyTypeObjectInheritsFromClass(PyTypeObject *pyObjType, QByteArray className) { className.append('*'); PyTypeObject *classPyType = Shiboken::Conversions::getPythonTypeObject(className.constData()); - bool isDerived = PySequence_Contains(pyObjType->tp_mro, + bool isDerived = PySequence_Contains(PepType(pyObjType)->tp_mro, reinterpret_cast(classPyType)); return isDerived; } @@ -118,7 +118,7 @@ bool pyTypeObjectInheritsFromClass(const PyTypeObject *pyObjType, QByteArray cla template void registerTypeIfInheritsFromClass( QByteArray className, - const PyTypeObject *typeToRegister, + PyTypeObject *typeToRegister, const QByteArray &typePointerName, const QByteArray &typeListName, QMetaObject *typeMetaObject, @@ -190,7 +190,7 @@ bool quickRegisterType(PyObject *pyObj, const char *uri, int versionMajor, int v PyTypeObject *pyObjType = reinterpret_cast(pyObj); PyTypeObject *qQuickItemPyType = Shiboken::Conversions::getPythonTypeObject("QQuickItem*"); - bool isQuickItem = PySequence_Contains(pyObjType->tp_mro, + bool isQuickItem = PySequence_Contains(PepType(pyObjType)->tp_mro, reinterpret_cast(qQuickItemPyType)); // Register only classes that inherit QQuickItem or its children. diff --git a/sources/pyside2/PySide2/QtQuick/pysidequickregistertype.h b/sources/pyside2/PySide2/QtQuick/pysidequickregistertype.h index 35d3edecb..1955413b2 100644 --- a/sources/pyside2/PySide2/QtQuick/pysidequickregistertype.h +++ b/sources/pyside2/PySide2/QtQuick/pysidequickregistertype.h @@ -40,7 +40,7 @@ #ifndef PYSIDE_QUICK_REGISTER_TYPE_H #define PYSIDE_QUICK_REGISTER_TYPE_H -#include +#include struct SbkObjectType; diff --git a/sources/pyside2/PySide2/QtScript/typesystem_script.xml b/sources/pyside2/PySide2/QtScript/typesystem_script.xml index ccb2e3ab7..dc089a300 100644 --- a/sources/pyside2/PySide2/QtScript/typesystem_script.xml +++ b/sources/pyside2/PySide2/QtScript/typesystem_script.xml @@ -84,11 +84,12 @@ if (%CPPSELF.isVariant() || %CPPSELF.isString()) { - QString format = QString().sprintf("%s(\"%s\")", ((PyObject*)%PYSELF)->ob_type->tp_name, qPrintable(%CPPSELF.toString())); + QString format = QString().sprintf("%s(\"%s\")", + PepType(Py_TYPE(%PYSELF))->tp_name, + qPrintable(%CPPSELF.toString())); %PYARG_0 = Shiboken::String::fromCString(qPrintable(format)); } else { - %PYARG_0 = Shiboken::String::fromCString( - ((PyObject* )%PYSELF)->ob_type->tp_name); + %PYARG_0 = Shiboken::String::fromCString(PepType(Py_TYPE(%PYSELF))->tp_name); } diff --git a/sources/pyside2/PySide2/QtWidgets/glue/qmenu_glue.cpp b/sources/pyside2/PySide2/QtWidgets/glue/qmenu_glue.cpp index 8a4b7e628..4e9c8c3b7 100644 --- a/sources/pyside2/PySide2/QtWidgets/glue/qmenu_glue.cpp +++ b/sources/pyside2/PySide2/QtWidgets/glue/qmenu_glue.cpp @@ -50,7 +50,11 @@ inline PyObject* addActionWithPyObject(QMenu* self, const QIcon& icon, const QSt self->addAction(act); PyObject* pyAct = %CONVERTTOPYTHON[QAction*](act); - Shiboken::AutoDecRef result(PyObject_CallMethod(pyAct, "connect", "OsO", pyAct, SIGNAL(triggered()), callback)); + Shiboken::AutoDecRef result(PyObject_CallMethod(pyAct, + const_cast("connect"), + const_cast("OsO"), + pyAct, + SIGNAL(triggered()), callback)); if (result.isNull()) { Py_DECREF(pyAct); return 0; diff --git a/sources/pyside2/PySide2/QtWidgets/glue/qmenubar_glue.cpp b/sources/pyside2/PySide2/QtWidgets/glue/qmenubar_glue.cpp index fdd621128..8cdbc2e01 100644 --- a/sources/pyside2/PySide2/QtWidgets/glue/qmenubar_glue.cpp +++ b/sources/pyside2/PySide2/QtWidgets/glue/qmenubar_glue.cpp @@ -45,7 +45,10 @@ addActionWithPyObject(QMenuBar* self, const QString& text, PyObject* callback) self->addAction(act); PyObject* pyAct = %CONVERTTOPYTHON[QAction*](act); - PyObject* result = PyObject_CallMethod(pyAct, "connect", "OsO", pyAct, + PyObject* result = PyObject_CallMethod(pyAct, + const_cast("connect"), + const_cast("OsO"), + pyAct, SIGNAL(triggered(bool)), callback); if (result == 0 || result == Py_False) { diff --git a/sources/pyside2/PySide2/QtWidgets/typesystem_widgets_common.xml b/sources/pyside2/PySide2/QtWidgets/typesystem_widgets_common.xml index b4a6c2453..11e6a9f7a 100644 --- a/sources/pyside2/PySide2/QtWidgets/typesystem_widgets_common.xml +++ b/sources/pyside2/PySide2/QtWidgets/typesystem_widgets_common.xml @@ -269,7 +269,7 @@ PyObject *userTypeConstant = PyInt_FromLong(QGraphicsItem::UserType); - PyDict_SetItemString(Sbk_QGraphicsItem_Type.super.ht_type.tp_dict, "UserType", userTypeConstant); + PyDict_SetItemString(PepType(Sbk_QGraphicsItem_TypeF())->tp_dict, "UserType", userTypeConstant); @@ -1022,7 +1022,11 @@ %0 = new %TYPE(%1, %2); - Shiboken::AutoDecRef result(PyObject_CallMethod(%PYSELF, "connect", "OsO", %PYSELF, SIGNAL(activated()), %PYARG_3)); + Shiboken::AutoDecRef result(PyObject_CallMethod(%PYSELF, + const_cast<char *>("connect"), + const_cast<char *>("OsO"), + %PYSELF, SIGNAL(activated()), %PYARG_3) + ); if (!result.isNull()) Shiboken::Object::setParent(%PYARG_2, %PYSELF); @@ -3029,7 +3033,11 @@ QAction *action = %CPPSELF.addAction(%1, %2); %PYARG_0 = %CONVERTTOPYTHON[QAction*](action); - Shiboken::AutoDecRef result(PyObject_CallMethod(%PYARG_0, "connect", "OsO", %PYARG_0, SIGNAL(triggered()), %PYARG_3)); + Shiboken::AutoDecRef result(PyObject_CallMethod(%PYARG_0, + const_cast<char *>("connect"), + const_cast<char *>("OsO"), + %PYARG_0, SIGNAL(triggered()), %PYARG_3) + ); @@ -3045,7 +3053,11 @@ QAction *action = %CPPSELF.addAction(%1); %PYARG_0 = %CONVERTTOPYTHON[QAction*](action); - Shiboken::AutoDecRef result(PyObject_CallMethod(%PYARG_0, "connect", "OsO", %PYARG_0, SIGNAL(triggered()), %PYARG_2)); + Shiboken::AutoDecRef result(PyObject_CallMethod(%PYARG_0, + const_cast<char *>("connect"), + const_cast<char *>("OsO"), + %PYARG_0, SIGNAL(triggered()), %PYARG_2) + ); diff --git a/sources/pyside2/PySide2/typesystem_templates.xml b/sources/pyside2/PySide2/typesystem_templates.xml index 798d02ddb..103d773cf 100644 --- a/sources/pyside2/PySide2/typesystem_templates.xml +++ b/sources/pyside2/PySide2/typesystem_templates.xml @@ -314,11 +314,12 @@