[patch] generate marshallers and metadata from dbus-glib-tool
Havoc Pennington
hp at redhat.com
Fri Nov 19 07:04:23 PST 2004
On Thu, 2004-11-18 at 22:19 -0500, Colin Walters wrote:
> Right, although you never need to swap a byte[] at least.
You only need to swap arrays with elements > 1 byte, essentially.
> Would it be useful to get the unswapped version in general?
If we have a function that returns the swapped version, it has to malloc
a new array. If we have unswapped then it can just give you a const
pointer. You can't really have a function to return either one, since
you wouldn't know whether to free the result. I mean, you could have a
function, but it probably looks sort of ugly to use.
> Maybe a less invasive approach would be a flag on the type, like:
>
> dbus_message_get_args (message,
> (DBUS_TYPE_ARRAY | DBUS_TYPE_FLAG_UNSWAPPED)
> &array,
> &len,
> DBUS_TYPE_INVALID);
Is the array malloc'd or not in that case? I'd assume not (since that's
the whole point) but it's probably a little confusing.
> > - always return by const reference; if you call a getter
> > on a field/arg where byte order matters, and the message is in the
> > wrong byte order, swap the *entire* message in place and then
> > return the const ref. i.e. byteswap lazily.
>
> That might work too, although it sounds a bit hard.
I don't think it's very hard, and it'd be a lot nicer than:
free_foo = false
array foo[] = get_unswapped()
if byte_order != compiler_byte_order:
{
free_foo = true
foo = copy_and_swap (foo)
}
use_foo (foo)
if (free_foo)
free (foo)
If we made the byteswapping transparent to the programmer, then everyone
could always use the const references with convenience loss and stuff
would be faster and nicer and so forth.
But we'd still get the win where the bus never swaps anything since it
would never access any unswapped data.
Havoc
More information about the dbus
mailing list