summaryrefslogtreecommitdiffstats
path: root/gio/ginputstream.override
diff options
context:
space:
mode:
authorJohan Dahlin <johan@gnome.org>2008-03-22 18:14:01 +0000
committerJohan Dahlin <johan@src.gnome.org>2008-03-22 18:14:01 +0000
commitc27ae2b634dc06b1242ac7a9368d11945a4e1783 (patch)
tree6df83df006616945e974ceef542906a84bb1ae44 /gio/ginputstream.override
parent6ee167447336570b83e41ca2c4216d6e9058fd43 (diff)
downloadpygobject-c27ae2b634dc06b1242ac7a9368d11945a4e1783.tar.gz
pygobject-c27ae2b634dc06b1242ac7a9368d11945a4e1783.tar.xz
pygobject-c27ae2b634dc06b1242ac7a9368d11945a4e1783.zip
Make read_finish() return the string, remove the get_buffer method. This
2008-03-22 Johan Dahlin <johan@gnome.org> * gio/ginputstream.override: * gio/gio.override: * tests/test_gio.py: Make read_finish() return the string, remove the get_buffer method. This is more pythonic, as it mimics the normal read() behavior of python. Update the tests and use a separate marshaller for read. svn path=/trunk/; revision=753
Diffstat (limited to 'gio/ginputstream.override')
-rw-r--r--gio/ginputstream.override97
1 files changed, 92 insertions, 5 deletions
diff --git a/gio/ginputstream.override b/gio/ginputstream.override
index c279d41..a33903b 100644
--- a/gio/ginputstream.override
+++ b/gio/ginputstream.override
@@ -19,6 +19,64 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
+#define BUFSIZE 8192
+
+typedef struct {
+ PyObject *callback;
+ PyObject *data;
+ PyObject *buffer;
+} PyGAsyncRequestNotifyRead;
+
+static void
+py_decref_callback (gpointer data)
+{
+ Py_DECREF((PyObject*)data);
+}
+
+static void
+async_result_callback_marshal_read(GObject *source_object,
+ GAsyncResult *result,
+ PyGAsyncRequestNotifyRead *notify)
+{
+ PyObject *ret;
+ PyGILState_STATE state;
+ static GQuark quark = 0;
+
+ state = pyg_gil_state_ensure();
+
+ /* buffer is only used by read_async */
+ if (notify->buffer) {
+ if (!quark)
+ quark = g_quark_from_string("pygio::buffer");
+ Py_XINCREF(notify->buffer);
+ g_object_set_qdata_full(G_OBJECT(result), quark,
+ notify->buffer, py_decref_callback);
+ }
+
+ if (notify->data)
+ ret = PyEval_CallFunction(notify->callback, "(OOO)",
+ pygobject_new(source_object),
+ pygobject_new((GObject *)result),
+ notify->data);
+ else
+ ret = PyObject_CallFunction(notify->callback, "(OO)",
+ pygobject_new(source_object),
+ pygobject_new((GObject *)result));
+
+ if (ret == NULL)
+ {
+ PyErr_Print();
+ PyErr_Clear();
+ }
+
+ Py_XDECREF(ret);
+
+ Py_DECREF(notify->callback);
+ Py_XDECREF(notify->data);
+ g_slice_free(PyGAsyncRequestNotifyRead, notify);
+
+ pyg_gil_state_release(state);
+}
%%
override g_input_stream_read kwargs
static PyObject *
@@ -103,9 +161,9 @@ _wrap_g_input_stream_read_async(PyGObject *self, PyObject *args, PyObject *kwarg
GCancellable *cancellable;
- PyGAsyncRequestNotify *notify;
+ PyGAsyncRequestNotifyRead *notify;
- notify = g_slice_new0(PyGAsyncRequestNotify);
+ notify = g_slice_new0(PyGAsyncRequestNotifyRead);
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"liOO|O:InputStream.read_async",
@@ -115,7 +173,7 @@ _wrap_g_input_stream_read_async(PyGObject *self, PyObject *args, PyObject *kwarg
&notify->callback,
&notify->data))
{
- g_slice_free(PyGAsyncRequestNotify, notify);
+ g_slice_free(PyGAsyncRequestNotifyRead, notify);
return NULL;
}
@@ -132,7 +190,7 @@ _wrap_g_input_stream_read_async(PyGObject *self, PyObject *args, PyObject *kwarg
if (!PyCallable_Check(notify->callback))
{
PyErr_SetString(PyExc_TypeError, "callback argument not callable");
- g_slice_free(PyGAsyncRequestNotify, notify);
+ g_slice_free(PyGAsyncRequestNotifyRead, notify);
return NULL;
}
Py_INCREF(notify->callback);
@@ -147,9 +205,38 @@ _wrap_g_input_stream_read_async(PyGObject *self, PyObject *args, PyObject *kwarg
count,
io_priority,
cancellable,
- (GAsyncReadyCallback)async_result_callback_marshal,
+ (GAsyncReadyCallback)async_result_callback_marshal_read,
notify);
Py_INCREF(Py_None);
return Py_None;
}
+%%
+override g_input_stream_read_finish kwargs
+static PyObject *
+_wrap_g_input_stream_read_finish(PyGObject *self, PyObject *args, PyObject *kwargs)
+{
+ static char *kwlist[] = { "result", NULL };
+ PyGObject *result;
+ GError *error = NULL;
+ static GQuark quark = 0;
+ PyObject *buffer;
+
+ if (!quark)
+ quark = g_quark_from_string("pygio::buffer");
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+ "O!:GInputStream.read_finish",
+ kwlist, &PyGAsyncResult_Type, &result))
+ return NULL;
+
+
+ g_input_stream_read_finish(G_INPUT_STREAM(self->obj), G_ASYNC_RESULT(result->obj), &error);
+
+ if (pyg_error_check(&error))
+ return NULL;
+
+ buffer = g_object_get_qdata(G_OBJECT(result->obj), quark);
+ /* FIXME: Should we refcount the buffer here? */
+ return buffer;
+}