diff options
-rw-r--r-- | gi/gimodule.c | 8 | ||||
-rw-r--r-- | gi/pygi-source.c | 22 | ||||
-rw-r--r-- | gi/pygi-source.h | 2 |
3 files changed, 19 insertions, 13 deletions
diff --git a/gi/gimodule.c b/gi/gimodule.c index 4ef24cb9..441831cc 100644 --- a/gi/gimodule.c +++ b/gi/gimodule.c @@ -1887,12 +1887,6 @@ _wrap_pyg_variant_type_from_string (PyObject *self, PyObject *args) return py_variant; } -static PyObject * -_wrap_pygi_source_new (PyObject *self, PyObject *args) -{ - return pygi_source_new (); -} - #define CHUNK_SIZE 8192 static PyObject* @@ -2255,7 +2249,7 @@ static PyMethodDef _gi_functions[] = { { "register_interface_info", (PyCFunction) _wrap_pyg_register_interface_info, METH_VARARGS }, { "hook_up_vfunc_implementation", (PyCFunction) _wrap_pyg_hook_up_vfunc_implementation, METH_VARARGS }, { "variant_type_from_string", (PyCFunction) _wrap_pyg_variant_type_from_string, METH_VARARGS }, - { "source_new", (PyCFunction) _wrap_pygi_source_new, METH_NOARGS }, + { "source_new", (PyCFunction) pygi_source_new, METH_NOARGS }, { "pyos_getsig", (PyCFunction) _wrap_pyig_pyos_getsig, METH_VARARGS }, { "source_set_callback", (PyCFunction) pygi_source_set_callback, METH_VARARGS }, { "io_channel_read", (PyCFunction) pyg_channel_read, METH_VARARGS }, diff --git a/gi/pygi-source.c b/gi/pygi-source.c index d62c54d4..26f6ad5b 100644 --- a/gi/pygi-source.c +++ b/gi/pygi-source.c @@ -280,18 +280,30 @@ pygi_source_set_callback (PyGObject *self_module, PyObject *args) * * Wrap the un-bindable g_source_new() and provide wrapper callbacks in the * GSourceFuncs which call back to Python. + * + * Returns NULL on error and sets an exception. */ PyObject* -pygi_source_new (void) +pygi_source_new (PyObject *self, PyObject *args) { - PyGRealSource *source = NULL; - PyObject *py_type; + PyGRealSource *source; + PyObject *py_type, *boxed; - source = (PyGRealSource*) g_source_new (&pyg_source_funcs, sizeof (PyGRealSource)); + g_assert (args == NULL); py_type = pygi_type_import_by_name ("GLib", "Source"); + if (!py_type) + return NULL; + + source = (PyGRealSource*) g_source_new (&pyg_source_funcs, sizeof (PyGRealSource)); /* g_source_new uses malloc, not slices */ - source->obj = pygi_boxed_new ( (PyTypeObject *) py_type, source, FALSE, 0); + boxed = pygi_boxed_new ( (PyTypeObject *) py_type, source, FALSE, 0); + Py_DECREF (py_type); + if (!boxed) { + g_source_unref ((GSource *)source); + return NULL; + } + source->obj = boxed; return source->obj; } diff --git a/gi/pygi-source.h b/gi/pygi-source.h index b24e98ae..5d60c634 100644 --- a/gi/pygi-source.h +++ b/gi/pygi-source.h @@ -24,7 +24,7 @@ #ifndef __PYGI_SOURCE_H__ #define __PYGI_SOURCE_H__ -PyObject *pygi_source_new (void); +PyObject *pygi_source_new (PyObject *self, PyObject *args); PyObject *pygi_source_set_callback (PyGObject *self, PyObject *args); #endif /* __PYGI_SOURCE_H__ */ |