diff options
author | Johan Dahlin <johan@gnome.org> | 2008-01-20 15:29:23 +0000 |
---|---|---|
committer | Johan Dahlin <johan@src.gnome.org> | 2008-01-20 15:29:23 +0000 |
commit | 702ed9b73e4f596aadf86cdfbf3655cee97b4cb6 (patch) | |
tree | ac70db328b47db266c01f4e9488d6dae4d00b2b8 | |
parent | 5df2f97e4db1dfefc1ff933758e9b580d796c53c (diff) | |
download | pygobject-702ed9b73e4f596aadf86cdfbf3655cee97b4cb6.tar.gz pygobject-702ed9b73e4f596aadf86cdfbf3655cee97b4cb6.tar.xz pygobject-702ed9b73e4f596aadf86cdfbf3655cee97b4cb6.zip |
Split out overrides into more files. Fix up module description in comment
2008-01-20 Johan Dahlin <johan@gnome.org>
* gio/Makefile.am:
* gio/ginputstream.override:
* gio/gio.override:
* gio/giomodule.c:
* gio/goutputstream.override:
* gio/gvolumemonitor.override:
* gio/unix.override:
* gio/unixmodule.c:
Split out overrides into more files. Fix up module description in
comment
svn path=/trunk/; revision=741
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | gio/Makefile.am | 12 | ||||
-rw-r--r-- | gio/ginputstream.override | 155 | ||||
-rw-r--r-- | gio/gio.override | 268 | ||||
-rw-r--r-- | gio/giomodule.c | 2 | ||||
-rw-r--r-- | gio/goutputstream.override | 60 | ||||
-rw-r--r-- | gio/gvolumemonitor.override | 84 | ||||
-rw-r--r-- | gio/unix.override | 22 | ||||
-rw-r--r-- | gio/unixmodule.c | 4 |
9 files changed, 375 insertions, 246 deletions
@@ -1,5 +1,19 @@ 2008-01-20 Johan Dahlin <johan@gnome.org> + * gio/Makefile.am: + * gio/ginputstream.override: + * gio/gio.override: + * gio/giomodule.c: + * gio/goutputstream.override: + * gio/gvolumemonitor.override: + * gio/unix.override: + * gio/unixmodule.c: + + Split out overrides into more files. Fix up module description in + comments + +2008-01-20 Johan Dahlin <johan@gnome.org> + * gio/gio.override (_wrap_g_simple_async_result_get_buffer): Add a new method, to fetch the buffer (_wrap_g_input_stream_read_async): Save a reference to the buffer. diff --git a/gio/Makefile.am b/gio/Makefile.am index 68de0cd..955e3f2 100644 --- a/gio/Makefile.am +++ b/gio/Makefile.am @@ -33,10 +33,16 @@ CLEANFILES = EXTRA_DIST = # gio module -GIO_DEFS = gio.defs gio-types.defs gio.override +GIO_OVERRIDES = \ + gio.override \ + ginputstream.override \ + goutputstream.override \ + gvolumemonitor.override + +GIO_DEFS = gio.defs gio-types.defs $(GIO_OVERRIDES) CLEANFILES += gio.c -EXTRA_DIST += $(GIO_DEFS) gio.override -gio.c: $(GIO_DEFS) gio.override +EXTRA_DIST += $(GIO_DEFS) $(GIO_OVERRIDES) +gio.c: $(GIO_DEFS) $(GIO_OVERRIDES) _gio_la_CFLAGS = $(GIO_CFLAGS) _gio_la_LDFLAGS = $(common_ldflags) -export-symbols-regex init_gio _gio_la_LIBADD = $(GIO_LIBS) diff --git a/gio/ginputstream.override b/gio/ginputstream.override new file mode 100644 index 0000000..a880f5f --- /dev/null +++ b/gio/ginputstream.override @@ -0,0 +1,155 @@ +/* -*- Mode: C; c-basic-offset: 4 -*- + * pygtk- Python bindings for the GTK toolkit. + * Copyright (C) 2008 Johan Dahlin + * + * ginputstream.override: module overrides for GInputStream + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + */ +%% +override g_input_stream_read kwargs +static PyObject * +_wrap_g_input_stream_read(PyGObject *self, PyObject *args, PyObject *kwargs) +{ + static char *kwlist[] = { "count", "cancellable", NULL }; + PyGObject *pycancellable = NULL; + PyObject *v; + + GCancellable *cancellable; + long count = -1; + GError *error = NULL; + size_t bytesread, buffersize, chunksize; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "|iO!:InputStream.read", + kwlist, &count, + &PyGCancellable_Type, &pycancellable)) + return NULL; + + buffersize = BUFSIZE; + + cancellable = pycancellable ? G_CANCELLABLE(pycancellable->obj) : NULL; + + v = PyString_FromStringAndSize((char *)NULL, buffersize); + if (v == NULL) + return NULL; + + bytesread = 0; + for (;;) + { + pyg_begin_allow_threads; + errno = 0; + chunksize = g_input_stream_read(G_INPUT_STREAM(self->obj), + PyString_AS_STRING((PyStringObject *)v) + bytesread, + buffersize - bytesread, cancellable, + &error); + pyg_end_allow_threads; + + if (pyg_error_check(&error)) + { + Py_DECREF(v); + return NULL; + } + else if (chunksize == 0) + { + PyErr_SetFromErrno(PyExc_IOError); + Py_DECREF(v); + return NULL; + } + + bytesread += chunksize; + if (bytesread < buffersize) + break; + + if (count < 0) + { + buffersize += BUFSIZE; + if (_PyString_Resize(&v, buffersize) < 0) + return NULL; + } + else + /* Got what was requested. */ + break; + } + + if (bytesread != buffersize) + _PyString_Resize(&v, bytesread); + + return v; +} +%% +override g_input_stream_read_async kwargs +static PyObject * +_wrap_g_input_stream_read_async(PyGObject *self, PyObject *args, PyObject *kwargs) +{ + static char *kwlist[] = { "count", "io_priority", "cancellable", "callback", + "user_data", NULL }; + long count = -1; + int io_priority = G_PRIORITY_DEFAULT; + PyGObject *pycancellable; + GCancellable *cancellable; + + + PyGAsyncRequestNotify *notify; + + notify = g_slice_new0(PyGAsyncRequestNotify); + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "iiOO|O:InputStream.read_async", + kwlist, &count, + &io_priority, + &pycancellable, + ¬ify->callback, + ¬ify->data)) + { + g_slice_free(PyGAsyncRequestNotify, notify); + return NULL; + } + + if ((PyObject*)pycancellable == Py_None) + cancellable = NULL; + else if (pygobject_check(pycancellable, &PyGCancellable_Type)) + cancellable = G_CANCELLABLE(pycancellable->obj); + else + { + PyErr_SetString(PyExc_TypeError, "cancellable should be a gio.Cancellable"); + return NULL; + } + + if (!PyCallable_Check(notify->callback)) + { + PyErr_SetString(PyExc_TypeError, "callback argument not callable"); + g_slice_free(PyGAsyncRequestNotify, notify); + return NULL; + } + Py_INCREF(notify->callback); + Py_XINCREF(notify->data); + + notify->buffer = PyString_FromStringAndSize((char *)NULL, count); + if (notify->buffer == NULL) + return NULL; + + g_input_stream_read_async(G_INPUT_STREAM(self->obj), + PyString_AS_STRING((PyStringObject *)notify->buffer), + count, + io_priority, + cancellable, + (GAsyncReadyCallback)async_result_callback_marshal, + notify); + + Py_INCREF(Py_None); + return Py_None; +} diff --git a/gio/gio.override b/gio/gio.override index 904791b..8e6f167 100644 --- a/gio/gio.override +++ b/gio/gio.override @@ -1,4 +1,28 @@ -/* -*- Mode: C; c-basic-offset: 4 -*- */ +/* -*- Mode: C; c-basic-offset: 4 -*- + * pygtk- Python bindings for the GTK toolkit. + * Copyright (C) 2008 Johan Dahlin + * + * giomodule.c: module wrapping the GIO library + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + */ +%% +modulename gio +%% +import gobject.GObject as PyGObject_Type %% headers #define NO_IMPORT_PYGOBJECT @@ -60,79 +84,16 @@ async_result_callback_marshal(GObject *source_object, pyg_gil_state_release(state); } - -%% -modulename gio %% -import gobject.GObject as PyGObject_Type +include + ginputstream.override + goutputstream.override + gvolumemonitor.override %% ignore-glob *_get_type *free %% -override g_volume_monitor_get_connected_drives noargs -static PyObject * -_wrap_g_volume_monitor_get_connected_drives (PyGObject *self) -{ - GList *list, *l; - PyObject *ret; - - list = g_volume_monitor_get_connected_drives (G_VOLUME_MONITOR (self->obj)); - - ret = PyList_New(0); - for (l = list; l; l = l->next) { - GDrive *drive = l->data; - PyObject *item = pygobject_new((GObject *)drive); - PyList_Append(ret, item); - Py_DECREF(item); - } - g_list_free(list); - - return ret; -} -%% -override g_volume_monitor_get_volumes noargs -static PyObject * -_wrap_g_volume_monitor_get_volumes (PyGObject *self) -{ - GList *list, *l; - PyObject *ret; - - list = g_volume_monitor_get_volumes (G_VOLUME_MONITOR (self->obj)); - - ret = PyList_New(0); - for (l = list; l; l = l->next) { - GVolume *volume = l->data; - PyObject *item = pygobject_new((GObject *)volume); - PyList_Append(ret, item); - Py_DECREF(item); - } - g_list_free(list); - - return ret; -} -%% -override g_volume_monitor_get_mounts noargs -static PyObject * -_wrap_g_volume_monitor_get_mounts (PyGObject *self) -{ - GList *list, *l; - PyObject *ret; - - list = g_volume_monitor_get_mounts (G_VOLUME_MONITOR (self->obj)); - - ret = PyList_New(0); - for (l = list; l; l = l->next) { - GMount *mount = l->data; - PyObject *item = pygobject_new((GObject *)mount); - PyList_Append(ret, item); - Py_DECREF(item); - } - g_list_free(list); - - return ret; -} -%% override g_drive_get_volumes noargs static PyObject * _wrap_g_drive_get_volumes (PyGObject *self) @@ -200,177 +161,6 @@ _wrap_g_app_info_get_all_for_type (PyGObject *self, PyObject *args) return ret; } %% -override g_input_stream_read kwargs -static PyObject * -_wrap_g_input_stream_read(PyGObject *self, PyObject *args, PyObject *kwargs) -{ - static char *kwlist[] = { "count", "cancellable", NULL }; - PyGObject *pycancellable = NULL; - PyObject *v; - - GCancellable *cancellable; - long count = -1; - GError *error = NULL; - size_t bytesread, buffersize, chunksize; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "|iO!:InputStream.read", - kwlist, &count, - &PyGCancellable_Type, &pycancellable)) - return NULL; - - buffersize = BUFSIZE; - - cancellable = pycancellable ? G_CANCELLABLE(pycancellable->obj) : NULL; - - v = PyString_FromStringAndSize((char *)NULL, buffersize); - if (v == NULL) - return NULL; - - bytesread = 0; - for (;;) - { - pyg_begin_allow_threads; - errno = 0; - chunksize = g_input_stream_read(G_INPUT_STREAM(self->obj), - PyString_AS_STRING((PyStringObject *)v) + bytesread, - buffersize - bytesread, cancellable, - &error); - pyg_end_allow_threads; - - if (pyg_error_check(&error)) - { - Py_DECREF(v); - return NULL; - } - else if (chunksize == 0) - { - PyErr_SetFromErrno(PyExc_IOError); - Py_DECREF(v); - return NULL; - } - - bytesread += chunksize; - if (bytesread < buffersize) - break; - - if (count < 0) - { - buffersize += BUFSIZE; - if (_PyString_Resize(&v, buffersize) < 0) - return NULL; - } - else - /* Got what was requested. */ - break; - } - - if (bytesread != buffersize) - _PyString_Resize(&v, bytesread); - - return v; -} -%% -override g_input_stream_read_async kwargs -static PyObject * -_wrap_g_input_stream_read_async(PyGObject *self, PyObject *args, PyObject *kwargs) -{ - static char *kwlist[] = { "count", "io_priority", "cancellable", "callback", - "user_data", NULL }; - long count = -1; - int io_priority = G_PRIORITY_DEFAULT; - PyGObject *pycancellable; - GCancellable *cancellable; - PyGAsyncRequestNotify *notify; - - notify = g_slice_new0(PyGAsyncRequestNotify); - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "iiOO|O:InputStream.read_async", - kwlist, &count, - &io_priority, - &pycancellable, - ¬ify->callback, - ¬ify->data)) - { - g_slice_free(PyGAsyncRequestNotify, notify); - return NULL; - } - - if ((PyObject*)pycancellable == Py_None) - cancellable = NULL; - else if (pygobject_check(pycancellable, &PyGCancellable_Type)) - cancellable = G_CANCELLABLE(pycancellable->obj); - else - { - PyErr_SetString(PyExc_TypeError, "cancellable should be a gio.Cancellable"); - return NULL; - } - - if (!PyCallable_Check(notify->callback)) - { - PyErr_SetString(PyExc_TypeError, "callback argument not callable"); - g_slice_free(PyGAsyncRequestNotify, notify); - return NULL; - } - Py_INCREF(notify->callback); - Py_XINCREF(notify->data); - - notify->buffer = PyString_FromStringAndSize((char *)NULL, count); - if (notify->buffer == NULL) - return NULL; - - g_input_stream_read_async(G_INPUT_STREAM(self->obj), - PyString_AS_STRING((PyStringObject *)notify->buffer), - count, - io_priority, - cancellable, - (GAsyncReadyCallback)async_result_callback_marshal, - notify); - - Py_INCREF(Py_None); - return Py_None; -} -%% -override g_output_stream_write kwargs -static PyObject * -_wrap_g_output_stream_write(PyGObject *self, PyObject *args, PyObject *kwargs) -{ - static char *kwlist[] = { "buffer", "cancellable", NULL }; - PyGObject *pycancellable = NULL; - gchar *buffer; - long count = 0; - GCancellable *cancellable; - GError *error = NULL; - gssize written; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "s#|O!:OutputStream.write", - kwlist, &buffer, &count, - &PyGCancellable_Type, &pycancellable)) - return NULL; - - if (!pycancellable) - cancellable = NULL; - else if (pygobject_check(pycancellable, &PyGCancellable_Type)) - cancellable = G_CANCELLABLE(pycancellable->obj); - else - { - PyErr_SetString(PyExc_TypeError, "cancellable should be a gio.Cancellable"); - return NULL; - } - - pyg_begin_allow_threads; - written = g_output_stream_write(G_OUTPUT_STREAM(self->obj), - buffer, count, cancellable, &error); - pyg_end_allow_threads; - - if (pyg_error_check(&error)) - return NULL; - - return PyInt_FromLong(written); -} -%% define GSimpleAsyncResult.get_buffer noargs static PyObject * _wrap_g_simple_async_result_get_buffer(PyGObject *self) diff --git a/gio/giomodule.c b/gio/giomodule.c index 0cd1403..6024258 100644 --- a/gio/giomodule.c +++ b/gio/giomodule.c @@ -1,5 +1,5 @@ /* -*- Mode: C; c-basic-offset: 4 -*- - * pygtk- Python bindings for the GTK toolkit. + * pygobject - Python bindings for GObject * Copyright (C) 2008 Johan Dahlin * * giomodule.c: module wrapping the GIO library diff --git a/gio/goutputstream.override b/gio/goutputstream.override new file mode 100644 index 0000000..f7ad2e1 --- /dev/null +++ b/gio/goutputstream.override @@ -0,0 +1,60 @@ +/* -*- Mode: C; c-basic-offset: 4 -*- + * pygtk- Python bindings for the GTK toolkit. + * Copyright (C) 2008 Johan Dahlin + * + * goutputstream.override: module overrides for GOutputStream + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + */ +%% +override g_output_stream_write kwargs +static PyObject * +_wrap_g_output_stream_write(PyGObject *self, PyObject *args, PyObject *kwargs) +{ + static char *kwlist[] = { "buffer", "cancellable", NULL }; + PyGObject *pycancellable = NULL; + gchar *buffer; + long count = 0; + GCancellable *cancellable; + GError *error = NULL; + gssize written; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "s#|O!:OutputStream.write", + kwlist, &buffer, &count, + &PyGCancellable_Type, &pycancellable)) + return NULL; + + if (!pycancellable) + cancellable = NULL; + else if (pygobject_check(pycancellable, &PyGCancellable_Type)) + cancellable = G_CANCELLABLE(pycancellable->obj); + else + { + PyErr_SetString(PyExc_TypeError, "cancellable should be a gio.Cancellable"); + return NULL; + } + + pyg_begin_allow_threads; + written = g_output_stream_write(G_OUTPUT_STREAM(self->obj), + buffer, count, cancellable, &error); + pyg_end_allow_threads; + + if (pyg_error_check(&error)) + return NULL; + + return PyInt_FromLong(written); +} diff --git a/gio/gvolumemonitor.override b/gio/gvolumemonitor.override new file mode 100644 index 0000000..27c193f --- /dev/null +++ b/gio/gvolumemonitor.override @@ -0,0 +1,84 @@ +/* -*- Mode: C; c-basic-offset: 4 -*- + * pygtk- Python bindings for the GTK toolkit. + * Copyright (C) 2008 Johan Dahlin + * + * gvolumemonitor.override: module overrides for GVolumeMonitor + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + */ +%% +override g_volume_monitor_get_connected_drives noargs +static PyObject * +_wrap_g_volume_monitor_get_connected_drives (PyGObject *self) +{ + GList *list, *l; + PyObject *ret; + + list = g_volume_monitor_get_connected_drives (G_VOLUME_MONITOR (self->obj)); + + ret = PyList_New(0); + for (l = list; l; l = l->next) { + GDrive *drive = l->data; + PyObject *item = pygobject_new((GObject *)drive); + PyList_Append(ret, item); + Py_DECREF(item); + } + g_list_free(list); + + return ret; +} +%% +override g_volume_monitor_get_volumes noargs +static PyObject * +_wrap_g_volume_monitor_get_volumes (PyGObject *self) +{ + GList *list, *l; + PyObject *ret; + + list = g_volume_monitor_get_volumes (G_VOLUME_MONITOR (self->obj)); + + ret = PyList_New(0); + for (l = list; l; l = l->next) { + GVolume *volume = l->data; + PyObject *item = pygobject_new((GObject *)volume); + PyList_Append(ret, item); + Py_DECREF(item); + } + g_list_free(list); + + return ret; +} +%% +override g_volume_monitor_get_mounts noargs +static PyObject * +_wrap_g_volume_monitor_get_mounts (PyGObject *self) +{ + GList *list, *l; + PyObject *ret; + + list = g_volume_monitor_get_mounts (G_VOLUME_MONITOR (self->obj)); + + ret = PyList_New(0); + for (l = list; l; l = l->next) { + GMount *mount = l->data; + PyObject *item = pygobject_new((GObject *)mount); + PyList_Append(ret, item); + Py_DECREF(item); + } + g_list_free(list); + + return ret; +} diff --git a/gio/unix.override b/gio/unix.override index 6d9f0ed..8088df2 100644 --- a/gio/unix.override +++ b/gio/unix.override @@ -1,4 +1,24 @@ -/* -*- Mode: C; c-basic-offset: 4 -*- */ +/* -*- Mode: C; c-basic-offset: 4 -*- + * pygobject - Python bindings for GObject + * Copyright (C) 2008 Johan Dahlin + * + * unixmodule.c: module wrapping the GIO UNIX library + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + */ %% headers #define NO_IMPORT_PYGOBJECT diff --git a/gio/unixmodule.c b/gio/unixmodule.c index 6d68d27..827dca9 100644 --- a/gio/unixmodule.c +++ b/gio/unixmodule.c @@ -1,8 +1,8 @@ /* -*- Mode: C; c-basic-offset: 4 -*- - * pygtk- Python bindings for the GTK toolkit. + * pygobject - Python bindings for GObject * Copyright (C) 2008 Johan Dahlin * - * giomodule.c: module wrapping the GIO library + * unixmodule.c: module wrapping the GIO UNIX library * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public |