summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--gio/gio.override45
-rw-r--r--tests/test_gio.py4
3 files changed, 46 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 4ac85c5..f5808eb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
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.
+ * tests/test_gio.py (TestInputStream.testReadAsync.callback):
+ Check the content
+
* tests/test_gio.py (TestInputStream.testReadAsyncError):
New function to test error condition of async read.
diff --git a/gio/gio.override b/gio/gio.override
index e2b8e50..904791b 100644
--- a/gio/gio.override
+++ b/gio/gio.override
@@ -8,20 +8,34 @@ headers
#define BUFSIZE 8192
typedef struct {
- PyObject *callback;
- PyObject *data;
+ PyObject *callback;
+ PyObject *data;
+ PyObject *buffer;
} PyGAsyncRequestNotify;
static void
+py_decref_callback (gpointer data)
+{
+ Py_DECREF((PyObject*)data);
+}
+
+static void
async_result_callback_marshal(GObject *source_object,
GAsyncResult *result,
PyGAsyncRequestNotify *notify)
{
PyObject *ret;
PyGILState_STATE state;
-
+ static GQuark quark = 0;
+
state = pyg_gil_state_ensure();
+ if (!quark)
+ quark = g_quark_from_string("pygio::buffer");
+ Py_INCREF(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),
@@ -266,7 +280,6 @@ _wrap_g_input_stream_read_async(PyGObject *self, PyObject *args, PyObject *kwarg
long count = -1;
int io_priority = G_PRIORITY_DEFAULT;
PyGObject *pycancellable;
- PyObject *buffer;
GCancellable *cancellable;
PyGAsyncRequestNotify *notify;
@@ -303,12 +316,12 @@ _wrap_g_input_stream_read_async(PyGObject *self, PyObject *args, PyObject *kwarg
Py_INCREF(notify->callback);
Py_XINCREF(notify->data);
- buffer = PyString_FromStringAndSize((char *)NULL, count);
- if (buffer == NULL)
+ 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 *)buffer),
+ PyString_AS_STRING((PyStringObject *)notify->buffer),
count,
io_priority,
cancellable,
@@ -357,3 +370,19 @@ _wrap_g_output_stream_write(PyGObject *self, PyObject *args, PyObject *kwargs)
return PyInt_FromLong(written);
}
+%%
+define GSimpleAsyncResult.get_buffer noargs
+static PyObject *
+_wrap_g_simple_async_result_get_buffer(PyGObject *self)
+{
+ static GQuark quark = 0;
+ PyObject *buffer;
+
+ if (!quark)
+ quark = g_quark_from_string("pygio::buffer");
+
+ buffer = g_object_get_qdata(G_OBJECT(self->obj), quark);
+
+ Py_INCREF(buffer);
+ return buffer;
+}
diff --git a/tests/test_gio.py b/tests/test_gio.py
index 3bb2746..092a8ec 100644
--- a/tests/test_gio.py
+++ b/tests/test_gio.py
@@ -25,10 +25,11 @@ class TestInputStream(unittest.TestCase):
def callback(stream, result):
read = stream.read_finish(result)
self.assertEquals(read, len("testing"))
+ self.assertEquals(result.get_buffer(), "testing")
stream.close()
loop.quit()
- self.stream.read_async(10240, 0, None, callback)
+ self.stream.read_async(7, 0, None, callback)
loop = gobject.MainLoop()
loop.run()
@@ -36,6 +37,7 @@ class TestInputStream(unittest.TestCase):
def testReadAsyncError(self):
self.count = 0
def callback(stream, result):
+ #self.assertEquals(result.get_buffer(), None)
self.count += 1
if self.count == 1:
return