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

Tycho Andersen tycho at tycho.pizza
Mon Sep 20 14:12:03 UTC 2021


On Mon, Sep 20, 2021 at 04:05:11PM +0200, Uli Schlachter wrote:
> Hi,
> 
> 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="*">
>         <fieldref>length</fieldref>
>         <value>4</value>
>       </op>
>     </list>
>   </struct>
> 
> Here, the length of the list is 4*length and there is again no explicit
> type given for the length.

Huh? The length field has type="CARD16" doesn't it?

The list itself as type="char". Which thing here doesn't have an
explicit type?

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

As you note, these both have types as well.

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

Nothing, other than that everything else does have a type as above.
I'm happy to hard code it if that's the way forward.

Tycho


More information about the Xcb mailing list