[Xcb] names of nested structs of named bitcase/case are prone to nameclashes. Solution?

josh at joshtriplett.org josh at joshtriplett.org
Tue Sep 2 11:42:05 PDT 2014


On Tue, Sep 02, 2014 at 06:43:51PM +0200, Christian Linhart wrote:
> On 09/02/14 17:22, Josh Triplett wrote:
> > 4: use 3 for any structs we've already named to avoid changing the API,
> > deprecate the names, and avoid naming any new inner structs (2).  If
> > application code *really* needs the inner struct types, there's always
> > typeof().
> 
> Good idea.
> This will need an attribute to tell the generator whether
> to generate the old style code or whether to generate the new style code.
> 
> Reason:
> the name-attribute of a case/bitcase is also used for 
> the field-name, like "key" in the example below,
> and that's still needed:
> 
>     typedef struct xcb_input_input_state_data_t {
>         struct {
>                 uint8_t  num_keys; /**<  */
>             uint8_t  pad0; /**<  */
>             uint8_t  keys[32]; /**<  */
>         } key;
>        /* ^^^ Still needed */
> 
> In the xml, for existing xml-defs it will look like it always looked
> which will create a type name as always:
>             <case name="key">
> will generate
>         struct _key{
>                 uint8_t  num_keys; /**<  */
>             uint8_t  pad0; /**<  */
>             uint8_t  keys[32]; /**<  */
>         } key;
> as before.
> 
> 
> For new xml-defs we could use an extra-attribute or using another attribute-name for the name:
>             <case name="key" anon-struct="true">
> or e.g.
>             <case casename="key">
> 
> will generate
>         struct{
>                 uint8_t  num_keys; /**<  */
>             uint8_t  pad0; /**<  */
>             uint8_t  keys[32]; /**<  */
>         } key;
> as before.
> 
> Which of the two attribute variants do you like more? ( extra attribute or other attribute-name for the name )

I'd like to avoid the "anon-struct", since we want this for all new
sub-structures, so we should make it the default.  I'd suggest leaving
"name", and adding something like named-type="true" for the structs
where we *should* name the type.

- Josh Triplett


More information about the Xcb mailing list