dbus/python Makefile.am, 1.19, 1.20 dbus_bindings.pyx, 1.6, 1.7 dbus_glib_bindings.pyx, 1.2, 1.3 glib.py, 1.1, 1.2

John Palmieri johnp at freedesktop.org
Wed Aug 31 18:22:08 PDT 2005


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

Modified Files:
	Makefile.am dbus_bindings.pyx dbus_glib_bindings.pyx glib.py 
Log Message:
* python/Makefile.am: Break on pyrexc errors instead of ignoring them

* python/dbus_bindings.pyx: Memory management foo
(global): remove hacky _user_data_references global list
(GIL_safe_cunregister_function_handler): userdata now stuffed into
tuples. Unref user_data
(GIL_safe_cmessage_function_handler): userdata now stuffed into tuples
(Connection::__del__): Remove and replace with __dealloc__ method
(Connection::add_filter): Stuff user_data into a tuple.  Use Py_INCREF
to keep tuple from being deallocated instead of the global var hack
(Connection::register_object_path): Stuff user_data into a tuple.
Use Py_INCREF to keep tuple from being deallocated instead of the 
global var hack
(Connection::register_fallback): Stuff user_data into a tuple.
Use Py_INCREF to keep tuple from being deallocated instead of the 
global var hack
(GIL_safe_pending_call_notification): Don't unref the message
because it gets unreffed when going out of scope.  Py_XDECREF
the user_data
(PendingCall::__del__): Remove and replace with __dealloc__ method
(PendingCall::set_notify): ref the pending call because we will
need it to stick around for when the notify callback gets called
(Message::__del__): Remove and replace with __dealloc__ method

* python/dbus_glib_bindings.pyx (init_gthreads): Changed to 
gthreads_init to match up with the dbus call

* python/glib.py (init_threads): Changed to threads_init to match
up with gobject.threads_init().  init_threads is kept for backwards
compat but will most likely be deprecated in the future

* test/python/test-client.py: 
- revamp to use Python's unittest functionality
- add async call tests
- setup threads in glib and dbus so we make sure locks are working


Index: Makefile.am
===================================================================
RCS file: /cvs/dbus/dbus/python/Makefile.am,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- Makefile.am	24 Aug 2005 19:58:32 -0000	1.19
+++ Makefile.am	1 Sep 2005 01:22:06 -0000	1.20
@@ -38,8 +38,8 @@
 	-$(PYTHON) $(srcdir)/extract.py $(srcdir)/dbus_bindings.pxd.in -I$(srcdir)/$(top_builddir)  -I$(srcdir) > $@.tmp && mv $@.tmp $@
 
 dbus_bindings.c: $(srcdir)/dbus_bindings.pyx dbus_bindings.pxd 
-	-pyrexc $(srcdir)/dbus_bindings.pyx -I. -o ./dbus_bindings.c
+	pyrexc $(srcdir)/dbus_bindings.pyx -I. -o ./dbus_bindings.c
 
 dbus_glib_bindings.c: $(srcdir)/dbus_glib_bindings.pyx dbus_bindings.pxd 
-	-pyrexc $(srcdir)/dbus_glib_bindings.pyx  -I. -o ./dbus_glib_bindings.c
+	pyrexc $(srcdir)/dbus_glib_bindings.pyx  -I. -o ./dbus_glib_bindings.c
 

Index: dbus_bindings.pyx
===================================================================
RCS file: /cvs/dbus/dbus/python/dbus_bindings.pyx,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- dbus_bindings.pyx	31 Aug 2005 02:18:43 -0000	1.6
+++ dbus_bindings.pyx	1 Sep 2005 01:22:06 -0000	1.7
@@ -63,9 +63,6 @@
   void (* dbus_internal_pad3) (void *)
   void (* dbus_internal_pad4) (void *)
 
-
-_user_data_references = [ ]
-
 class DBusException(Exception):
     pass
 
@@ -182,14 +179,15 @@
                                                   void *user_data):
     cdef Connection conn
 
-    itup = <object>user_data
-    assert (type(tup) == list)    
+    tup = <object>user_data
+    assert (type(tup) == tuple)    
     function = tup[1]
     conn = Connection()
     conn.__cinit__(None, connection)
 
     args = (conn)
     function(*args)
+    Py_XDECREF(tup) 
 
 cdef void cunregister_function_handler (DBusConnection *connection,
                                         void *user_data):
@@ -210,7 +208,7 @@
     cdef Message message
 
     tup = <object>user_data
-    assert (type(tup) == list)
+    assert (type(tup) == tuple)
     function = tup[0]
     message = EmptyMessage()
 
