[PATCH:libX11 1/2] Bug 32098: Making XInternAtoms take const char ** breaks callers

Simon Thum simon.thum at gmx.de
Tue Dec 14 14:46:12 PST 2010


On 12/14/2010 02:22 AM, Alan Coopersmith wrote:
> Callers who had successfully built without issues with the existing
> libX11 headers were suddenly either given warnings or errors (-Werror)
> with the new headers.
I've stumbled into this and I'd really appreciate if someone could clarify.

AFAIK "const char**" promises "through that pointer no-one messes with
the contents". So why the heck are there no implicit conversions to
catch up with that? Do I need to pass -fapply-common-sense?

Waiting for enlightenment,

Simon

> 
> This compromise solution allows us to move to the correct declaration
> without breaking such callers - if they simply include the headers as
> is, nothing changes for them.   If they want to take advantage of the
> new const declaration to avoid getting warnings from passing arrays of
> string literals, then they can #define XINTERNATOMS_WANT_CONST_NAMES
> before they #include <X11/Xlib.h>.   Callers using pkg-config will
> eventually be able to require x11 > 1.4 to get this - those not using
> pkg-config or not wanting a hard requirement can simply check after
> the #include <X11/Xlib.h> for #ifdef XINTERNATOMS_HAVE_CONST_NAMES
> to see if the header is new enough to have satisfied their request.
> 
> Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
> ---
>  include/X11/Xlib.h |    5 +++++
>  src/IntAtom.c      |    2 ++
>  2 files changed, 7 insertions(+), 0 deletions(-)
> 
> diff --git a/include/X11/Xlib.h b/include/X11/Xlib.h
> index b0d7d4d..c33019e 100644
> --- a/include/X11/Xlib.h
> +++ b/include/X11/Xlib.h
> @@ -1548,7 +1548,12 @@ extern Atom XInternAtom(
>  );
>  extern Status XInternAtoms(
>      Display*		/* dpy */,
> +#ifdef XINTERNATOMS_WANT_CONST_NAMES
> +# define XINTERNATOMS_HAVE_CONST_NAMES
>      _Xconst char**	/* names */,
> +#else
> +    char**		/* names */,
> +#endif
>      int			/* count */,
>      Bool		/* onlyIfExists */,
>      Atom*		/* atoms_return */
> diff --git a/src/IntAtom.c b/src/IntAtom.c
> index 80d78c0..751584a 100644
> --- a/src/IntAtom.c
> +++ b/src/IntAtom.c
> @@ -26,6 +26,8 @@ from The Open Group.
>  
>  */
>  
> +#define XINTERNATOMS_WANT_CONST_NAMES /* must come before Xlib.h is included */
> +
>  #ifdef HAVE_CONFIG_H
>  #include <config.h>
>  #endif



More information about the xorg-devel mailing list