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/pysideweakref.cpp | 74 +++++++++-------------------- 1 file changed, 23 insertions(+), 51 deletions(-) (limited to 'sources/pyside2/libpyside/pysideweakref.cpp') diff --git a/sources/pyside2/libpyside/pysideweakref.cpp b/sources/pyside2/libpyside/pysideweakref.cpp index c31334ee5..906aafd7c 100644 --- a/sources/pyside2/libpyside/pysideweakref.cpp +++ b/sources/pyside2/libpyside/pysideweakref.cpp @@ -40,6 +40,7 @@ #include "pysideweakref.h" #include +#include typedef struct { PyObject_HEAD @@ -50,56 +51,27 @@ typedef struct { static PyObject* CallableObject_call(PyObject* callable_object, PyObject* args, PyObject* kw); -static PyTypeObject PySideCallableObjectType = { - PyVarObject_HEAD_INIT(0, 0) +static PyType_Slot PySideCallableObjectType_slots[] = { + {Py_tp_call, (void *)CallableObject_call}, + {Py_tp_dealloc, (void *)SbkDummyDealloc}, + {0, 0} +}; +static PyType_Spec PySideCallableObjectType_spec = { const_cast("PySide.Callable"), - sizeof(PySideCallableObject), /*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 */ - CallableObject_call, /*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 */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - 0, /* 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 */ + sizeof(PySideCallableObject), + 0, + Py_TPFLAGS_DEFAULT, + PySideCallableObjectType_slots, }; + +static PyTypeObject *PySideCallableObjectTypeF(void) +{ + static PyTypeObject *type = + (PyTypeObject *)PyType_FromSpec(&PySideCallableObjectType_spec); + return type; +} + static PyObject *CallableObject_call(PyObject *callable_object, PyObject *args, PyObject * /* kw */) { PySideCallableObject* obj = reinterpret_cast(callable_object); @@ -116,13 +88,13 @@ PyObject* create(PyObject* obj, PySideWeakRefFunction func, void* userData) if (obj == Py_None) return 0; - if (Py_TYPE(&PySideCallableObjectType) == 0) + if (Py_TYPE(PySideCallableObjectTypeF()) == 0) { - Py_TYPE(&PySideCallableObjectType) = &PyType_Type; - PyType_Ready(&PySideCallableObjectType); + Py_TYPE(PySideCallableObjectTypeF()) = &PyType_Type; + PyType_Ready(PySideCallableObjectTypeF()); } - PySideCallableObject* callable = PyObject_New(PySideCallableObject, &PySideCallableObjectType); + PySideCallableObject* callable = PyObject_New(PySideCallableObject, PySideCallableObjectTypeF()); if (!callable || PyErr_Occurred()) return 0; -- cgit v1.2.3