[Xcb] Alignment problems in XKB GetGeometry

Ran Benita ran234 at gmail.com
Mon Aug 5 00:45:09 PDT 2013


On Mon, Aug 05, 2013 at 01:21:10AM +0200, Daniel Martin wrote:
> On Sun, Aug 04, 2013 at 11:57:10PM +0300, Ran Benita wrote:
> > Now if I try to change xkb.xml to read simply:
> > 
> > 	<struct name="Property">
> > 		<field name="name" type="CountedString16" />
> > 		<field name="value" type="CountedString16" />
> > 	</struct>
> > 
> > Then struct xcb_xkb_property_t is empty, which is undefined behavior
> > (AFAIK) and doesn't work anyway (the padding calculations becomes
> > confused). If I try to inline the CountedString16 definition into
> > Property, it doesn't work either.
> > 
> > Are there any suggestions on how I might proceed?
> 
> The generated struct is empty, because variadic length fields will be
> omitted. But, having an empty struct at the end is suboptimal. Sure.
> 
> Did you saw the new functions, that've been generated due to the change
> in the struct?:
>   xcb_xkb_counted_string_16_t *xcb_xkb_property_name (const xcb_xkb_property_t *R  /**< */)
> and
>   xcb_xkb_counted_string_16_t *xcb_xkb_property_value (const xcb_xkb_property_t *R  /**< */).

Yes, I've tried. But the padding calculation becomes confused. Let me try
to explain what happens. As above, there is a "labelFont"
CountedString16 followed by a list of properties (key-value pairs).
Looking at the first property only, this is correct:

labelFont = "-*-helvetica-medium-r-normal--*-120-*-*-*-*-iso8859-1"
name[0]   = "description"
value[0]  = "Generic 104"

With current (misaligned) xkb.xml what happens is:

labelFont = "-*-helvetica-medium-r-normal--*-120-*-*-*-*-iso8859-1"
name[0]   = "description"
value[0]  = "" (length is read incorrectly as 0)

With changing Property to two CountedString16's:

labelFont = "-*-helvetica-medium-r-normal--*-120-*-*-*-*-iso8859-1"
name[0]   = "-*-helvetica-medium-r-normal--*-120-*-*-*-*-iso8859-1"
value[0]  = "description"

The problem occurs in xcb_xkb_get_geometry_properties_iterator(). Here's
the generated code:

xcb_xkb_property_iterator_t
xcb_xkb_get_geometry_properties_iterator(const xcb_xkb_get_geometry_reply_t *R)
{
    xcb_xkb_property_iterator_t i;
    /* This returns a correct value, if I understand the purpose of the
     * 'index' field correctly.. */
    xcb_generic_iterator_t prev = xcb_xkb_counted_string_16_alignment_pad_end(xcb_xkb_get_geometry_label_font(R));

    /* XCB_TYPE_PAD comes out -56, which brings prev.data right back to
     * the beginning of the previous CountedString16. */
    i.data = (xcb_xkb_property_t *) ((char *) prev.data + XCB_TYPE_PAD(xcb_xkb_property_t, prev.index));

    i.rem = R->nProperties;
    i.index = (char *) i.data - (char *) R;
    return i;
}

So something's wrong here.

Thanks for the help,
Ran


More information about the Xcb mailing list