[Xcb] [Xcb-commit] 3 commits - src xcbgen

Eamon Walsh ewalsh at tycho.nsa.gov
Thu May 22 12:16:25 PDT 2008


Jeremy Kolb wrote:
> On Wed, 2008-05-21 at 19:50 -0700, Eamon Walsh wrote:
>   
>> src/sync.xml    |    6 +++---
>>  xcbgen/types.py |    4 +++-
>>  2 files changed, 6 insertions(+), 4 deletions(-)
>>
>> New commits:
>> commit 3e8dbef32e691150ca1c86a2bccfd4458ef16190
>> Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
>> Date:   Wed May 21 22:49:14 2008 -0400
>>
>>     Avoid using enum types as structure fields.
>>
>> diff --git a/src/sync.xml b/src/sync.xml
>> index a60a81f..386d233 100644
>> --- a/src/sync.xml
>> +++ b/src/sync.xml
>> @@ -55,9 +55,9 @@ for licensing information.
>>  
>>    <struct name="TRIGGER">
>>      <field type="COUNTER" name="counter" />
>> -    <field type="VALUETYPE" name="wait_type" />
>> +    <field type="CARD32" name="wait_type" />
>>      <field type="INT64" name="wait_value" />
>> -    <field type="TESTTYPE" name="test_type" />
>> +    <field type="CARD32" name="test_type" />
>>    </struct>
>>  
>>    <struct name="WAITCONDITION">
>> @@ -154,7 +154,7 @@ for licensing information.
>>        <field type="TRIGGER" name="trigger" />
>>        <field type="INT64" name="delta" />
>>        <field type="BOOL" name="events" />
>> -      <field type="ALARMSTATE" name="state" />
>> +      <field type="CARD8" name="state" />
>>      </reply>
>>    </request> 
>>     
>
> Wouldn't it be better to use enum fields?  That way other language
> bindings can do cool things while the c bindings use the appropriate
> CARD.  It would also make documentation clearer.
>
> Jeremy
>
>   

The appropriate CARD to use is not present in the current schema.  If 
you look at the generated sync.h from before this patch, the 
QueryAlarmReply "state" structure field changed above was declared as 
"xcb_alarmstate_t" which would take the default size of enums on the 
host, often a 4-byte int but it varies.  This is an encoding error since 
that field is specified as CARD8 in the spec.

I ran into this by accident and decided to fix it since sync.xml is the 
only place that uses enum types in structures.  If you want to 
communicate the enum info, perhaps add an attribute to schema for enum 
tags, e.g. <enum name="foo" type="CARD8">, or field tags, e.g. <field 
type="CARD8" enum="foo">.  This would allow request calls to take enum 
parameters, but I can't see a solution for reply structures such as 
QueryAlarmReply; the size of enum types can't be explicitly set, so they 
can't be used as structure fields.



-- 
Eamon Walsh <ewalsh at tycho.nsa.gov>
National Security Agency



More information about the Xcb mailing list