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

Christoph Reimann chrr at arcor.de
Sat Jun 5 00:20:40 PDT 2010

Hi again,
in order to parse xkb.xml and implement the <switch> tag I need to fix
a few things in the C code generator:
- currently requests with variable-sized fields that are not lists are
not supported
- neither are requests with lists of variable-sized element.
- and neither are variable-sized fields followed by fixed-sized fields

In order to adress these issues, I would like to change the way how
the request's fields are serialized.
At the moment a struct is filled with all fixed-sized fields collected
together in xcb_out, and it always gets serialized like this:

    xcb_parts[2].iov_base = (char *) &xcb_out;
    xcb_parts[2].iov_len = sizeof(xcb_out);
    xcb_parts[3].iov_base = 0;
    xcb_parts[3].iov_len = -xcb_parts[2].iov_len & 3;
    (... variable-sized fields ...)

Now I would like to do the serializing element-wise, e.g. in case of
the xcb_create_window request

    unsigned int xcb_pad_bytes = 0;
    xcb_parts[2].iov_base = (char *) &depth;
    xcb_parts[2].iov_len  = sizeof(uint8_t);
    xcb_pad_bytes += sizeof(uint8_t);
    xcb_parts[3].iov_base = (char *) &wid;
    xcb_parts[3].iov_len  = sizeof(xcb_window_t);
    xcb_pad_bytes += sizeof(xcb_window_t);
    xcb_parts[4].iov_base = (char *) &parent;
    xcb_parts[4].iov_len  = sizeof(xcb_window_t);
    xcb_pad_bytes += sizeof(xcb_window_t);
    xcb_parts[5].iov_base = (char *) &x;
    xcb_parts[5].iov_len  = sizeof(int16_t);
    xcb_pad_bytes += sizeof(int16_t);
    xcb_parts[6].iov_base = (char *) &y;
    xcb_parts[6].iov_len  = sizeof(int16_t);

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.
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?

Thanks in advance for answers


More information about the Xcb mailing list