[PATCH libX11 3/5] fix: warning: pointer targets in passing argument 2 of '_XSend' differ in signedness [-Wpointer-sign]

Peter Hutterer peter.hutterer at who-t.net
Mon May 2 22:07:08 UTC 2016


On Sat, Apr 30, 2016 at 11:08:34PM +0200, walter harms wrote:
> 
> 
> Am 29.04.2016 03:03, schrieb Alan Coopersmith:
> > On 04/28/16 04:43 PM, Peter Hutterer wrote:
> >> fixing this isn't going to do much, and adding fake statements neither.
> >> to fix the compiler warnings you could do something like:
> >>
> >> #define _xlib_used_internally __attribute__((unused))
> >>
> >> and then use that to annotate the variable. No need for fake code changes
> >> and it's more expressive.
> > 
> > Yes, if we're going to fix this, please just use attributes instead of
> > adding
> > confusing unused code that some other compiler will warn is being
> > optimized out.
> > 
> > Though I'd prefer _X_UNUSED from <X11/Xfuncproto.h> over the raw attribute
> > to take advantage of the existing compiler checks there to see where it's
> > safe to use.
> > 
> 
> I have tried _X_UNUSED register xReq *req; and it works fine.
> 
> But i still do not understand where req is used.
> 
> The code looks like that here:
> 
>   GetEmptyReq(GetModifierMapping, req);
>     (void) _XReply (dpy, (xReply *)&rep, 0, xFalse);
> 
> GetEmptyReq() is a Macro and expands into this:
> 
>   req = (xReq *) _XGetRequest(dpy, X_GetModifierMapping, SIZEOF(xReq));
> 
> _XGetRequest generates a buffer inside dpy (code in XlibInt.c)
> 
>  _XReply() is a function in xcb_io.c is uses the buffer inside dpy, granted but
> not req. I realy do not see why:
> 
> (void) _XGetRequest(dpy, X_GetModifierMapping, SIZEOF(xReq));
> (void) _XReply (dpy, (xReply *)&rep, 0, xFalse);
> 
> should not work as the code before.
> 
> I am still willing to use _X_UNUSED but i would like to know why not remove req,
> just point me to the line where it is used.

req itself isn't used here, so that's correct and that's why you can use
_X_UNUSED. But the side-effect is that the _XGetRequest() advances the
dpy->bufptr and fills in the bits (request type and length). so next time we
flush the queue, this request will be sent to the server. Since
XGetModifierMapping requires a reply, this happens in _XReply() -> _XSend().

but the return value from _XGetRequest isn't used here  because this request
has no other data than the request type.

> I realy do not see why:
> 
> (void) _XGetRequest(dpy, X_GetModifierMapping, SIZEOF(xReq));
> (void) _XReply (dpy, (xReply *)&rep, 0, xFalse);
> 
> should not work as the code before.

because it is different to every other invocation of the request handlers
(iirc). There is no point in making the code slightly different here and
increasing the cognitive load just to silence a compiler warning when
_X_UNUSED does the same job and leaves the code as-is.

Cheers,
   Peter


More information about the xorg-devel mailing list