python bindings and uint16 on big-endian platforms

Johan Hedberg johan.hedberg at nokia.com
Fri Nov 4 07:44:43 PST 2005


Hi,

I'm trying to implement a service which receives uint16 parameters in a
method call. The service (actually the D-BUS daemon we're developing for
BlueZ) is implemented using the low-level C bindings, and the client
program used for testing it in python. What I found out was that the
service was alway getting a zero (0x0000) value for the uint16
parameters no matter what I sent from the python app. This was also only
happening on my powerbook (big-endian), but not on little-endian
machines.

I think that this behaviour is caused by the code using dbus_int32_t
where it should be using dbus_int16_t. Attached is a patch which seems
to solve the problem. The last part of the patch adds support for 16 bit
integers to the __str__ method of the MessageIter class.

Johan
-------------- next part --------------
Index: python/dbus_bindings.pyx
===================================================================
RCS file: /cvs/dbus/dbus/python/dbus_bindings.pyx,v
retrieving revision 1.15
diff -u -r1.15 dbus_bindings.pyx
--- python/dbus_bindings.pyx	4 Nov 2005 12:17:54 -0000	1.15
+++ python/dbus_bindings.pyx	4 Nov 2005 15:23:33 -0000
@@ -1137,14 +1137,14 @@
         return dbus_message_iter_append_basic(self.iter, TYPE_BYTE, <char *>&b)
 
     def append_int16(self, value):
-        cdef dbus_int32_t c_value
+        cdef dbus_int16_t c_value
         c_value = value
-        return dbus_message_iter_append_basic(self.iter, TYPE_INT16, <dbus_int32_t *>&c_value)
+        return dbus_message_iter_append_basic(self.iter, TYPE_INT16, <dbus_int16_t *>&c_value)
 
     def append_uint16(self, value):
-        cdef dbus_uint32_t c_value
+        cdef dbus_uint16_t c_value
         c_value = value
-        return dbus_message_iter_append_basic(self.iter, TYPE_UINT16, <dbus_uint32_t *>&c_value)
+        return dbus_message_iter_append_basic(self.iter, TYPE_UINT16, <dbus_uint16_t *>&c_value)
 
     def append_int32(self, value):
         cdef dbus_int32_t c_value
@@ -1359,6 +1359,12 @@
             elif type == TYPE_OBJECT_PATH:
                 path = iter.get_object_path()
                 arg = 'object_path:%s\n' % (path)
+            elif type == TYPE_INT16:
+                num = iter.get_int16()
+                arg = 'int16:%d\n' % (num)
+            elif type == TYPE_UINT16:
+                num = iter.get_uint16()
+                arg = 'uint16:%u\n' % (num)
             elif type == TYPE_INT32:
                 num = iter.get_int32()
                 arg = 'int32:%d\n' % (num)


More information about the dbus mailing list