[Xcb] [PATCH 2/3] Do not block when calling reply() multiple times.

Julien Danjou julien at danjou.info
Tue Jan 19 13:04:25 PST 2010


Signed-off-by: Julien Danjou <julien at danjou.info>
---
 src/cookie.c |   14 +++++++++++---
 src/cookie.h |    1 +
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/cookie.c b/src/cookie.c
index db0a20f..08b9a75 100644
--- a/src/cookie.c
+++ b/src/cookie.c
@@ -23,6 +23,7 @@ xpybCookie_new(PyTypeObject *self, PyObject *args, PyObject *kw)
 static void
 xpybCookie_dealloc(xpybCookie *self)
 {
+    Py_CLEAR(self->reply);
     Py_CLEAR(self->reply_type);
     Py_CLEAR(self->request);
     Py_CLEAR(self->conn);
@@ -63,7 +64,7 @@ xpybCookie_reply(xpybCookie *self, PyObject *args)
 {
     xcb_generic_error_t *error;
     xcb_generic_reply_t *data;
-    PyObject *shim, *reply;
+    PyObject *shim;
 
     /* Check arguments and connection. */
     if (self->request->is_void) {
@@ -73,6 +74,12 @@ xpybCookie_reply(xpybCookie *self, PyObject *args)
     if (xpybConn_invalid(self->conn))
 	return NULL;
 
+    if(self->reply)
+    {
+        Py_INCREF((PyObject *) self->reply);
+        return (PyObject *) self->reply;
+    }
+
     /* Make XCB call */
     data = xcb_wait_for_reply(self->conn->conn, self->cookie.sequence, &error);
     if (xpybError_set(self->conn, error))
@@ -88,9 +95,10 @@ xpybCookie_reply(xpybCookie *self, PyObject *args)
 	goto err1;
 
     /* Call the reply type object to get a new xcb.Reply instance */
-    reply = PyObject_CallFunctionObjArgs((PyObject *)self->reply_type, shim, NULL);
+    self->reply = (xpybReply *) PyObject_CallFunctionObjArgs((PyObject *)self->reply_type, shim, NULL);
+    Py_INCREF((PyObject *) self->reply);
     Py_DECREF(shim);
-    return reply;
+    return (PyObject *) self->reply;
 err1:
     free(data);
     return NULL;
diff --git a/src/cookie.h b/src/cookie.h
index b00e999..f0e25c0 100644
--- a/src/cookie.h
+++ b/src/cookie.h
@@ -9,6 +9,7 @@ typedef struct {
     PyObject_HEAD
     xpybConn *conn;
     xpybRequest *request;
+    xpybReply *reply;
     PyTypeObject *reply_type;
     xcb_void_cookie_t cookie;
 } xpybCookie;
-- 
1.6.6



More information about the Xcb mailing list