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

Povilas Kanapickas povilas at radix.lt
Mon Sep 20 14:53:32 UTC 2021


Hi,

On 9/20/21 5:47 PM, Tycho Andersen wrote:
> On Mon, Sep 20, 2021 at 04:21:25PM +0200, Uli Schlachter wrote:
>> Hi,
>>
>> Am 20.09.21 um 16:12 schrieb Tycho Andersen:
>>> On Mon, Sep 20, 2021 at 04:05:11PM +0200, Uli Schlachter wrote:
>>>> 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?
>>
>> Nothing. So perhaps I am misunderstanding you.
>>
>> What does not have an explicit type with the new <length> element? The
>> field "len" has type="CARD16", doesn't it? Put differently: What is the
>> difference to SetupAuthenticate above?
>>
>>     <struct name="DeviceClass">
>>         <length>
>>             <op op="*">
>>                 <fieldref>len</fieldref>
>>                 <value>4</value>
>>             </op>
>>         </length>
>>         <field type="CARD16"   name="type" enum="DeviceClassType" />
>>         <field type="CARD16"   name="len" />
>> [...]
>>     </struct>
> 
> I see, I think we're both misunderstanding each other :). I understand
> your comparison now, and I think this clears it up for me.
> 
> My initial confusion was that all other kinds of struct elements have
> explicit types (because we need to know how big the thing will be on
> the wire), and this one does not. However, this thing won't be present
> on the wire, so we don't need an explicit type for it either.

Yes, that's correct. Another existing example is the expression that
determines the number of elements in a list.

For example:

    <list type="BYTE" name="data">
        <op op="*">
             <fieldref>abc</fieldref>
             <value>8</value>
        </op>
    </list>

The type="BYTE" in the list element defines the type of the elements.
The length of the list therefore does not have a specific type and is
whatever is calculated by the expression within the list element.

The length element is therefore similar: it's just a value that we can
compute and it has the same semantics as the underlying C expression in
the code that xcb eventually generates.

Cheers,
Povilas


More information about the Xcb mailing list