Commit f1229222 authored by Christoph Reiter's avatar Christoph Reiter 🐍

Merge branch 'gi-boxed-remove-del' into 'master'

Remove gi.Boxed.__del__ and GObject.Value.__del__

See merge request GNOME/pygobject!106
parents d9ee92df c9f127b8
......@@ -524,7 +524,10 @@ class Source(GLib.Source):
def __del__(self):
if hasattr(self, '__pygi_custom_source'):
self.destroy()
super(Source, self).__del__()
# XXX: We have to unref the underlying source while the Python
# wrapper is still valid, so the source can call into the
# wrapper methods for the finalized callback.
self._clear_boxed()
def set_callback(self, fn, user_data=None):
if hasattr(self, '__pygi_custom_source'):
......
......@@ -209,14 +209,6 @@ class Value(GObjectModule.Value):
if py_value is not None:
self.set_value(py_value)
def __del__(self):
if self._is_valid:
if self._free_on_dealloc and self.g_type != TYPE_INVALID:
self.unset()
# We must call base class __del__() after unset.
super(Value, self).__del__()
def set_boxed(self, boxed):
# Workaround the introspection marshalers inability to know
# these methods should be marshaling boxed types. This is because
......
......@@ -28,33 +28,49 @@
#include <girepository.h>
static void
boxed_dealloc (PyGIBoxed *self)
{
Py_TYPE (self)->tp_free ((PyObject *)self);
}
struct _PyGIBoxed {
PyGBoxed base;
gboolean slice_allocated;
gsize size;
};
static PyObject *
boxed_del (PyGIBoxed *self)
static void
boxed_clear (PyGIBoxed *self)
{
GType g_type;
gpointer boxed = pyg_boxed_get_ptr (self);
GType g_type = ((PyGBoxed *)self)->gtype;
if ( ( (PyGBoxed *) self)->free_on_dealloc && boxed != NULL) {
if (self->slice_allocated) {
if (g_type && g_type_is_a (g_type, G_TYPE_VALUE))
g_value_unset (boxed);
g_slice_free1 (self->size, boxed);
self->slice_allocated = FALSE;
self->size = 0;
} else {
g_type = pyg_type_from_object ( (PyObject *) self);
g_boxed_free (g_type, boxed);
}
}
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)
{
......@@ -187,18 +203,6 @@ pygi_boxed_new (PyTypeObject *type,
return (PyObject *) self;
}
static PyObject *
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:
*
......@@ -218,19 +222,13 @@ 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 }
};
......@@ -247,7 +245,6 @@ pygi_boxed_register_types (PyObject *m)
PyGIBoxed_Type.tp_init = (initproc) boxed_init;
PyGIBoxed_Type.tp_dealloc = (destructor) boxed_dealloc;
PyGIBoxed_Type.tp_flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE);
PyGIBoxed_Type.tp_getset = pygi_boxed_getsets;
PyGIBoxed_Type.tp_methods = boxed_methods;
if (PyType_Ready (&PyGIBoxed_Type) < 0)
......
......@@ -26,11 +26,7 @@
G_BEGIN_DECLS
typedef struct {
PyGBoxed base;
gboolean slice_allocated;
gsize size;
} PyGIBoxed;
typedef struct _PyGIBoxed PyGIBoxed;
extern PyTypeObject PyGIBoxed_Type;
......
......@@ -666,12 +666,6 @@ class TestGValue(unittest.TestCase):
value.set_value(42.0)
self.assertEqual(value.get_value(), 42)
def test_multi_del(self):
value = GObject.Value(str, 'foo_bar')
value.__del__()
value.__del__()
del value
def test_string(self):
value = GObject.Value(str, 'foo_bar')
self.assertEqual(value.g_type, GObject.TYPE_STRING)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment