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/libpyside/pysideslot.cpp | 80 +++++++++++--------------------- 1 file changed, 27 insertions(+), 53 deletions(-) (limited to 'sources/pyside2/libpyside/pysideslot.cpp') diff --git a/sources/pyside2/libpyside/pysideslot.cpp b/sources/pyside2/libpyside/pysideslot.cpp index 8f307260d..db1a7d9ed 100644 --- a/sources/pyside2/libpyside/pysideslot.cpp +++ b/sources/pyside2/libpyside/pysideslot.cpp @@ -62,55 +62,29 @@ static int slotTpInit(PyObject*, PyObject*, PyObject*); static PyObject* slotCall(PyObject*, PyObject*, PyObject*); // Class Definition ----------------------------------------------- -static PyTypeObject PySideSlotType = { - PyVarObject_HEAD_INIT(0, 0) - "PySide2.QtCore." SLOT_DEC_NAME, /*tp_name*/ - sizeof(PySideSlot), /*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 */ - slotCall, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT, /*tp_flags*/ - SLOT_DEC_NAME, /*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 */ - 0, /*tp_base */ - 0, /*tp_dict */ - 0, /*tp_descr_get */ - 0, /*tp_descr_set */ - 0, /*tp_dictoffset */ - slotTpInit, /*tp_init */ - 0, /*tp_alloc */ - PyType_GenericNew, /*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*/ +static PyType_Slot PySideSlotType_slots[] = { + {Py_tp_call, (void *)slotCall}, + {Py_tp_init, (void *)slotTpInit}, + {Py_tp_new, (void *)PyType_GenericNew}, + {Py_tp_dealloc, (void *)SbkDummyDealloc}, + {0, 0} }; +static PyType_Spec PySideSlotType_spec = { + "PySide2.QtCore." SLOT_DEC_NAME, + sizeof(PySideSlot), + 0, + Py_TPFLAGS_DEFAULT, + PySideSlotType_slots, +}; + + +static PyTypeObject *PySideSlotTypeF(void) +{ + static PyTypeObject *type = nullptr; + if (!type) + type = (PyTypeObject *)PyType_FromSpec(&PySideSlotType_spec); + return type; +} int slotTpInit(PyObject *self, PyObject *args, PyObject *kw) { @@ -139,7 +113,7 @@ int slotTpInit(PyObject *self, PyObject *args, PyObject *kw) data->args = typeName; } } else { - PyErr_Format(PyExc_TypeError, "Unknown signal argument type: %s", argType->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Unknown signal argument type: %s", PepType((Py_TYPE(argType)))->tp_name); return -1; } } @@ -166,7 +140,7 @@ PyObject *slotCall(PyObject *self, PyObject *args, PyObject * /* kw */) PySideSlot *data = reinterpret_cast(self); if (!data->slotName) { - PyObject *funcName = reinterpret_cast(callback)->func_name; + PyObject *funcName = PepFunction_GetName(callback); data->slotName = strdup(Shiboken::String::toCString(funcName)); } @@ -209,11 +183,11 @@ namespace PySide { namespace Slot { void init(PyObject* module) { - if (PyType_Ready(&PySideSlotType) < 0) + if (PyType_Ready(PySideSlotTypeF()) < 0) return; - Py_INCREF(&PySideSlotType); - PyModule_AddObject(module, SLOT_DEC_NAME, reinterpret_cast(&PySideSlotType)); + Py_INCREF(PySideSlotTypeF()); + PyModule_AddObject(module, SLOT_DEC_NAME, reinterpret_cast(PySideSlotTypeF())); } } // namespace Slot -- cgit v1.2.3