diff options
author | Johan Dahlin <johan@gnome.org> | 2008-07-21 17:27:22 +0000 |
---|---|---|
committer | Johan Dahlin <johan@src.gnome.org> | 2008-07-21 17:27:22 +0000 |
commit | bf49647a03923975eb24ce634dae8254553db8de (patch) | |
tree | fac72b5b605789d7fa566332bd6a986b148a1ca5 /glib/glibmodule.c | |
parent | 39cf2d9ca4fc9b50984ec172282d33b1843fceee (diff) | |
download | pygobject-bf49647a03923975eb24ce634dae8254553db8de.tar.gz pygobject-bf49647a03923975eb24ce634dae8254553db8de.tar.xz pygobject-bf49647a03923975eb24ce634dae8254553db8de.zip |
Move over Source, IOChannel, Idle, Timeout and PollFD to glib from
2008-07-21 Johan Dahlin <johan@gnome.org>
* glib/Makefile.am:
* glib/glibmodule.c (pyg_idle_add), (pyg_timeout_add),
(pyg_timeout_add_seconds), (pyg_io_add_watch),
(pyglib_register_api), (pyglib_register_error),
(pyglib_register_version_tuples), (init_glib):
* glib/pygiochannel.c (py_io_channel_next),
(py_io_channel_shutdown), (py_io_channel_set_encoding),
(py_io_channel_read_chars), (py_io_channel_write_chars),
(py_io_channel_write_lines), (py_io_channel_flush),
(py_io_channel_set_flags), (py_io_channel_read_line),
(py_io_channel_read_lines), (py_io_channel_seek),
(py_io_channel_init), (pyglib_iochannel_register_types):
* glib/pygiochannel.h:
* glib/pyglib-private.h:
* glib/pyglib.c (pyglib_threads_enabled),
(pyglib_gil_state_ensure), (pyglib_gil_state_release),
(pyglib_enable_threads), (pyglib_block_threads),
(pyglib_unblock_threads), (pyglib_set_thread_block_funcs),
(pyglib_handler_marshal), (pyglib_destroy_notify):
* glib/pyglib.h:
* glib/pygsource.c (pyg_source_set_callback),
(pyglib_source_register_types):
* glib/pygsource.h:
* glib/pygspawn.c (pyglib_spawn_register_types):
* glib/pygspawn.h:
* gobject/Makefile.am:
* gobject/__init__.py:
* gobject/gobjectmodule.c (pyg_set_thread_block_funcs),
(init_gobject):
* gobject/pygiochannel.c:
* gobject/pygobject-private.h:
* gobject/pygsource.c:
Move over Source, IOChannel, Idle, Timeout and PollFD to glib from
gobject.
Clean up and add a bit of new api for glib.
svn path=/trunk/; revision=846
Diffstat (limited to 'glib/glibmodule.c')
-rw-r--r-- | glib/glibmodule.c | 79 |
1 files changed, 18 insertions, 61 deletions
diff --git a/glib/glibmodule.c b/glib/glibmodule.c index 6892d1a..0281524 100644 --- a/glib/glibmodule.c +++ b/glib/glibmodule.c @@ -30,33 +30,16 @@ #include "pyglib.h" #include "pyglib-private.h" +#include "pygiochannel.h" #include "pygmaincontext.h" #include "pygmainloop.h" +#include "pygsource.h" #include "pygspawn.h" #define PYGLIB_MAJOR_VERSION PYGOBJECT_MAJOR_VERSION #define PYGLIB_MINOR_VERSION PYGOBJECT_MINOR_VERSION #define PYGLIB_MICRO_VERSION PYGOBJECT_MICRO_VERSION -/** - * pyg_destroy_notify: - * @user_data: a PyObject pointer. - * - * A function that can be used as a GDestroyNotify callback that will - * call Py_DECREF on the data. - */ -void -pyg_destroy_notify(gpointer user_data) -{ - PyObject *obj = (PyObject *)user_data; - PyGILState_STATE state; - - state = pyglib_gil_state_ensure(); - Py_DECREF(obj); - pyglib_gil_state_release(state); -} - - /* ---------------- glib module functions -------------------- */ @@ -100,33 +83,6 @@ get_handler_priority(gint *priority, PyObject *kwargs) return 0; } -gboolean -pyg_handler_marshal(gpointer user_data) -{ - PyObject *tuple, *ret; - gboolean res; - PyGILState_STATE state; - - g_return_val_if_fail(user_data != NULL, FALSE); - - state = pyglib_gil_state_ensure(); - - tuple = (PyObject *)user_data; - ret = PyObject_CallObject(PyTuple_GetItem(tuple, 0), - PyTuple_GetItem(tuple, 1)); - if (!ret) { - PyErr_Print(); - res = FALSE; - } else { - res = PyObject_IsTrue(ret); - Py_DECREF(ret); - } - - pyglib_gil_state_release(state); - - return res; -} - static PyObject * pyg_idle_add(PyObject *self, PyObject *args, PyObject *kwargs) { @@ -160,8 +116,8 @@ pyg_idle_add(PyObject *self, PyObject *args, PyObject *kwargs) data = Py_BuildValue("(ON)", callback, cbargs); if (data == NULL) return NULL; - handler_id = g_idle_add_full(priority, pyg_handler_marshal, data, - pyg_destroy_notify); + handler_id = g_idle_add_full(priority, pyglib_handler_marshal, data, + pyglib_destroy_notify); return PyInt_FromLong(handler_id); } @@ -200,8 +156,8 @@ pyg_timeout_add(PyObject *self, PyObject *args, PyObject *kwargs) if (data == NULL) return NULL; handler_id = g_timeout_add_full(priority, interval, - pyg_handler_marshal, data, - pyg_destroy_notify); + pyglib_handler_marshal, data, + pyglib_destroy_notify); return PyInt_FromLong(handler_id); } @@ -239,8 +195,8 @@ pyg_timeout_add_seconds(PyObject *self, PyObject *args, PyObject *kwargs) if (data == NULL) return NULL; handler_id = g_timeout_add_seconds_full(priority, interval, - pyg_handler_marshal, data, - pyg_destroy_notify); + pyglib_handler_marshal, data, + pyglib_destroy_notify); return PyInt_FromLong(handler_id); } @@ -328,7 +284,7 @@ pyg_io_add_watch(PyObject *self, PyObject *args, PyObject *kwargs) iochannel = g_io_channel_unix_new(fd); handler_id = g_io_add_watch_full(iochannel, priority, condition, iowatch_marshal, data, - (GDestroyNotify)pyg_destroy_notify); + (GDestroyNotify)pyglib_destroy_notify); g_io_channel_unref(iochannel); return PyInt_FromLong(handler_id); @@ -613,7 +569,7 @@ struct _PyGLib_Functions pyglib_api_functions = { }; static void -pyg_register_api(PyObject *d) +pyglib_register_api(PyObject *d) { PyObject *o; @@ -626,7 +582,7 @@ pyg_register_api(PyObject *d) } static void -pyg_register_error(PyObject *d) +pyglib_register_error(PyObject *d) { PyObject *dict; PyObject *gerror_class; @@ -644,7 +600,7 @@ pyg_register_error(PyObject *d) } static void -pyg_register_version_tuples(PyObject *d) +pyglib_register_version_tuples(PyObject *d) { PyObject *o; @@ -671,11 +627,12 @@ init_glib(void) m = Py_InitModule("glib._glib", pyglib_functions); d = PyModule_GetDict(m); - pyg_register_api(d); - pyg_register_error(d); - pyg_register_version_tuples(d); - pyg_spawn_register_types(d); - + pyglib_register_api(d); + pyglib_register_error(d); + pyglib_register_version_tuples(d); + pyglib_iochannel_register_types(d); pyglib_mainloop_register_types(d); pyglib_maincontext_register_types(d); + pyglib_source_register_types(d); + pyglib_spawn_register_types(d); } |