Dict parsing question

Lawrence D'Oliveiro ldo at geek-central.gen.nz
Tue Jan 2 21:50:30 UTC 2024


I wrote:

> But you don’t know on what boundary the array length is positioned: if
> it’s already at an address that is a multiple of 8 bytes (which could
> happen, say, 50% of the time), then the addition of 4 bytes of padding
> means the element field is no longer 8-byte-aligned.

Sorry, wrong way round: if the initial length field begins on an
address of the form 4n + 4 (where n is an integer), then if you add 4
bytes of padding after that, the first element will also be on an
address of the form 4n + 4, which means it will not be 8-byte-aligned.

To go back to what Simon McVittie said:

> This means that the array will sometimes pack more efficiently than
> how you might have imagined that it worked.

That also means that the array can no longer be laid out as a
self-contained structure, you have to look at how it is located within
the entire message structure. This complicates the problem of building
a message out of component pieces nested within component pieces: you
can’t build each piece in one step and then insert it into its parent
structure in another step: you have to do everything directly within
the final message structure to begin with.


More information about the dbus mailing list