[PATCH xrdb] predefined cpp macros can produce unexpected results (bug 3413)
Matthieu Herrb
matthieu.herrb at laas.fr
Sun Dec 5 13:39:20 PST 2010
On Fri, Dec 03, 2010 at 05:38:06PM -0500, Gaetan Nadon wrote:
> On Fri, 2010-12-03 at 15:52 -0500, Matt Turner wrote:
>
> > From: Matthieu Herrb <matthieu.herrb at laas.fr>
> >
> > GNU cpp is predefining a number of symbols, depending on the host and target
> > architecture. This can produce some unexpected results: for example, the
> > expansion of CLIENTHOST if the host name is i386.my.domain.
> >
> > The attached patch creates a new -undef option to xrdb that is passed to
> > cpp.
> > ---
> > Should it be on by default?
> >
> > Matthieu, please give your Signed-off-by.
> >
> > xrdb.c | 12 +++++++++++-
> > xrdb.man | 4 ++++
> > 2 files changed, 15 insertions(+), 1 deletions(-)
> >
> > diff --git a/xrdb.c b/xrdb.c
> > index 21005c0..68accf8 100644
> > --- a/xrdb.c
> > +++ b/xrdb.c
> > @@ -479,8 +479,11 @@ DoCmdDefines(String *buff)
> > *val = '=';
> > } else
> > AddSimpleDef(buff, arg + 2);
> > - } else
> > + } else if (arg[1] == 'U') {
> > AddUndef(buff, arg + 2);
> > + } else if (!strcmp(arg, "-undef") && oper != OPSYMBOLS) {
> > + addstring(buff, " -undef");
> > + }
> > }
> > }
> >
> > @@ -867,6 +870,13 @@ main(int argc, char *argv[])
> > fatal("%s: Too many -U/-D arguments\n", ProgramName);
> > }
> > continue;
> > + } else if (!strcmp ("-undef", arg)) {
> > + if (num_cmd_defines < MAX_CMD_DEFINES) {
> > + cmd_defines[num_cmd_defines++] = "-undef";
> > + } else {
> > + fatal("%s: Too many cpp arguments\n", ProgramName);
> > + }
> > + continue;
> > }
> > Syntax ();
> > } else if (arg[0] == '=')
> > diff --git a/xrdb.man b/xrdb.man
> > index d0d45ad..ddf1a73 100644
> > --- a/xrdb.man
> > +++ b/xrdb.man
> > @@ -223,6 +223,10 @@ This option indicates that
> > should not run the input file through a preprocessor before loading it
> > into properties.
> > .TP 8
> > +.B -undef
> > +This option is passed to the C preprocessor if used. It prevents it from
> > +predefining any system specific macros.
> > +.TP 8
> > .B \-symbols
> > This option indicates that the symbols that are defined for the preprocessor
> > should be printed onto the standard output.
>
>
> If I understand, strings like CLIENTHOST were not meant to be
> substituted.
>
> What if the pre-processor is not a GNU cpp? Solaris or something
> else.
You loose, but iirc Solaris or other cpp I know of don't pre-define
any macro.
>
> You might want to look at this link, it looks like -undef does not work
> properly on CYGWIN gcc 2.95.
> http://www.cygwin.com/ml/cygwin/2002-05/msg01613.html
Not sure if this is still relevant.
>
> The gcc doc is pretty vague as to what will not be substituted. It would
> be nice to have a list of such symbols in the commit to help
> investigation if something is not expected.
run cpp -dM -E - < /dev/null to figure it out for a given machine.
Most macros are prefixed by __ so the likelyhood of them beeing
present in a X resource file is low, but there are sill a few like
'linux' 'unix' present on Ubuntu 10.4 which can cause harm if someone
wants to configure a resource containing those words.
--
Matthieu Herrb
More information about the xorg-devel
mailing list