summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorSeth Nickell <seth@gnome.org>2004-06-01 01:20:59 +0000
committerSeth Nickell <seth@gnome.org>2004-06-01 01:20:59 +0000
commit23e9d3d5040f51870f212ea70a94c9913c90e66b (patch)
tree672609cc6a54ca4a4accb6b2ad963b1084572470 /python
parentd027c9937534e3f49564e9c30c37421f8138c562 (diff)
downloaddbus-23e9d3d5040f51870f212ea70a94c9913c90e66b.tar.gz
* python/dbus_bindings.pyx.in:
* python/tests/test-client.py: Test Suite: 1 Python Bindings: 0 (fix string array memory trashing bug... oops)
Diffstat (limited to 'python')
-rw-r--r--python/dbus_bindings.pyx.in82
-rw-r--r--python/tests/test-client.py20
2 files changed, 88 insertions, 14 deletions
diff --git a/python/dbus_bindings.pyx.in b/python/dbus_bindings.pyx.in
index dba5bc7f..0df7836b 100644
--- a/python/dbus_bindings.pyx.in
+++ b/python/dbus_bindings.pyx.in
@@ -5,6 +5,7 @@
cdef extern from "stdlib.h":
cdef void *malloc(size_t size)
cdef void free(void *ptr)
+ cdef void *calloc(size_t nmemb, size_t size)
cdef extern from "dbus-glib.h":
ctypedef struct GMainContext
@@ -486,6 +487,12 @@ cdef class MessageIter:
retval = self.get_object_path_array()
elif array_type == TYPE_BYTE:
retval = self.get_byte_array()
+ elif array_type == TYPE_INT32:
+ retval = self.get_int32_array()
+ elif array_type == TYPE_UINT32:
+ retval = self.get_uint32_array()
+ elif array_type == TYPE_DOUBLE:
+ retval = self.get_double_array()
else:
raise TypeError, "Unknown array type %d in MessageIter" % (array_type)
elif arg_type == TYPE_DICT:
@@ -562,9 +569,34 @@ cdef class MessageIter:
return list
# FIXME: implement dbus_message_iter_get_boolean_array
- # dbus_message_iter_get_int32_array
- # dbus_message_iter_get_uint32_array
- # dbus_message_iter_get_double_array
+
+ def get_int32_array(self):
+ cdef int len
+ cdef dbus_int32_t *retval
+ dbus_message_iter_get_int32_array(self.iter, &retval, <int*>&len)
+ python_list = []
+ for i from 0 <= i < len:
+ python_list.append(retval[i])
+ return python_list
+
+ def get_uint32_array(self):
+ cdef int len
+ cdef dbus_uint32_t *retval
+ dbus_message_iter_get_uint32_array(self.iter, &retval, <int*>&len)
+ python_list = []
+ for i from 0 <= i < len:
+ python_list.append(retval[i])
+ return python_list
+
+ def get_double_array(self):
+ cdef int len
+ cdef double *retval
+ dbus_message_iter_get_double_array(self.iter, &retval, <int*>&len)
+ python_list = []
+ for i from 0 <= i < len:
+ python_list.append(retval[i])
+ return python_list
+
def get_string_array(self):
cdef int len
@@ -606,6 +638,10 @@ cdef class MessageIter:
list_type = type(value[0])
if list_type == str:
self.append_string_array(value)
+ elif list_type == int:
+ self.append_int32_array(value)
+ elif list_type == float:
+ self.append_double_array(value)
elif isinstance(value[0], ObjectPath):
self.append_object_path_array(value)
else:
@@ -640,33 +676,55 @@ cdef class MessageIter:
def append_string(self, value):
return dbus_message_iter_append_string(self.iter, value)
- # FIXME: dbus_message_iter_append_named
-
def append_dict_key(self, value):
return dbus_message_iter_append_dict_key(self.iter, value)
def append_object_path(self, value):
return dbus_message_iter_append_object_path(self.iter, value)
- # FIXME: append_array, append_dict_array, append_boolean_array, append_int32_array, append_uint32_array, append_double_array
+ # FIXME: append_array, append_dict_array, append_boolean_array, append_uint32_array
- def append_byte_array(self, list):
+ def append_byte_array(self, python_list):
cdef unsigned char * value
cdef int length
- length = len(list)
- value = <unsigned char*>malloc(length)
+ length = len(python_list)
+ value = <unsigned char*>malloc(length * sizeof(unsigned char))
for i from 0 <= i < length:
- item = list[i]
+ item = python_list[i]
if type(item) != str or len(item) != 1:
raise TypeError
value[i] = ord(item)
return dbus_message_iter_append_byte_array(self.iter, value, length)
+ def append_int32_array(self, python_list):
+ cdef dbus_int32_t *value
+ cdef int length
+ length = len(python_list)
+ value = <dbus_int32_t*>malloc(length * sizeof(dbus_int32_t))
+ for i from 0 <= i < length:
+ item = python_list[i]
+ if type(item) != int:
+ raise TypeError
+ value[i] = item
+ return dbus_message_iter_append_int32_array(self.iter, value, length)
+
+ def append_double_array(self, python_list):
+ cdef double *value
+ cdef int length
+ length = len(python_list)
+ value = <double*>malloc(length * sizeof(double))
+ for i from 0 <= i < length:
+ item = python_list[i]
+ if type(item) != float:
+ raise TypeError
+ value[i] = item
+ return dbus_message_iter_append_double_array(self.iter, value, length)
+
def append_object_path_array(self, list):
cdef char **value
cdef int length
length = len(list)
- value = <char**>malloc(length)
+ value = <char**>malloc(length * sizeof(char *))
for i from 0 <= i < length:
item = list[i]
if not isinstance(item, ObjectPath):
@@ -680,7 +738,7 @@ cdef class MessageIter:
cdef int length
cdef dbus_bool_t return_code
length = len(python_list)
- value = <char**>malloc(length)
+ value = <char**>malloc(length * sizeof(char *))
for i from 0 <= i < length:
item = python_list[i]
if type(item) != str:
diff --git a/python/tests/test-client.py b/python/tests/test-client.py
index 092ee43b..f08f9861 100644
--- a/python/tests/test-client.py
+++ b/python/tests/test-client.py
@@ -43,5 +43,21 @@ TestEcho(39.5)
TestEcho("HelloWorld")
TestEcho(dbus_bindings.ObjectPath("/test/path"))
-#FIXME!!! Crashes on lists ?!?
-#TestEchoList(["one", "two", "three", "four"])
+
+string_list = []
+for i in range(200):
+ string_list.append("List item " + str(i))
+TestEchoList(string_list)
+
+int_list = range(200)
+TestEchoList(int_list)
+
+path_list = []
+for i in range(200):
+ path_list.append(dbus_bindings.ObjectPath("/some/object/path" + str(i)))
+TestEchoList(path_list)
+
+double_list = []
+for i in range(200):
+ double_list.append(float(i) / 1000)
+TestEchoList(double_list)