summaryrefslogtreecommitdiff
path: root/gi/pygi-struct.c
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2017-07-12 08:35:07 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2017-07-12 08:35:08 +0900
commitdf82aa0a770d4b3e52e96eb5c60b528ddcdb2343 (patch)
treebbf6d1c2270fe7057773ff1c2cf578ff40f704da /gi/pygi-struct.c
parent095413828bd9b33e57b352f9ca80473172611202 (diff)
downloadpygobject2-df82aa0a770d4b3e52e96eb5c60b528ddcdb2343.tar.gz
pygobject2-df82aa0a770d4b3e52e96eb5c60b528ddcdb2343.tar.bz2
pygobject2-df82aa0a770d4b3e52e96eb5c60b528ddcdb2343.zip
Imported Upstream version 2.26.0upstream/2.26.0
Change-Id: I616aeca320e366d54dd6e188c260b64639305c49 Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'gi/pygi-struct.c')
-rw-r--r--gi/pygi-struct.c55
1 files changed, 16 insertions, 39 deletions
diff --git a/gi/pygi-struct.c b/gi/pygi-struct.c
index 2f1ce42..c2e1f4d 100644
--- a/gi/pygi-struct.c
+++ b/gi/pygi-struct.c
@@ -25,19 +25,28 @@
#include <pygobject.h>
#include <girepository.h>
+#include <pyglib-python-compat.h>
static void
_struct_dealloc (PyGIStruct *self)
{
+ GIBaseInfo *info = _pygi_object_get_gi_info (
+ (PyObject *) self,
+ &PyGIStructInfo_Type);
+
PyObject_GC_UnTrack ( (PyObject *) self);
PyObject_ClearWeakRefs ( (PyObject *) self);
- if (self->free_on_dealloc) {
+ if (info != NULL && g_struct_info_is_foreign ( (GIStructInfo *) info)) {
+ pygi_struct_foreign_release (info, ( (PyGPointer *) self)->pointer);
+ } else if (self->free_on_dealloc) {
g_free ( ( (PyGPointer *) self)->pointer);
}
- ( (PyGPointer *) self)->ob_type->tp_free ( (PyObject *) self);
+ g_base_info_unref (info);
+
+ Py_TYPE( (PyGPointer *) self )->tp_free ( (PyObject *) self);
}
static PyObject *
@@ -48,7 +57,6 @@ _struct_new (PyTypeObject *type,
static char *kwlist[] = { NULL };
GIBaseInfo *info;
- gboolean is_simple;
gsize size;
gpointer pointer;
PyObject *self = NULL;
@@ -92,41 +100,7 @@ _struct_init (PyObject *self,
return 0;
}
-
-PyTypeObject PyGIStruct_Type = {
- PyObject_HEAD_INIT (NULL)
- 0,
- "gi.Struct", /* tp_name */
- sizeof (PyGIStruct), /* tp_basicsize */
- 0, /* tp_itemsize */
- (destructor) _struct_dealloc, /* tp_dealloc */
- (printfunc) NULL, /* tp_print */
- (getattrfunc) NULL, /* tp_getattr */
- (setattrfunc) NULL, /* tp_setattr */
- (cmpfunc) NULL, /* tp_compare */
- (reprfunc) NULL, /* tp_repr */
- NULL, /* tp_as_number */
- NULL, /* tp_as_sequence */
- NULL, /* tp_as_mapping */
- (hashfunc) NULL, /* tp_hash */
- (ternaryfunc) NULL, /* tp_call */
- (reprfunc) NULL, /* tp_str */
- (getattrofunc) NULL, /* tp_getattro */
- (setattrofunc) NULL, /* tp_setattro */
- NULL, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
- NULL, /* tp_doc */
- (traverseproc) NULL, /* tp_traverse */
- (inquiry) NULL, /* tp_clear */
- (richcmpfunc) NULL, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- (getiterfunc) NULL, /* tp_iter */
- (iternextfunc) NULL, /* tp_iternext */
- NULL, /* tp_methods */
- NULL, /* tp_members */
- NULL, /* tp_getset */
- (PyTypeObject *) NULL, /* tp_base */
-};
+PYGLIB_DEFINE_TYPE("gi.Struct", PyGIStruct_Type, PyGIStruct);
PyObject *
_pygi_struct_new (PyTypeObject *type,
@@ -158,10 +132,13 @@ _pygi_struct_new (PyTypeObject *type,
void
_pygi_struct_register_types (PyObject *m)
{
- PyGIStruct_Type.ob_type = &PyType_Type;
+ Py_TYPE(&PyGIStruct_Type) = &PyType_Type;
PyGIStruct_Type.tp_base = &PyGPointer_Type;
PyGIStruct_Type.tp_new = (newfunc) _struct_new;
PyGIStruct_Type.tp_init = (initproc) _struct_init;
+ PyGIStruct_Type.tp_dealloc = (destructor) _struct_dealloc;
+ PyGIStruct_Type.tp_flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE);
+
if (PyType_Ready (&PyGIStruct_Type))
return;
if (PyModule_AddObject (m, "Struct", (PyObject *) &PyGIStruct_Type))