[Xcb] _Problems_ in GSoC, 2011

Evgeny M. Zubok evgeny.zubok at tochka.ru
Thu Sep 8 05:50:15 PDT 2011


Jamey Sharp <jamey at minilop.net> writes:

> Here is a sketch of an algorithm that I believe is correct for
> statically computing alignment padding for all X types. I'll use the
> terms from xcbgen/xtypes.py.
>
> First, compute the minimum alignment requirement for every type:
>
> - For every SimpleType and ExprType, including the standard types like
>   CARD8, the alignment required equals the size of the type, but no more
>   than 4 bytes. So CARD8 needs 1 byte, INT16 needs 2 bytes, FLOAT needs
>   4 bytes, and DOUBLE also needs 4 bytes.

I think we don't need to verify the alignment for SimpleTypes. They are
already properly aligned with <pad bytes="...">. We only need their
sizes for the calculation of current total size.

> - Request, Reply, Event, and Error types always have 4-byte alignment.
>
> - For StructType and UnionType, the alignment is the maximum alignment
>   needed by any field in the struct or union. So STR, which is a struct
>   containing a CARD8 and a list of CARD8, only needs 1-byte alignment;
>   but a struct containing an INT16 and a DOUBLE needs 4-byte alignment.


Will it work for structures? Compare:

Examples with padding:
---------------------

xproto.xml:

  <struct name="HOST">
    <field type="CARD8" name="family" enum="Family" />
    <pad bytes="1" />
    <field type="CARD16" name="address_len" />
    <list type="BYTE" name="address">
      <fieldref>address_len</fieldref>
    </list>
    <!-- standard states padding here -->
    <pad align="4"><sizeof>address</sizeof></pad>
  </struct>

sync.xml:

  <struct name="SYSTEMCOUNTER">
    <field type="COUNTER" name="counter" />
    <field type="INT64" name="resolution" />
    <field type="CARD16" name="name_len" />
    <list type="char" name="name">
      <fieldref>name_len</fieldref>
    </list>
    <!-- standard states padding here -->
    <pad align="4">
      <op op="+">
	<sizeof>name</sizeof>
	<value>2</value>
      </op>
    </pad>
  </struct>

xkb.xml:

  <struct name="Listing">
    <field name="flags" type="CARD16" />
    <field name="length" type="CARD16" />
    <list name="string" type="STRING8">
      <fieldref>length</fieldref>
    </list>
    <!-- Spec states pad to a 2-byte boundary -->
    <pad align="2"><sizeof>string</sizeof></pad>
  </struct>

The similar examples without padding
------------------------------------

xv.xml:

  <struct name="AttributeInfo">
    <field type="CARD32" name="flags" mask="AttributeFlag" />
    <field type="INT32" name="min" />
    <field type="INT32" name="max" />
    <field type="CARD32" name="size" />
    <list type="char" name="name">
       <fieldref>size</fieldref>
    </list>
  </struct>

xkb.xml: STRING8 declared as char

  <struct name="Property">
    <field name="nameLength" type="CARD16" />
    <list name="name" type="STRING8">
      <fieldref>nameLength</fieldref>
    </list>
    <field name="valueLength" type="CARD16" />
    <list name="value" type="STRING8">
      <fieldref>valueLength</fieldref>
    </list>
  </struct>

However, the natural alignment rule (or some variants of) will probably
work for requests, replies, events and errors. If it's so, we will only
need to explicitly insert an alignment into the few structures.


> - For ListTypes, the alignment is the same as the member type's
>   alignment.

I suppose that the rule for lists in requests and replies is simpler:
the list of any type should always be positioned with 4-byte alignment.


> I haven't thought about the rules for Switch or Bitcase yet.



More information about the Xcb mailing list