diff options
| author | Mathieu Duponchelle <mathieu@centricular.com> | 2018-02-15 23:32:08 +0100 |
|---|---|---|
| committer | Mathieu Duponchelle <mathieu@centricular.com> | 2018-02-16 17:56:16 +0100 |
| commit | d08e244d011121f8ffd5c21437e0f11fe9545bbf (patch) | |
| tree | 42ff6f31fbd199a6125422354cb621dc2c99ba11 /gi/pygi-boxed.c | |
| parent | c56b4510649dae58519681c1a53aed85d598139e (diff) | |
| download | pygobject-d08e244d011121f8ffd5c21437e0f11fe9545bbf.tar.gz | |
Revert "Revert "Revert "Refactor boxed wrapper memory management strategy"""
This reverts commit a506d5e3c64321c43a4ce7c2a72ca8d36e985999.
Diffstat (limited to 'gi/pygi-boxed.c')
| -rw-r--r-- | gi/pygi-boxed.c | 32 |
1 files changed, 7 insertions, 25 deletions
diff --git a/gi/pygi-boxed.c b/gi/pygi-boxed.c index e9014f20..fa690bb3 100644 --- a/gi/pygi-boxed.c +++ b/gi/pygi-boxed.c @@ -113,7 +113,7 @@ _boxed_new (PyTypeObject *type, goto out; } - self = (PyGIBoxed *) _pygi_boxed_new (type, boxed, FALSE, size); + self = (PyGIBoxed *) _pygi_boxed_new (type, boxed, TRUE, size); if (self == NULL) { g_slice_free1 (size, boxed); goto out; @@ -149,48 +149,30 @@ _boxed_init (PyObject *self, PYGLIB_DEFINE_TYPE("gi.Boxed", PyGIBoxed_Type, PyGIBoxed); PyObject * -_pygi_boxed_new (PyTypeObject *pytype, +_pygi_boxed_new (PyTypeObject *type, gpointer boxed, - gboolean copy_boxed, + gboolean free_on_dealloc, gsize allocated_slice) { PyGIBoxed *self; - GType gtype; if (!boxed) { Py_RETURN_NONE; } - if (!PyType_IsSubtype (pytype, &PyGIBoxed_Type)) { + if (!PyType_IsSubtype (type, &PyGIBoxed_Type)) { PyErr_SetString (PyExc_TypeError, "must be a subtype of gi.Boxed"); return NULL; } - gtype = pyg_type_from_object ((PyObject *)pytype); - - /* Boxed objects with slice allocation means they come from caller allocated - * out arguments. In this case copy_boxed does not make sense because we - * already own the slice allocated memory and we should be receiving full - * ownership transfer. */ - if (copy_boxed) { - g_assert (allocated_slice == 0); - boxed = g_boxed_copy (gtype, boxed); - } - - self = (PyGIBoxed *) pytype->tp_alloc (pytype, 0); + self = (PyGIBoxed *) type->tp_alloc (type, 0); if (self == NULL) { return NULL; } - /* We always free on dealloc because we always own the memory due to: - * 1) copy_boxed == TRUE - * 2) allocated_slice > 0 - * 3) otherwise the mode is assumed "transfer everything". - */ - ((PyGBoxed *)self)->free_on_dealloc = TRUE; - ((PyGBoxed *)self)->gtype = gtype; + ( (PyGBoxed *) self)->gtype = pyg_type_from_object ( (PyObject *) type); + ( (PyGBoxed *) self)->free_on_dealloc = free_on_dealloc; pyg_boxed_set_ptr (self, boxed); - if (allocated_slice > 0) { self->size = allocated_slice; self->slice_allocated = TRUE; |
