summaryrefslogtreecommitdiff
path: root/gi/pygi-boxed.c
diff options
context:
space:
mode:
authorChristoph Reiter <reiter.christoph@gmail.com>2019-01-15 14:45:55 +0100
committerChristoph Reiter <reiter.christoph@gmail.com>2019-01-15 15:43:42 +0100
commit22656c4bc33e62aa8387df7accb73ad95fc8e8e9 (patch)
treeb2a061df200b35165dbef772b866c5d52761a64a /gi/pygi-boxed.c
parent012973c4064a622e0d9a886464192cc97283360d (diff)
downloadpygobject-22656c4bc33e62aa8387df7accb73ad95fc8e8e9.tar.gz
boxed: remove __del__ implementation and free in tp_dealloc
This allows us to assume that the wrapper is always valid and remove the _is_valid attribute. One difference now is that g_boxed_free() is called when the wrapper can no longer be used and that breaks the custom glib sources where g_boxed_free() triggers the finalize callback which tries to call into a method of the wrapper. To work around this provide a _clear_boxed() method which allows the wrapper to free the underlying boxed in __del__ where the wrapper is still usable.
Diffstat (limited to 'gi/pygi-boxed.c')
-rw-r--r--gi/pygi-boxed.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/gi/pygi-boxed.c b/gi/pygi-boxed.c
index 32fa477c..90c57c72 100644
--- a/gi/pygi-boxed.c
+++ b/gi/pygi-boxed.c
@@ -35,13 +35,7 @@ struct _PyGIBoxed {
};
static void
-boxed_dealloc (PyGIBoxed *self)
-{
- Py_TYPE (self)->tp_free ((PyObject *)self);
-}
-
-static PyObject *
-boxed_del (PyGIBoxed *self)
+boxed_clear (PyGIBoxed *self)
{
gpointer boxed = pyg_boxed_get_ptr (self);
@@ -55,10 +49,25 @@ boxed_del (PyGIBoxed *self)
}
}
pyg_boxed_set_ptr (self, NULL);
+}
+
+static PyObject *
+boxed_clear_wrapper (PyGIBoxed *self)
+{
+ boxed_clear (self);
Py_RETURN_NONE;
}
+
+static void
+boxed_dealloc (PyGIBoxed *self)
+{
+ boxed_clear (self);
+
+ Py_TYPE (self)->tp_free ((PyObject *)self);
+}
+
void *
pygi_boxed_alloc (GIBaseInfo *info, gsize *size_out)
{
@@ -197,12 +206,6 @@ boxed_get_free_on_dealloc(PyGIBoxed *self, void *closure)
return pygi_gboolean_to_py( ((PyGBoxed *)self)->free_on_dealloc );
}
-static PyObject *
-boxed_get_is_valid (PyGIBoxed *self, void *closure)
-{
- return pygi_gboolean_to_py (pyg_boxed_get_ptr (self) != NULL);
-}
-
/**
* pygi_boxed_copy_in_place:
*
@@ -222,19 +225,18 @@ pygi_boxed_copy_in_place (PyGIBoxed *self)
if (ptr)
copy = g_boxed_copy (pygboxed->gtype, ptr);
- boxed_del (self);
+ boxed_clear (self);
pyg_boxed_set_ptr (pygboxed, copy);
pygboxed->free_on_dealloc = TRUE;
}
static PyGetSetDef pygi_boxed_getsets[] = {
{ "_free_on_dealloc", (getter)boxed_get_free_on_dealloc, (setter)0 },
- { "_is_valid", (getter)boxed_get_is_valid, (setter)0 },
{ NULL, 0, 0 }
};
static PyMethodDef boxed_methods[] = {
- { "__del__", (PyCFunction)boxed_del, METH_NOARGS },
+ { "_clear_boxed", (PyCFunction)boxed_clear_wrapper, METH_NOARGS },
{ NULL, NULL, 0 }
};