[Xcb] Question: Why are structs not serialized elementwise in the autogenerated C cocde?

Peter Harris pharris at opentext.com
Wed Jun 9 08:38:31 PDT 2010

On 2010-06-05 03:20, Christoph Reimann wrote:
> When everything gets serialized like this, there should be no problem
> in handling variable-sized structs etc. as the serializer code can
> always be generated recursively in c_client.py.

I suspect it was never done this way for performance reasons. Larger
iovecs mean more dcache usage, more setting means more icache usage, and
processing all the extra elements means more CPU usage.

That said, I doubt anyone has ever measured the difference. Perhaps you
could measure and let us know.

Alternatively, you could automatically join adjacent fields where
possible, allowing you to insert variable fields without changing the
output in the case where there are no variable fields. I'm not sure how
much code would be needed to do that in c_client.py.

> One more thing: What is the rule for padding with respect to xcb_parts?
> At the moment element no. 3 is always
>     xcb_parts[3].iov_base = 0;
>     xcb_parts[3].iov_len = -xcb_parts[2].iov_len & 3;
> and also code like this gets inserted between fixed and variable sized
> data. When is it necessary to insert padding?

It is necessary to insert padding before any list of items of size
greater than byte, as all fields are naturally aligned in the X protocol.

That said, I'd be much happier if all padding was explicitly specified
in the .xml files, and none was ever automagically inserted by any of
the generators. See, for example, commit 0d62c1d0 (and surrounding
commit series) where we added some of the missing padding. It wouldn't
surprise me to discover that we'd missed some.

Support of <pad align= /> could simplify some of the padding that hasn't
been added yet (struct "Setup" between "vendor" and "pixmap_formats",
for example).

But I think we're getting beyond the scope of your GSoC project here.

Peter Harris
               Open Text Connectivity Solutions Group
Peter Harris                    http://connectivity.opentext.com/
Research and Development        Phone: +1 905 762 6001
pharris at opentext.com            Toll Free: 1 877 359 4866

More information about the Xcb mailing list