[Xcb] EWMH API for XCB

Josh Triplett josh at joshtriplett.org
Tue Dec 15 16:51:25 PST 2009


On Wed, Dec 16, 2009 at 01:14:47AM +0100, Arnaud Fontaine wrote:
> >>>>> Jamey Sharp <jamey at minilop.net> writes:
>     > Yeah, the data_len parameter in xcb_ewmh_send_client_message isn't
>     > a constant,  so it can't be checked at compile  time. I meant that
>     > you'd add something like this in every caller:
> 
>     > BUILD_BUG_ON(sizeof data > sizeof ((xcb_client_message_event_t *)
>     > 0)->data);
> 
>     > Unlike an  assertion, this doesn't generate any  code; instead the
>     > compiler  can prove  that all  those calls are  safe, but  only if
>     > you've  checked all the callers,  which is why  I suggested making
>     >     this    function    static.     Also,    you     could    wrap
>     > xcb_ewmh_send_client_message up in a  macro that does this, if you
>     >  wanted.
> 
>     >> I'm a bit confused by this macro and does not understand anything
>     >>  besides of  the basic  principle.  I was  thinking about  simply
>     >> adding an assertion otherwise.
> 
>     > Absolutely, that would be better than nothing.
> 
> Well, I think  it would be better to  not make it static as  it could be
> useful to any program implementing extensions to EWMH. Therefore, I have
> just added an assert()[0]. I think it's ok this way, isn't it?

In XCB, we've had some bad experiences with asserts, simply because
end-users notice them and blame XCB rather than buggy applications. :)
Detecting problems at compile time seem ideal when you can.  This case
seems somewhat less problematic since an application would have to
explicitly use your new library; however, I'd still suggest doing as
much checking as you possibly can at compile time.

- Josh Triplett


More information about the Xcb mailing list