pygobject r740 - in trunk: . gio tests



Author: johan
Date: Sun Jan 20 10:21:31 2008
New Revision: 740
URL: http://svn.gnome.org/viewvc/pygobject?rev=740&view=rev

Log:
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



Modified:
   trunk/ChangeLog
   trunk/gio/gio.override
   trunk/tests/test_gio.py

Modified: trunk/gio/gio.override
==============================================================================
--- trunk/gio/gio.override	(original)
+++ trunk/gio/gio.override	Sun Jan 20 10:21:31 2008
@@ -8,20 +8,34 @@
 #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 @@
   long count = -1;
   int io_priority = G_PRIORITY_DEFAULT;
   PyGObject *pycancellable;
-  PyObject *buffer;
   GCancellable *cancellable;
   PyGAsyncRequestNotify *notify;
   
@@ -303,12 +316,12 @@
   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 @@
       
   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;
+}

Modified: trunk/tests/test_gio.py
==============================================================================
--- trunk/tests/test_gio.py	(original)
+++ trunk/tests/test_gio.py	Sun Jan 20 10:21:31 2008
@@ -25,10 +25,11 @@
         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 @@
     def testReadAsyncError(self):
         self.count = 0
         def callback(stream, result):
+            #self.assertEquals(result.get_buffer(), None)
             self.count += 1
             if self.count == 1:
                 return



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]