how can I receive an ARRAY via dbus_message_get_args interface?

Mike Gorse mgorse at novell.com
Wed May 25 20:55:14 PDT 2011


Hi Songyue,

On Thu, 26 May 2011, Wang, Songyue wrote:

> In dbus_get.c:
> dbus_int32_t array[] = {0,0,0};
> dbus_int32_t *v_ARRAY = array;
> dbus_message_get_args (message, &dberr,DBUS_TYPE_ARRAY,DBUS_TYPE_INT32,&v_ARRAY,3, DBUS_TYPE_INVALID);

You're misunderstanding the way dbus_message_get_args handles arrays.  It 
does not copy the array into memory that you allocated.  After the call, 
v_array will be modified to point to the array data within the message 
(so, if you need the data after the message goes away, then you'll need to 
copy it, except for string arrays).  The next parameter should point to an 
int where the count of items in the array will be written.  I think your 
code is crashing because you're trying to pass in the number of elements 
you're expecting while libdbus assumes that you've passed a pointer for it 
to store the count.

Hth,
-Mike


More information about the dbus mailing list