aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/libpyside/pysideproperty.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sources/pyside6/libpyside/pysideproperty.cpp')
-rw-r--r--sources/pyside6/libpyside/pysideproperty.cpp86
1 files changed, 47 insertions, 39 deletions
diff --git a/sources/pyside6/libpyside/pysideproperty.cpp b/sources/pyside6/libpyside/pysideproperty.cpp
index 1961f566e..3720815db 100644
--- a/sources/pyside6/libpyside/pysideproperty.cpp
+++ b/sources/pyside6/libpyside/pysideproperty.cpp
@@ -8,6 +8,7 @@
#include "pysidesignal_p.h"
#include <shiboken.h>
+#include <pep384ext.h>
#include <signature.h>
using namespace Shiboken;
@@ -58,34 +59,39 @@ static PyGetSetDef PySidePropertyType_getset[] = {
{nullptr, nullptr, nullptr, nullptr, nullptr}
};
-static PyType_Slot PySidePropertyType_slots[] = {
- {Py_tp_dealloc, reinterpret_cast<void *>(qpropertyDeAlloc)},
- {Py_tp_call, reinterpret_cast<void *>(qPropertyCall)},
- {Py_tp_traverse, reinterpret_cast<void *>(qpropertyTraverse)},
- {Py_tp_clear, reinterpret_cast<void *>(qpropertyClear)},
- {Py_tp_methods, reinterpret_cast<void *>(PySidePropertyMethods)},
- {Py_tp_init, reinterpret_cast<void *>(qpropertyTpInit)},
- {Py_tp_new, reinterpret_cast<void *>(qpropertyTpNew)},
- {Py_tp_getset, PySidePropertyType_getset},
- {Py_tp_del, reinterpret_cast<void *>(PyObject_GC_Del)},
- {0, nullptr}
-};
+static PyTypeObject *createPropertyType()
+{
+ PyType_Slot PySidePropertyType_slots[] = {
+ {Py_tp_dealloc, reinterpret_cast<void *>(qpropertyDeAlloc)},
+ {Py_tp_call, reinterpret_cast<void *>(qPropertyCall)},
+ {Py_tp_traverse, reinterpret_cast<void *>(qpropertyTraverse)},
+ {Py_tp_clear, reinterpret_cast<void *>(qpropertyClear)},
+ {Py_tp_methods, reinterpret_cast<void *>(PySidePropertyMethods)},
+ {Py_tp_init, reinterpret_cast<void *>(qpropertyTpInit)},
+ {Py_tp_new, reinterpret_cast<void *>(qpropertyTpNew)},
+ {Py_tp_getset, PySidePropertyType_getset},
+ {Py_tp_del, reinterpret_cast<void *>(PyObject_GC_Del)},
+ {0, nullptr}
+ };
-static PyType_Spec PySidePropertyType_spec = {
- "2:PySide6.QtCore.Property",
- sizeof(PySideProperty),
- 0,
- Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_BASETYPE,
- PySidePropertyType_slots,
-};
+ PyType_Spec PySidePropertyType_spec = {
+ "2:PySide6.QtCore.Property",
+ sizeof(PySideProperty),
+ 0,
+ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_BASETYPE,
+ PySidePropertyType_slots,
+ };
+ return SbkType_FromSpec(&PySidePropertyType_spec);
+}
PyTypeObject *PySideProperty_TypeF(void)
{
- static auto *type = SbkType_FromSpec(&PySidePropertyType_spec);
+ static auto *type = createPropertyType();
return type;
}
+PySidePropertyPrivate::PySidePropertyPrivate() noexcept = default;
PySidePropertyPrivate::~PySidePropertyPrivate() = default;
PyObject *PySidePropertyPrivate::getValue(PyObject *source)
@@ -174,14 +180,14 @@ void PySidePropertyPrivate::metaCall(PyObject *source, QMetaObject::Call call, v
static PyObject *qpropertyTpNew(PyTypeObject *subtype, PyObject * /* args */, PyObject * /* kwds */)
{
- PySideProperty *me = reinterpret_cast<PySideProperty *>(subtype->tp_alloc(subtype, 0));
+ auto *me = PepExt_TypeCallAlloc<PySideProperty>(subtype, 0);
me->d = new PySidePropertyPrivate;
return reinterpret_cast<PyObject *>(me);
}
static int qpropertyTpInit(PyObject *self, PyObject *args, PyObject *kwds)
{
- PyObject *type = nullptr;
+ PyObject *type{};
auto data = reinterpret_cast<PySideProperty *>(self);
PySidePropertyPrivate *pData = data->d;
@@ -190,6 +196,13 @@ static int qpropertyTpInit(PyObject *self, PyObject *args, PyObject *kwds)
"user", "constant", "final", nullptr};
char *doc{};
+ Py_CLEAR(pData->pyTypeObject);
+ Py_CLEAR(pData->fget);
+ Py_CLEAR(pData->fset);
+ Py_CLEAR(pData->freset);
+ Py_CLEAR(pData->fdel);
+ Py_CLEAR(pData->notify);
+
if (!PyArg_ParseTupleAndKeywords(args, kwds,
"O|OOOOsObbbbbb:QtCore.Property",
const_cast<char **>(kwlist),
@@ -246,7 +259,7 @@ static void qpropertyDeAlloc(PyObject *self)
Py_DECREF(Py_TYPE(self));
}
PyObject_GC_UnTrack(self);
- Py_TYPE(self)->tp_free(self);
+ PepExt_TypeCallFree(self);
}
// Create a copy of the property to prevent the @property.setter from modifying
@@ -255,7 +268,7 @@ static void qpropertyDeAlloc(PyObject *self)
static PyObject *
_property_copy(PyObject *old, PyObject *get, PyObject *set, PyObject *reset, PyObject *del)
{
- PySideProperty *pold = reinterpret_cast<PySideProperty *>(old);
+ auto *pold = reinterpret_cast<PySideProperty *>(old);
PySidePropertyPrivate *pData = pold->d;
AutoDecRef type(PyObject_Type(old));
@@ -409,6 +422,7 @@ static int qpropertyTraverse(PyObject *self, visitproc visit, void *arg)
Py_VISIT(data->freset);
Py_VISIT(data->fdel);
Py_VISIT(data->notify);
+ Py_VISIT(data->pyTypeObject);
return 0;
}
@@ -423,7 +437,7 @@ static int qpropertyClear(PyObject *self)
Py_CLEAR(data->freset);
Py_CLEAR(data->fdel);
Py_CLEAR(data->notify);
- Py_XDECREF(data->pyTypeObject);
+ Py_CLEAR(data->pyTypeObject);
delete data;
reinterpret_cast<PySideProperty *>(self)->d = nullptr;
@@ -432,16 +446,14 @@ static int qpropertyClear(PyObject *self)
} // extern "C"
-namespace {
-
static PyObject *getFromType(PyTypeObject *type, PyObject *name)
{
- PyObject *attr = nullptr;
- attr = PyDict_GetItem(type->tp_dict, name);
+ AutoDecRef tpDict(PepType_GetDict(type));
+ auto *attr = PyDict_GetItem(tpDict.object(), name);
if (!attr) {
PyObject *bases = type->tp_bases;
- int size = PyTuple_GET_SIZE(bases);
- for(int i=0; i < size; i++) {
+ const Py_ssize_t size = PyTuple_GET_SIZE(bases);
+ for (Py_ssize_t i = 0; i < size; ++i) {
PyObject *base = PyTuple_GET_ITEM(bases, i);
attr = getFromType(reinterpret_cast<PyTypeObject *>(base), name);
if (attr)
@@ -451,10 +463,7 @@ static PyObject *getFromType(PyTypeObject *type, PyObject *name)
return attr;
}
-} //namespace
-
-
-namespace PySide { namespace Property {
+namespace PySide::Property {
static const char *Property_SignatureStrings[] = {
"PySide6.QtCore.Property(self,type:type,fget:typing.Callable=None,fset:typing.Callable=None,"
@@ -466,6 +475,7 @@ static const char *Property_SignatureStrings[] = {
"PySide6.QtCore.Property.read(self,fget:typing.Callable)->PySide6.QtCore.Property",
"PySide6.QtCore.Property.setter(self,fset:typing.Callable)->PySide6.QtCore.Property",
"PySide6.QtCore.Property.write(self,fset:typing.Callable)->PySide6.QtCore.Property",
+ "PySide6.QtCore.Property.__call__(self, func:typing.Callable)->PySide6.QtCore.Property",
nullptr}; // Sentinel
void init(PyObject *module)
@@ -569,9 +579,8 @@ bool isFinal(const PySideProperty *self)
const char *getNotifyName(PySideProperty *self)
{
if (self->d->notifySignature.isEmpty()) {
- PyObject *str = PyObject_Str(self->d->notify);
+ AutoDecRef str(PyObject_Str(self->d->notify));
self->d->notifySignature = Shiboken::String::toCString(str);
- Py_DECREF(str);
}
return self->d->notifySignature.isEmpty()
@@ -588,5 +597,4 @@ PyObject *getTypeObject(const PySideProperty *self)
return self->d->pyTypeObject;
}
-} //namespace Property
-} //namespace PySide
+} //namespace PySide::Property