Commit d4054be9 authored by Martin Pitt's avatar Martin Pitt
Browse files

Wrap GLib.Source.is_destroyed() method

Based on original patch from Bryan Silverthorn.

https://bugzilla.gnome.org/show_bug.cgi?id=524719
parent 05030a95
......@@ -129,6 +129,20 @@ pyg_source_destroy(PyGSource *self)
return Py_None;
}
static PyObject *
pyg_source_is_destroyed(PyGSource *self)
{
PyObject *result;
if (self->source == NULL || g_source_is_destroyed(self->source))
result = Py_True;
else
result = Py_False;
Py_INCREF(result);
return result;
}
static PyObject *
pyg_source_set_callback(PyGSource *self, PyObject *args)
{
......@@ -255,6 +269,7 @@ pyg_source_get_current_time(PyGSource *self)
static PyMethodDef pyg_source_methods[] = {
{ "attach", (PyCFunction)pyg_source_attach, METH_VARARGS|METH_KEYWORDS },
{ "destroy", (PyCFunction)pyg_source_destroy, METH_NOARGS },
{ "is_destroyed", (PyCFunction)pyg_source_is_destroyed, METH_NOARGS },
{ "set_callback", (PyCFunction)pyg_source_set_callback, METH_VARARGS },
{ "get_context", (PyCFunction)pyg_source_get_context, METH_NOARGS },
{ "add_poll", (PyCFunction)pyg_source_add_poll, METH_KEYWORDS },
......
......@@ -89,6 +89,30 @@ class TestSource(unittest.TestCase):
assert dispatched[0]
def testIsDestroyedSimple(self):
s = GLib.Source()
self.assertFalse(s.is_destroyed())
s.destroy()
self.assertTrue(s.is_destroyed())
c = GLib.MainContext()
s = GLib.Source()
s.attach(c)
self.assertFalse(s.is_destroyed())
s.destroy()
self.assertTrue(s.is_destroyed())
def testIsDestroyedContext(self):
def f():
c = GLib.MainContext()
s = GLib.Source()
s.attach(c)
return s
s = f()
self.assertTrue(s.is_destroyed())
class TestTimeout(unittest.TestCase):
def test504337(self):
......
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