diff options
Diffstat (limited to 'sources/pyside2/libpyside')
-rw-r--r-- | sources/pyside2/libpyside/CMakeLists.txt | 2 | ||||
-rw-r--r-- | sources/pyside2/libpyside/dynamicqmetaobject_p.h | 2 | ||||
-rw-r--r-- | sources/pyside2/libpyside/globalreceiverv2.cpp | 2 | ||||
-rw-r--r-- | sources/pyside2/libpyside/pyside.cpp | 10 | ||||
-rw-r--r-- | sources/pyside2/libpyside/pysideclassinfo.cpp | 15 | ||||
-rw-r--r-- | sources/pyside2/libpyside/pysideclassinfo_p.h | 2 | ||||
-rw-r--r-- | sources/pyside2/libpyside/pysidemetafunction.cpp | 10 | ||||
-rw-r--r-- | sources/pyside2/libpyside/pysideproperty.cpp | 24 | ||||
-rw-r--r-- | sources/pyside2/libpyside/pysidesignal.cpp | 77 | ||||
-rw-r--r-- | sources/pyside2/libpyside/pysideslot.cpp | 22 | ||||
-rw-r--r-- | sources/pyside2/libpyside/pysidestaticstrings.cpp | 59 | ||||
-rw-r--r-- | sources/pyside2/libpyside/pysidestaticstrings.h | 56 | ||||
-rw-r--r-- | sources/pyside2/libpyside/signalmanager.cpp | 13 |
13 files changed, 226 insertions, 68 deletions
diff --git a/sources/pyside2/libpyside/CMakeLists.txt b/sources/pyside2/libpyside/CMakeLists.txt index 7b8adfc84..7493a453a 100644 --- a/sources/pyside2/libpyside/CMakeLists.txt +++ b/sources/pyside2/libpyside/CMakeLists.txt @@ -53,6 +53,7 @@ set(libpyside_SRC pysideqflags.cpp pysideweakref.cpp pyside.cpp + pysidestaticstrings.cpp ${DESTROYLISTENER_MOC} ) @@ -130,6 +131,7 @@ set(libpyside_HEADERS pysidemacros.h signalmanager.h pyside.h + pysidestaticstrings.h pysidemetafunction.h pysidesignal.h pysideproperty.h diff --git a/sources/pyside2/libpyside/dynamicqmetaobject_p.h b/sources/pyside2/libpyside/dynamicqmetaobject_p.h index 534be5825..9199630b7 100644 --- a/sources/pyside2/libpyside/dynamicqmetaobject_p.h +++ b/sources/pyside2/libpyside/dynamicqmetaobject_p.h @@ -45,8 +45,6 @@ #include <QtCore/QByteArray> #include <QtCore/QMetaMethod> -#define GLOBAL_RECEIVER_CLASS_NAME "__GlobalReceiver__" - struct PySideProperty; namespace PySide { diff --git a/sources/pyside2/libpyside/globalreceiverv2.cpp b/sources/pyside2/libpyside/globalreceiverv2.cpp index 84ec92687..0377f7697 100644 --- a/sources/pyside2/libpyside/globalreceiverv2.cpp +++ b/sources/pyside2/libpyside/globalreceiverv2.cpp @@ -187,7 +187,7 @@ DynamicSlotDataV2::~DynamicSlotDataV2() GlobalReceiverV2::GlobalReceiverV2(PyObject *callback, SharedMap map) : QObject(nullptr), - m_metaObject(GLOBAL_RECEIVER_CLASS_NAME, &QObject::staticMetaObject), + m_metaObject("__GlobalReceiver__", &QObject::staticMetaObject), m_sharedMap(std::move(map)) { m_data = new DynamicSlotDataV2(callback, this); diff --git a/sources/pyside2/libpyside/pyside.cpp b/sources/pyside2/libpyside/pyside.cpp index 9ee20f461..2419b2e16 100644 --- a/sources/pyside2/libpyside/pyside.cpp +++ b/sources/pyside2/libpyside/pyside.cpp @@ -45,6 +45,7 @@ #include "pysideproperty.h" #include "pysidesignal.h" #include "pysidesignal_p.h" +#include "pysidestaticstrings.h" #include "pysideslot_p.h" #include "pysidemetafunction_p.h" #include "pysidemetafunction.h" @@ -57,6 +58,7 @@ #include <gilstate.h> #include <sbkconverter.h> #include <sbkstring.h> +#include <sbkstaticstrings.h> #include <qapp_macro.h> #include <QtCore/QByteArray> @@ -147,7 +149,8 @@ bool fillQtProperties(PyObject *qObj, const QMetaObject *metaObj, PyObject *kwds return false; } if (!accept) { - PyErr_Format(PyExc_AttributeError, "'%S' is not a Qt property or a signal", key); + PyErr_Format(PyExc_AttributeError, "'%s' is not a Qt property or a signal", + propName.constData()); return false; } } @@ -233,7 +236,8 @@ void initDynamicMetaObject(SbkObjectType *type, const QMetaObject *base, std::si if (!converter) return; Shiboken::AutoDecRef pyMetaObject(Shiboken::Conversions::pointerToPython(converter, metaObjectPtr)); - PyObject_SetAttrString(reinterpret_cast<PyObject *>(type), "staticMetaObject", pyMetaObject); + PyObject_SetAttr(reinterpret_cast<PyObject *>(type), + PySide::PyName::qtStaticMetaObject(), pyMetaObject); } TypeUserData *retrieveTypeUserData(SbkObjectType *sbkTypeObj) @@ -539,7 +543,7 @@ bool registerInternalQtConf() // Querying __file__ should be done only for modules that have finished their initialization. // Thus querying for the top-level PySide2 package works for us whenever any Qt-wrapped module // is loaded. - PyObject *pysideInitFilePath = PyObject_GetAttrString(pysideModule, "__file__"); + PyObject *pysideInitFilePath = PyObject_GetAttr(pysideModule, Shiboken::PyMagicName::file()); Py_DECREF(pysideModule); if (!pysideInitFilePath) return false; diff --git a/sources/pyside2/libpyside/pysideclassinfo.cpp b/sources/pyside2/libpyside/pysideclassinfo.cpp index bf2a1307f..fe5ca8765 100644 --- a/sources/pyside2/libpyside/pysideclassinfo.cpp +++ b/sources/pyside2/libpyside/pysideclassinfo.cpp @@ -45,8 +45,7 @@ #include "dynamicqmetaobject.h" #include <shiboken.h> - -#define CLASSINFO_CLASS_NAME "ClassInfo" +#include <signature.h> extern "C" { @@ -65,7 +64,7 @@ static PyType_Slot PySideClassInfoType_slots[] = { {0, 0} }; static PyType_Spec PySideClassInfoType_spec = { - "PySide2.QtCore." CLASSINFO_CLASS_NAME, + "PySide2.QtCore.ClassInfo", sizeof(PySideClassInfo), 0, Py_TPFLAGS_DEFAULT, @@ -161,7 +160,7 @@ int classInfoTpInit(PyObject *self, PyObject *args, PyObject *kwds) } } - return PyErr_Occurred() ? -1 : 1; + return PyErr_Occurred() ? -1 : 0; } void classInfoFree(void *self) @@ -179,13 +178,17 @@ void classInfoFree(void *self) namespace PySide { namespace ClassInfo { +static const char *ClassInfo_SignatureStrings[] = { + "PySide2.QtCore.ClassInfo(**info:typing.Dict[str,str])", + nullptr}; // Sentinel + void init(PyObject *module) { - if (PyType_Ready(PySideClassInfoTypeF()) < 0) + if (SbkSpecial_Type_Ready(module, PySideClassInfoTypeF(), ClassInfo_SignatureStrings) < 0) return; Py_INCREF(PySideClassInfoTypeF()); - PyModule_AddObject(module, CLASSINFO_CLASS_NAME, reinterpret_cast<PyObject *>(PySideClassInfoTypeF())); + PyModule_AddObject(module, "ClassInfo", reinterpret_cast<PyObject *>(PySideClassInfoTypeF())); } bool checkType(PyObject *pyObj) diff --git a/sources/pyside2/libpyside/pysideclassinfo_p.h b/sources/pyside2/libpyside/pysideclassinfo_p.h index 426aee133..021aa58e9 100644 --- a/sources/pyside2/libpyside/pysideclassinfo_p.h +++ b/sources/pyside2/libpyside/pysideclassinfo_p.h @@ -44,8 +44,6 @@ #include <QMetaObject> #include "pysideclassinfo.h" -#define __INFO_ATTR_NAME__ "__classInfo__" - struct PySideClassInfo; extern "C" diff --git a/sources/pyside2/libpyside/pysidemetafunction.cpp b/sources/pyside2/libpyside/pysidemetafunction.cpp index 346117201..e0e0c439b 100644 --- a/sources/pyside2/libpyside/pysidemetafunction.cpp +++ b/sources/pyside2/libpyside/pysidemetafunction.cpp @@ -41,6 +41,7 @@ #include "pysidemetafunction_p.h" #include <shiboken.h> +#include <signature.h> #include <QtCore/QMetaMethod> @@ -65,7 +66,7 @@ static PyType_Slot PySideMetaFunctionType_slots[] = { {0, 0} }; static PyType_Spec PySideMetaFunctionType_spec = { - "PySide.MetaFunction", + "PySide2.QtCore.MetaFunction", sizeof(PySideMetaFunction), 0, Py_TPFLAGS_DEFAULT, @@ -101,11 +102,16 @@ PyObject *functionCall(PyObject *self, PyObject *args, PyObject * /* kw */) namespace PySide { namespace MetaFunction { +static const char *MetaFunction_SignatureStrings[] = { + "PySide2.QtCore.MetaFunction.__call__(*args:typing.Any)->typing.Any", + nullptr}; // Sentinel + void init(PyObject *module) { - if (PyType_Ready(PySideMetaFunctionTypeF()) < 0) + if (SbkSpecial_Type_Ready(module, PySideMetaFunctionTypeF(), MetaFunction_SignatureStrings) < 0) return; + Py_INCREF(PySideMetaFunctionTypeF()); PyModule_AddObject(module, "MetaFunction", reinterpret_cast<PyObject *>(PySideMetaFunctionTypeF())); } diff --git a/sources/pyside2/libpyside/pysideproperty.cpp b/sources/pyside2/libpyside/pysideproperty.cpp index a2bf5fd2b..d9d15eb3b 100644 --- a/sources/pyside2/libpyside/pysideproperty.cpp +++ b/sources/pyside2/libpyside/pysideproperty.cpp @@ -45,8 +45,7 @@ #include "pysidesignal_p.h" #include <shiboken.h> - -#define QPROPERTY_CLASS_NAME "Property" +#include <signature.h> extern "C" { @@ -82,7 +81,7 @@ static PyType_Slot PySidePropertyType_slots[] = { }; // Dotted modulename is crucial for PyType_FromSpec to work. Is this name right? static PyType_Spec PySidePropertyType_spec = { - "PySide2.QtCore." QPROPERTY_CLASS_NAME, + "PySide2.QtCore.Property", sizeof(PySideProperty), 0, Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_BASETYPE, @@ -175,7 +174,7 @@ int qpropertyTpInit(PyObject *self, PyObject *args, PyObject *kwds) /*s*/ &doc, /*O*/ &(pData->notify), /*bbbbbb*/ &(pData->designable), &(pData->scriptable), &(pData->stored), &(pData->user), &(pData->constant), &(pData->final))) { - return 0; + return -1; } if (doc) { @@ -198,7 +197,7 @@ int qpropertyTpInit(PyObject *self, PyObject *args, PyObject *kwds) Py_XINCREF(pData->freset); Py_XINCREF(pData->fdel); Py_XINCREF(pData->notify); - return 1; + return 0; } pData->fget = nullptr; pData->fset = nullptr; @@ -321,13 +320,24 @@ static PyObject *getFromType(PyTypeObject *type, PyObject *name) namespace PySide { namespace Property { +static const char *Property_SignatureStrings[] = { + "PySide2.QtCore.Property(type:type,fget:typing.Callable=None,fset:typing.Callable=None," + "freset:typing.Callable=None,fdel:typing.Callable=None,doc:str=None," + "notify:typing.Callable=None,designable:bool=True,scriptable:bool=True," + "stored:bool=True,user:bool=False,constant:bool=False,final:bool=False)", + "PySide2.QtCore.Property.getter(func:typing.Callable)", + "PySide2.QtCore.Property.read(func:typing.Callable)", + "PySide2.QtCore.Property.setter(func:typing.Callable)", + "PySide2.QtCore.Property.write(func:typing.Callable)", + nullptr}; // Sentinel + void init(PyObject *module) { - if (PyType_Ready(PySidePropertyTypeF()) < 0) + if (SbkSpecial_Type_Ready(module, PySidePropertyTypeF(), Property_SignatureStrings) < 0) return; Py_INCREF(PySidePropertyTypeF()); - PyModule_AddObject(module, QPROPERTY_CLASS_NAME, reinterpret_cast<PyObject *>(PySidePropertyTypeF())); + PyModule_AddObject(module, "Property", reinterpret_cast<PyObject *>(PySidePropertyTypeF())); } bool checkType(PyObject *pyObj) diff --git a/sources/pyside2/libpyside/pysidesignal.cpp b/sources/pyside2/libpyside/pysidesignal.cpp index 47a5fff43..ed1dcb729 100644 --- a/sources/pyside2/libpyside/pysidesignal.cpp +++ b/sources/pyside2/libpyside/pysidesignal.cpp @@ -40,6 +40,7 @@ #include <sbkpython.h> #include "pysidesignal.h" #include "pysidesignal_p.h" +#include "pysidestaticstrings.h" #include "signalmanager.h" #include <shiboken.h> @@ -47,12 +48,11 @@ #include <QtCore/QObject> #include <QtCore/QMetaMethod> #include <QtCore/QMetaObject> +#include <signature.h> #include <algorithm> #include <utility> -#define SIGNAL_CLASS_NAME "Signal" -#define SIGNAL_INSTANCE_NAME "SignalInstance" #define QT_SIGNAL_SENTINEL '2' namespace PySide { @@ -101,35 +101,35 @@ static PyObject *signalCall(PyObject *, PyObject *, PyObject *); static PyObject *metaSignalCheck(PyObject *, PyObject *); -static PyMethodDef Signal_methods[] = { - {"__instancecheck__", (PyCFunction)metaSignalCheck, METH_O, NULL}, +static PyMethodDef MetaSignal_methods[] = { + {"__instancecheck__", (PyCFunction)metaSignalCheck, METH_O|METH_STATIC, NULL}, {0, 0, 0, 0} }; -static PyType_Slot PySideSignalMetaType_slots[] = { - {Py_tp_methods, (void *)Signal_methods}, +static PyType_Slot PySideMetaSignalType_slots[] = { + {Py_tp_methods, (void *)MetaSignal_methods}, {Py_tp_base, (void *)&PyType_Type}, {Py_tp_free, (void *)PyObject_GC_Del}, {Py_tp_dealloc, (void *)object_dealloc}, {0, 0} }; -static PyType_Spec PySideSignalMetaType_spec = { +static PyType_Spec PySideMetaSignalType_spec = { "PySide2.QtCore.MetaSignal", 0, // sizeof(PyHeapTypeObject) is filled in by PyType_FromSpecWithBases // which calls PyType_Ready which calls inherit_special. 0, Py_TPFLAGS_DEFAULT, - PySideSignalMetaType_slots, + PySideMetaSignalType_slots, }; -PyTypeObject *PySideSignalMetaTypeF(void) +PyTypeObject *PySideMetaSignalTypeF(void) { static PyTypeObject *type = nullptr; if (!type) { PyObject *bases = Py_BuildValue("(O)", &PyType_Type); - type = (PyTypeObject *)PyType_FromSpecWithBases(&PySideSignalMetaType_spec, bases); + type = (PyTypeObject *)PyType_FromSpecWithBases(&PySideMetaSignalType_spec, bases); Py_XDECREF(bases); } return type; @@ -146,7 +146,7 @@ static PyType_Slot PySideSignalType_slots[] = { {0, 0} }; static PyType_Spec PySideSignalType_spec = { - "PySide2.QtCore." SIGNAL_CLASS_NAME, + "PySide2.QtCore.Signal", sizeof(PySideSignal), 0, Py_TPFLAGS_DEFAULT, @@ -160,7 +160,7 @@ PyTypeObject *PySideSignalTypeF(void) if (!type) { type = (PyTypeObject *)PyType_FromSpec(&PySideSignalType_spec); PyTypeObject *hold = Py_TYPE(type); - Py_TYPE(type) = PySideSignalMetaTypeF(); + Py_TYPE(type) = PySideMetaSignalTypeF(); Py_INCREF(Py_TYPE(type)); Py_DECREF(hold); } @@ -185,7 +185,7 @@ static PyType_Slot PySideSignalInstanceType_slots[] = { {0, 0} }; static PyType_Spec PySideSignalInstanceType_spec = { - "PySide2.QtCore." SIGNAL_INSTANCE_NAME, + "PySide2.QtCore.SignalInstance", sizeof(PySideSignalInstance), 0, Py_TPFLAGS_DEFAULT, @@ -211,8 +211,8 @@ int signalTpInit(PyObject *self, PyObject *args, PyObject *kwds) emptyTuple = PyTuple_New(0); if (!PyArg_ParseTupleAndKeywords(emptyTuple, kwds, - "|sO:QtCore." SIGNAL_CLASS_NAME, const_cast<char **>(kwlist), &argName, &argArguments)) - return 0; + "|sO:QtCore.Signal", const_cast<char **>(kwlist), &argName, &argArguments)) + return -1; bool tupledArgs = false; PySideSignal *data = reinterpret_cast<PySideSignal *>(self); @@ -257,7 +257,7 @@ int signalTpInit(PyObject *self, PyObject *args, PyObject *kwds) PySide::Signal::SignalSignature(sig)); } - return 1; + return 0; } void signalFree(void *self) @@ -317,7 +317,7 @@ PyObject *signalInstanceConnect(PyObject *self, PyObject *args, PyObject *kwds) static const char *kwlist[] = {"slot", "type", nullptr}; if (!PyArg_ParseTupleAndKeywords(args, kwds, - "O|O:" SIGNAL_INSTANCE_NAME, const_cast<char **>(kwlist), &slot, &type)) + "O|O:SignalInstance", const_cast<char **>(kwlist), &slot, &type)) return 0; PySideSignalInstance *source = reinterpret_cast<PySideSignalInstance *>(self); @@ -413,7 +413,8 @@ PyObject *signalInstanceConnect(PyObject *self, PyObject *args, PyObject *kwds) if (match) { Shiboken::AutoDecRef tupleArgs(PyList_AsTuple(pyArgs)); - Shiboken::AutoDecRef pyMethod(PyObject_GetAttrString(source->d->source, "connect")); + Shiboken::AutoDecRef pyMethod(PyObject_GetAttr(source->d->source, + PySide::PyName::qtConnect())); if (pyMethod.isNull()) { // PYSIDE-79: check if pyMethod exists. PyErr_SetString(PyExc_RuntimeError, "method 'connect' vanished!"); return 0; @@ -466,7 +467,8 @@ PyObject *signalInstanceEmit(PyObject *self, PyObject *args) for (Py_ssize_t i = 0, max = PyTuple_Size(args); i < max; i++) PyList_Append(pyArgs, PyTuple_GetItem(args, i)); - Shiboken::AutoDecRef pyMethod(PyObject_GetAttrString(source->d->source, "emit")); + Shiboken::AutoDecRef pyMethod(PyObject_GetAttr(source->d->source, + PySide::PyName::qtEmit())); Shiboken::AutoDecRef tupleArgs(PyList_AsTuple(pyArgs)); return PyObject_CallObject(pyMethod, tupleArgs); @@ -531,7 +533,8 @@ PyObject *signalInstanceDisconnect(PyObject *self, PyObject *args) if (match) { Shiboken::AutoDecRef tupleArgs(PyList_AsTuple(pyArgs)); - Shiboken::AutoDecRef pyMethod(PyObject_GetAttrString(source->d->source, "disconnect")); + Shiboken::AutoDecRef pyMethod(PyObject_GetAttr(source->d->source, + PySide::PyName::qtDisconnect())); PyObject *result = PyObject_CallObject(pyMethod, tupleArgs); if (!result || result == Py_True) return result; @@ -585,9 +588,9 @@ PyObject *signalInstanceCall(PyObject *self, PyObject *args, PyObject *kw) return PyCFunction_Call(homonymousMethod, args, kw); } -static PyObject *metaSignalCheck(PyObject * /* klass */, PyObject *args) +static PyObject *metaSignalCheck(PyObject * /* klass */, PyObject *arg) { - if (PyType_IsSubtype(Py_TYPE(args), PySideSignalInstanceTypeF())) + if (PyType_IsSubtype(Py_TYPE(arg), PySideSignalInstanceTypeF())) Py_RETURN_TRUE; else Py_RETURN_FALSE; @@ -598,21 +601,36 @@ static PyObject *metaSignalCheck(PyObject * /* klass */, PyObject *args) namespace PySide { namespace Signal { +static const char *MetaSignal_SignatureStrings[] = { + "PySide2.QtCore.MetaSignal.__instancecheck__(object:object)->bool", + nullptr}; // Sentinel + +static const char *Signal_SignatureStrings[] = { + "PySide2.QtCore.Signal(*types:type,name:str=nullptr,arguments:str=nullptr)", + nullptr}; // Sentinel + +static const char *SignalInstance_SignatureStrings[] = { + "PySide2.QtCore.SignalInstance.connect(slot:object,type:type=nullptr)", + "PySide2.QtCore.SignalInstance.disconnect(slot:object=nullptr)", + "PySide2.QtCore.SignalInstance.emit(*args:typing.Any)", + nullptr}; // Sentinel + void init(PyObject *module) { - if (PyType_Ready(PySideSignalMetaTypeF()) < 0) + if (SbkSpecial_Type_Ready(module, PySideMetaSignalTypeF(), MetaSignal_SignatureStrings) < 0) return; + Py_INCREF(PySideSignalTypeF()); + PyModule_AddObject(module, "MetaSignal", reinterpret_cast<PyObject *>(PySideMetaSignalTypeF())); - if (PyType_Ready(PySideSignalTypeF()) < 0) + if (SbkSpecial_Type_Ready(module, PySideSignalTypeF(), Signal_SignatureStrings) < 0) return; - Py_INCREF(PySideSignalTypeF()); - PyModule_AddObject(module, SIGNAL_CLASS_NAME, reinterpret_cast<PyObject *>(PySideSignalTypeF())); + PyModule_AddObject(module, "Signal", reinterpret_cast<PyObject *>(PySideSignalTypeF())); - if (PyType_Ready(PySideSignalInstanceTypeF()) < 0) + if (SbkSpecial_Type_Ready(module, PySideSignalInstanceTypeF(), SignalInstance_SignatureStrings) < 0) return; - Py_INCREF(PySideSignalInstanceTypeF()); + PyModule_AddObject(module, "SignalInstance", reinterpret_cast<PyObject *>(PySideSignalInstanceTypeF())); } bool checkType(PyObject *pyObj) @@ -742,7 +760,8 @@ void instanceInitialize(PySideSignalInstance *self, PyObject *name, PySideSignal bool connect(PyObject *source, const char *signal, PyObject *callback) { - Shiboken::AutoDecRef pyMethod(PyObject_GetAttrString(source, "connect")); + Shiboken::AutoDecRef pyMethod(PyObject_GetAttr(source, + PySide::PyName::qtConnect())); if (pyMethod.isNull()) return false; diff --git a/sources/pyside2/libpyside/pysideslot.cpp b/sources/pyside2/libpyside/pysideslot.cpp index 2cdf32626..204253aa2 100644 --- a/sources/pyside2/libpyside/pysideslot.cpp +++ b/sources/pyside2/libpyside/pysideslot.cpp @@ -45,8 +45,7 @@ #include <QtCore/QMetaObject> #include <QtCore/QString> - -#define SLOT_DEC_NAME "Slot" +#include <signature.h> struct SlotData { @@ -76,7 +75,7 @@ static PyType_Slot PySideSlotType_slots[] = { {0, 0} }; static PyType_Spec PySideSlotType_spec = { - "PySide2.QtCore." SLOT_DEC_NAME, + "PySide2.QtCore.Slot", sizeof(PySideSlot), 0, Py_TPFLAGS_DEFAULT, @@ -102,9 +101,9 @@ int slotTpInit(PyObject *self, PyObject *args, PyObject *kw) if (emptyTuple == 0) emptyTuple = PyTuple_New(0); - if (!PyArg_ParseTupleAndKeywords(emptyTuple, kw, "|sO:QtCore." SLOT_DEC_NAME, + if (!PyArg_ParseTupleAndKeywords(emptyTuple, kw, "|sO:QtCore.Slot", const_cast<char **>(kwlist), &argName, &argResult)) { - return 0; + return -1; } PySideSlot *data = reinterpret_cast<PySideSlot *>(self); @@ -128,7 +127,7 @@ int slotTpInit(PyObject *self, PyObject *args, PyObject *kw) data->slotData->resultType = argResult ? PySide::Signal::getTypeName(argResult) : PySide::Signal::voidType(); - return 1; + return 0; } PyObject *slotCall(PyObject *self, PyObject *args, PyObject * /* kw */) @@ -177,15 +176,20 @@ PyObject *slotCall(PyObject *self, PyObject *args, PyObject * /* kw */) } // extern "C" -namespace PySide { namespace Slot { +namespace PySide { +namespace Slot { + +static const char *Slot_SignatureStrings[] = { + "PySide2.QtCore.Slot(*types:type,name:str=nullptr,result:str=nullptr)->typing.Callable[...,typing.Optional[str]]", + nullptr}; // Sentinel void init(PyObject *module) { - if (PyType_Ready(PySideSlotTypeF()) < 0) + if (SbkSpecial_Type_Ready(module, PySideSlotTypeF(), Slot_SignatureStrings) < 0) return; Py_INCREF(PySideSlotTypeF()); - PyModule_AddObject(module, SLOT_DEC_NAME, reinterpret_cast<PyObject *>(PySideSlotTypeF())); + PyModule_AddObject(module, "Slot", reinterpret_cast<PyObject *>(PySideSlotTypeF())); } } // namespace Slot diff --git a/sources/pyside2/libpyside/pysidestaticstrings.cpp b/sources/pyside2/libpyside/pysidestaticstrings.cpp new file mode 100644 index 000000000..82e233621 --- /dev/null +++ b/sources/pyside2/libpyside/pysidestaticstrings.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt for Python. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "pysidestaticstrings.h" +#include <sbkstring.h> + +#define STATIC_STRING_IMPL(funcName, value) \ +PyObject *funcName() \ +{ \ + static PyObject *const s = Shiboken::String::createStaticString(value); \ + return s; \ +} + +namespace PySide +{ +namespace PyName +{ +STATIC_STRING_IMPL(qtStaticMetaObject, "staticMetaObject") +STATIC_STRING_IMPL(qtConnect, "connect") +STATIC_STRING_IMPL(qtDisconnect, "disconnect") +STATIC_STRING_IMPL(qtEmit, "emit") +} // namespace PyName +} // namespace PySide diff --git a/sources/pyside2/libpyside/pysidestaticstrings.h b/sources/pyside2/libpyside/pysidestaticstrings.h new file mode 100644 index 000000000..1d5700c51 --- /dev/null +++ b/sources/pyside2/libpyside/pysidestaticstrings.h @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt for Python. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PYSIDESTRINGS_H +#define PYSIDESTRINGS_H + +#include <sbkpython.h> + +namespace PySide +{ +namespace PyName +{ +PyObject *qtStaticMetaObject(); +PyObject *qtConnect(); +PyObject *qtDisconnect(); +PyObject *qtEmit(); +} // namespace PyName +} // namespace PySide + +#endif // PYSIDESTRINGS_H diff --git a/sources/pyside2/libpyside/signalmanager.cpp b/sources/pyside2/libpyside/signalmanager.cpp index 0895cc682..c21a3e565 100644 --- a/sources/pyside2/libpyside/signalmanager.cpp +++ b/sources/pyside2/libpyside/signalmanager.cpp @@ -53,6 +53,7 @@ #include <gilstate.h> #include <sbkconverter.h> #include <sbkstring.h> +#include <sbkstaticstrings.h> #include <QtCore/QDebug> #include <QtCore/QHash> @@ -77,8 +78,6 @@ #define PYSIDE_SIGNAL '2' #include "globalreceiverv2.h" -#define PYTHON_TYPE "PyObject" - namespace { static PyObject *metaObjectAttr = 0; @@ -171,7 +170,7 @@ QDataStream &operator<<(QDataStream &out, const PyObjectWrapper &myObj) Shiboken::GilState gil; if (!reduce_func) { Shiboken::AutoDecRef pickleModule(PyImport_ImportModule("pickle")); - reduce_func = PyObject_GetAttrString(pickleModule, "dumps"); + reduce_func = PyObject_GetAttr(pickleModule, Shiboken::PyName::dumps()); } Shiboken::AutoDecRef repr(PyObject_CallFunctionObjArgs(reduce_func, (PyObject *)myObj, NULL)); if (repr.object()) { @@ -202,7 +201,7 @@ QDataStream &operator>>(QDataStream &in, PyObjectWrapper &myObj) Shiboken::GilState gil; if (!eval_func) { Shiboken::AutoDecRef pickleModule(PyImport_ImportModule("pickle")); - eval_func = PyObject_GetAttrString(pickleModule, "loads"); + eval_func = PyObject_GetAttr(pickleModule, Shiboken::PyName::loads()); } QByteArray repr; @@ -268,15 +267,15 @@ SignalManager::SignalManager() : m_d(new SignalManagerPrivate) using namespace Shiboken; // Register PyObject type to use in queued signal and slot connections - qRegisterMetaType<PyObjectWrapper>(PYTHON_TYPE); - qRegisterMetaTypeStreamOperators<PyObjectWrapper>(PYTHON_TYPE); + qRegisterMetaType<PyObjectWrapper>("PyObject"); + qRegisterMetaTypeStreamOperators<PyObjectWrapper>("PyObject"); qRegisterMetaTypeStreamOperators<PyObjectWrapper>("PyObjectWrapper"); qRegisterMetaTypeStreamOperators<PyObjectWrapper>("PySide::PyObjectWrapper"); SbkConverter *converter = Shiboken::Conversions::createConverter(&PyBaseObject_Type, nullptr); Shiboken::Conversions::setCppPointerToPythonFunction(converter, PyObject_PTR_CppToPython_PyObject); Shiboken::Conversions::setPythonToCppPointerFunctions(converter, PyObject_PythonToCpp_PyObject_PTR, is_PyObject_PythonToCpp_PyObject_PTR_Convertible); - Shiboken::Conversions::registerConverterName(converter, PYTHON_TYPE); + Shiboken::Conversions::registerConverterName(converter, "PyObject"); Shiboken::Conversions::registerConverterName(converter, "object"); Shiboken::Conversions::registerConverterName(converter, "PyObjectWrapper"); Shiboken::Conversions::registerConverterName(converter, "PySide::PyObjectWrapper"); |