dbus/python dbus_bindings.pyx.in,1.26,1.27

John Palmieri johnp at freedesktop.org
Tue Jun 28 12:36:53 PDT 2005


Update of /cvs/dbus/dbus/python
In directory gabe:/tmp/cvs-serv21340/python

Modified Files:
	dbus_bindings.pyx.in 
Log Message:
* python/dbus_bindings.pyx.in (cunregister_function_handler,
  cmessage_function_handler): Patch from 
  Anthony Baxter <anthony at interlink.com.au> fixes threading problems
  by using the Py_GILState_Ensure/Release to synchronize with the
  python runtime.


Index: dbus_bindings.pyx.in
===================================================================
RCS file: /cvs/dbus/dbus/python/dbus_bindings.pyx.in,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- dbus_bindings.pyx.in	16 Jun 2005 05:51:46 -0000	1.26
+++ dbus_bindings.pyx.in	28 Jun 2005 19:36:51 -0000	1.27
@@ -34,6 +34,10 @@
     void Py_XINCREF (object)
     void Py_XDECREF (object)
     object PyString_FromStringAndSize(char *, int)
+    ctypedef void *PyGILState_STATE
+    void PyErr_Clear()
+    PyGILState_STATE PyGILState_Ensure()
+    void PyGILState_Release(PyGILState_STATE)
 
 ctypedef struct DBusError:
     char *name
@@ -158,38 +162,46 @@
 cdef void cunregister_function_handler (DBusConnection *connection,
                                         void *user_data):
     cdef Connection conn
-    tup = <object>user_data
-    assert (type(tup) == list)    
-    function = tup[1]
-    conn = Connection()
-    conn.__cinit__(None, connection)
+    cdef PyGILState_STATE gil
 
-    args = [conn]
-    function(*args)
+    gil = PyGILState_Ensure()
+    try:
+        itup = <object>user_data
+        assert (type(tup) == list)    
+        function = tup[1]
+        conn = Connection()
+        conn.__cinit__(None, connection)
+
+        args = [conn]
+        function(*args)
+    finally:
+        PyGILState_Release(gil)
 
 cdef DBusHandlerResult cmessage_function_handler (DBusConnection *connection,
                                                   DBusMessage *msg,
                                                   void *user_data):
     cdef Connection conn
     cdef Message message
+    cdef PyGILState_STATE gil
 
-    tup = <object>user_data
-    assert (type(tup) == list)
-    function = tup[0]
-    message = Message(_create=0)
-    message._set_msg(msg)
-  
-    conn = Connection()
-    conn.__cinit__(None, connection)  
- 
-    args = [conn,
-            message]
-    retval = function(*args)
-    if (retval == None):
-        retval = DBUS_HANDLER_RESULT_HANDLED
-
-    return retval
-
+    gil = PyGILState_Ensure()
+    try:
+        tup = <object>user_data
+        assert (type(tup) == list)
+        function = tup[0]
+        message = Message(_create=0)
+        message._set_msg(msg)
+        conn = Connection()
+        conn.__cinit__(None, connection)  
+        args = [conn,
+                message]
+        retval = function(*args)
+        if (retval == None):
+            retval = DBUS_HANDLER_RESULT_HANDLED
+        return retval
+    finally:
+        PyGILState_Release(gil)
+	
 cdef class Connection:
     cdef DBusConnection *conn
     



More information about the dbus-commit mailing list