[Xcb] new "length" element needs a type?

Uli Schlachter psychon at znc.in
Mon Sep 20 14:05:11 UTC 2021


Am 19.09.21 um 15:34 schrieb Tycho Andersen:
> There is a new length element for structs documented in c36dde3f4535
> ("Add element to specify expression that defines length of a struct")
> with a first use introduced in f0db8b7d31a3 ("xinput: Add length
> specification for DeviceClass struct"), but as near as I can tell
> there's no type information for this, either in the docs or in this
> particular usage.

Why does there need to be a type? Other uses of expressions in the XML
are also untyped.

For example:

  <struct name="SetupAuthenticate">
    <field type="CARD8" name="status" /> <!-- always 2 -> Authenticate -->
    <pad bytes="5" />
    <field type="CARD16" name="length" />
    <list type="char" name="reason">
      <op op="*">

Here, the length of the list is 4*length and there is again no explicit
type given for the length.

A "fun" example is "ChangeProperty". It contains a list of length
data_len * format / 8 where data_len has type CARD32 and format has CARD8.

If you really want to infer a type, you could look at the expression.
Things like <value>4</value> do not really constraint the type. But
<fieldref>len</fieldref> has the type of the "len" field. So, in the
DeviceClass example, the type of the length would be CARD16 (and you
risk integer overflows in the "4*"). For "ChangeProperty", one would
have to somehow infer CARD32.

Alternatively, this is about a length, so you can just always assume
that the length is of type size_t. What would be wrong with that?

- He wants the impossible...!
- That's the short definition of 'captain'.

More information about the Xcb mailing list