@@ -221,7 +219,7 @@
     conn.__cinit__(None, connection)
     args = (conn,
             message)
-
+ 
     retval = function(*args)
 
     if (retval == None):
@@ -265,7 +263,7 @@
             if dbus_error_is_set(&error):
                 raise DBusException, error.message
 
-    def __del__(self):
+    def __dealloc__(self):
         if self.conn != NULL:
             dbus_connection_unref(self.conn)
 
@@ -416,10 +414,9 @@
     # FIXME: set_dispatch_status_function, get_unix_user, set_unix_user_function
 
     def add_filter(self, filter_function):
-        user_data = [ filter_function ]
-        global _user_data_references
-        _user_data_references.append(user_data)
-        
+        user_data = (filter_function,)
+        Py_XINCREF(user_data)
+       
         return dbus_connection_add_filter(self.conn,
                                           cmessage_function_handler,
                                           <void*>user_data,
@@ -459,9 +456,8 @@
         cvtable.unregister_function = cunregister_function_handler 
         cvtable.message_function    = cmessage_function_handler
 
-        user_data = [message_cb, unregister_cb]
-        global _user_data_references
-        _user_data_references.append(user_data)
+        user_data = (message_cb, unregister_cb)
+        Py_XINCREF(user_data)
         
         return dbus_connection_register_object_path(self.conn, path, &cvtable,
                                                     <void*>user_data) 
@@ -472,10 +468,9 @@
         cvtable.unregister_function = cunregister_function_handler 
         cvtable.message_function    = cmessage_function_handler
 
-        user_data = [message_cb, unregister_cb]
-        global _user_data_references
-        _user_data_references.append(user_data)        
-        
+        user_data = (message_cb, unregister_cb)
+        Py_XINCREF(user_data)
+       
         return dbus_connection_register_fallback(self.conn, path, &cvtable,
                                                  <void*>user_data) 
 
@@ -527,8 +522,8 @@
     else:
         error_handler(DBusException('Unexpected Message Type: ' + message.type_to_name(type)))
 
-    dbus_message_unref(dbus_message)
     dbus_pending_call_unref(pending_call)
+    Py_XDECREF(<object>user_data)
 
 cdef void _pending_call_notification(DBusPendingCall *pending_call, 
                                      void *user_data):
@@ -555,7 +550,7 @@
         self.pending_call = _pending_call
         dbus_pending_call_ref(self.pending_call)
 
-    def __del__(self):
+    def __dealloc__(self):
         if self.pending_call != NULL:
             dbus_pending_call_unref(self.pending_call)
 
@@ -580,6 +575,7 @@
     def set_notify(self, reply_handler, error_handler):
         user_data = (reply_handler, error_handler)
         Py_XINCREF(user_data)
+        dbus_pending_call_ref(self.pending_call)
         dbus_pending_call_set_notify(self.pending_call, _pending_call_notification, 
                                      <void *>user_data, _pending_call_free_user_data)
         
@@ -1297,7 +1293,7 @@
                 self.msg = dbus_message_new_error(cmsg, error_name, error_message)
  
 
-    def __del__(self):
+    def __dealloc__(self):
         if self.msg != NULL:
             dbus_message_unref(self.msg)
             

Index: dbus_glib_bindings.pyx
===================================================================
RCS file: /cvs/dbus/dbus/python/dbus_glib_bindings.pyx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- dbus_glib_bindings.pyx	23 Aug 2005 17:43:59 -0000	1.2
+++ dbus_glib_bindings.pyx	1 Sep 2005 01:22:06 -0000	1.3
@@ -13,5 +13,5 @@
    connection = conn
    dbus_connection_setup_with_g_main(connection._get_conn(), NULL)
 
-def init_gthreads ():
+def gthreads_init ():
     dbus_g_thread_init ()

Index: glib.py
===================================================================
RCS file: /cvs/dbus/dbus/python/glib.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- glib.py	12 Jul 2005 18:16:06 -0000	1.1
+++ glib.py	1 Sep 2005 01:22:06 -0000	1.2
@@ -5,11 +5,13 @@
     dbus_glib_bindings.setup_with_g_main(conn._connection)
 
 _dbus_gthreads_initialized = False
-def init_threads():
+def threads_init():
     global _dbus_gthreads_initialized
     if not _dbus_gthreads_initialized:
-        dbus_glib_bindings.init_gthreads ()
+        dbus_glib_bindings.gthreads_init()
         _dbus_gthreads_initialized = True
 
+def init_threads():
+    threads_init()
 
 setattr(dbus, "_dbus_mainloop_setup_function", _setup_with_g_main)



More information about the dbus-commit mailing list