You are viewing a plain text version of this content. The canonical link for it is here.
Posted to apreq-dev@httpd.apache.org by Joe Schaefer <jo...@sunstarsys.com> on 2005/02/16 13:56:50 UTC

Re: [multi-env] illegal escape sequence

Randy Kobes <ra...@theoryx5.uwinnipeg.ca> writes:

> On Win32, in the multi-env branch (but also in trunk), I get
> an error when compiling library/t/cookie.c:
>
> D:\svn\MULTI-~1\library\t\cookie.c(114) :
>     error C2017: illegal escape sequence
>
> This arises whenever an escaped quote is used, as in
>    "rfc=out; Version=1; domain=\"example.com\""
> of line 114 in cookie.c, apparently due to VC++ not being
> able to correctly use AT_str_eq() of at.h in this case. I've
> found qualitatively similar problems with google, but can't
> find something that works here - does this ring a bell with
> anyone? Thanks.

Boggle: what happens when you feed that string to this macro:

  #define QUOTE_ME(foo) #foo
  const char bar[] = QUOTE_ME("rfc=out; Version=1; domain=\"example.com\"");

K&R says this about #foo:

  First, if an occurrence of a parameter in the replacement token
  sequence is immediately preceded by ##, string quotes (") are placed
  around the corresponding parameter, and then both the # and the 
  parameter identifier are replaced by the quoted argument.  A \ character
  is inserted before each " or \ character that appears surrounding,
  or inside, a string literal of character constant in the argument.

I take this to mean that the above expands to

  const char bar[] = "\"rfc=out; Version=1; domain=\\\"example.com\\\"\"";

Does VC++ think this is an illegal escape sequence as well?
It'd be nice to know exactly what the preprocessor finds 
objectionable here; maybe the at.h just needs the usual 

#ifdef  __cplusplus
 extern "C" {
#endif 

wrapper (C++ may have tighter macro expansion rules)?

-- 
Joe Schaefer


Re: [multi-env] illegal escape sequence

Posted by Joe Schaefer <jo...@sunstarsys.com>.
Joe Schaefer <jo...@sunstarsys.com> writes:

[...]

> K&R says this about #foo:

page 230 in my copy.

>
>   First, if an occurrence of a parameter in the replacement token
>   sequence is immediately preceded by ##, string quotes (") are placed
                                        ^^
typo: '#'

>   around the corresponding parameter, and then both the # and the 
>   parameter identifier are replaced by the quoted argument.  A \ character
>   is inserted before each " or \ character that appears surrounding,
>   or inside, a string literal of character constant in the argument.
                                ^^
typo: 'or'

-- 
Joe Schaefer


Re: [multi-env] illegal escape sequence

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Fri, 18 Feb 2005, Stas Bekman wrote:

> Randy Kobes wrote:
> [...]
> > Just as a further note on this - I asked Steve Hay to check
> > out this problem with VC++ 7, and he found it gives the same
> > results as gcc. So it looks like it is a bug in VC++ 6
> > that's been fixed in 7. However, because ActiveState uses
> > VC++ 6 to compile Win32 ActivePerl, and since there's some
> > differences between 6 and 7 that affect users (different
> > run-time libraries, some incompatibilities in principle when
> > mixing), we still have to support VC++ 6.
>
> If it's possible to recognize at build time which compiler version is
> used, may be it's possible to generate VC++-6 specific header which will
> please it? or is there a C macro that tells us that it's VC++-6?

There is a macro available that gives the version of VC++ -
that's a good idea to just use the workaround for 6; I'll
look into this.

-- 
best regards,
randy

Re: [multi-env] illegal escape sequence

Posted by Stas Bekman <st...@stason.org>.
Randy Kobes wrote:
[...]
> Just as a further note on this - I asked Steve Hay to check
> out this problem with VC++ 7, and he found it gives the same
> results as gcc. So it looks like it is a bug in VC++ 6
> that's been fixed in 7. However, because ActiveState uses
> VC++ 6 to compile Win32 ActivePerl, and since there's some
> differences between 6 and 7 that affect users (different
> run-time libraries, some incompatibilities in principle when
> mixing), we still have to support VC++ 6.

If it's possible to recognize at build time which compiler version is 
used, may be it's possible to generate VC++-6 specific header which will 
please it? or is there a C macro that tells us that it's VC++-6?

-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

Re: [multi-env] illegal escape sequence

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Thu, 17 Feb 2005, Randy Kobes wrote:

> On Thu, 17 Feb 2005, Joe Schaefer wrote:
>
> > Randy Kobes <ra...@theoryx5.uwinnipeg.ca> writes:
> >
> > [...]
> >
> > > I see you just provided a Win32 workaround in cookie.c -
> >
> > Yup, no need to waste time on WinFU sillyness.
> > The string literals are inside the macros just
> > to produce better debug messages, which IMO isn't
> > worth this much attention.  If the problem persists
> > elsewhere, I suggest we just route around it with
> > something similar.

Just as a further note on this - I asked Steve Hay to check
out this problem with VC++ 7, and he found it gives the same
results as gcc. So it looks like it is a bug in VC++ 6
that's been fixed in 7. However, because ActiveState uses
VC++ 6 to compile Win32 ActivePerl, and since there's some
differences between 6 and 7 that affect users (different
run-time libraries, some incompatibilities in principle when
mixing), we still have to support VC++ 6.

-- 
best regards,
randy

Re: [multi-env] illegal escape sequence

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Thu, 17 Feb 2005, Joe Schaefer wrote:

> Randy Kobes <ra...@theoryx5.uwinnipeg.ca> writes:
>
> [...]
>
> > I see you just provided a Win32 workaround in cookie.c -
>
> Yup, no need to waste time on WinFU sillyness.
> The string literals are inside the macros just
> to produce better debug messages, which IMO isn't
> worth this much attention.  If the problem persists
> elsewhere, I suggest we just route around it with
> something similar.

Agreed :)

> > thanks!
>
> Heh, we'll see about that... lots of new multi-env
> problems will soon be coming your way.  Hope you're
> not having too much trouble keeping up so far. If
> you are, just holler ;-).

:) With the fix in cookie.c, all but the first 3 tests in
library/t/parsers.c pass for me on Win32 (on the C side).
These failures are the same ones as the corresponding
failures reported here:
   http://marc.theaimsgroup.com/?t=110784648400001&r=1&w=2
about comparing things coming from apreq_parser. I'll
look into this in a new thread.

-- 
best regards,
randy

Re: [multi-env] illegal escape sequence

Posted by Joe Schaefer <jo...@sunstarsys.com>.
Randy Kobes <ra...@theoryx5.uwinnipeg.ca> writes:

[...]

> I see you just provided a Win32 workaround in cookie.c -

Yup, no need to waste time on WinFU sillyness.
The string literals are inside the macros just 
to produce better debug messages, which IMO isn't
worth this much attention.  If the problem persists
elsewhere, I suggest we just route around it with
something similar.

> thanks!

Heh, we'll see about that... lots of new multi-env
problems will soon be coming your way.  Hope you're
not having too much trouble keeping up so far. If
you are, just holler ;-).

-- 
Joe Schaefer


Re: [multi-env] illegal escape sequence

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Thu, 17 Feb 2005, Joe Schaefer wrote:

> Nice work- so it chokes on the final escaped quote,
> right?

Yes, that's right - it seems to get the 1st escaped
quote right, but then messes up subsequent ones (and
it doesn't matter that in this case the final one
occurs at the end - moving it elsewhere produces the
same error).

> See what it does with a single, escaped quote
> char:
>
>     QUOTE_ME("\"")

That works OK.

> If it escapes that properly, you *might* be able to
> get somewhere by breaking the string literal into two
> pieces:
>
>     QUOTE_ME("domain=\"example.com" "\"")
>
> or
>
>    QUOTE_ME("domain=\"example.com") QUOTE_ME("\"")

That does change things, but I haven't found a combination
that works yet - I'll keep experimenting.

I tried this out with Borland's Win32 (free) compiler,
bcc32, and while it gets the escaped quotes right, it misses
the closing quote.

I see you just provided a Win32 workaround in cookie.c -
thanks!

-- 
best regards,
randy

Re: [multi-env] illegal escape sequence

Posted by Joe Schaefer <jo...@sunstarsys.com>.
Randy Kobes <ra...@theoryx5.uwinnipeg.ca> writes:

[...]

> which is OK. However
>
> int main(void) {
>    const char bar[] = QUOTE_ME("domain=\"example.com\"");
>    printf("bar is %s\n", bar);
>    return 0;
> }
>
> expands to
>
> int main(void) {
>    const char bar[] = "\"domain=\\\"example.com\\"\"";
>    printf("bar is %s\n", bar);
>    return 0;
> }
>
> which explains the "illegal escape sequence" error.
> This is with VC++ 6 (with gcc, both the above are fine).
>
> I'll keep looking for solutions ...

Nice work- so it chokes on the final escaped quote, 
right?  See what it does with a single, escaped quote 
char:

    QUOTE_ME("\"")

If it escapes that properly, you *might* be able to 
get somewhere by breaking the string literal into two
pieces:

    QUOTE_ME("domain=\"example.com" "\"")

or 

   QUOTE_ME("domain=\"example.com") QUOTE_ME("\"")

-- 
Joe Schaefer


Re: [multi-env] illegal escape sequence

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Wed, 16 Feb 2005, Joe Schaefer wrote:

> Joe Schaefer <jo...@sunstarsys.com> writes:
>
> [...]
>
> > Boggle: what happens when you feed that string to this macro:
> >
> >   #define QUOTE_ME(foo) #foo
> >   const char bar[] = QUOTE_ME("rfc=out; Version=1; domain=\"example.com\"");
> >
> > K&R says this about #foo:
>
> The VC6 docs even include a similar example
>
>     <URL:
>         http://msdn.microsoft.com/library/default.asp?
>         url=/library/en-us/vccore98/html/_predir_stringizing_operator.asp
>      >
>
> Staring at the offending code in at.h, I can't
> see what the problem might be here so I'll just
> shut up now. I trust you guys will come up with
> a good solution.

:) Thanks for the pointers, Joe. I'm sure this problem
must have come up in other contexts. For one thing, I found
this suggestion (in a newsgroup) to use:

#define QUOTE_ME_HELPER(foo) #foo
#define QUOTE_ME(foo) QUOTE_ME_HELPER(foo)

But using this or the one you suggested doesn't make a
difference in the following. The following (which is
similar to an example on the msdn site):

int main(void) {
   const char bar[] = QUOTE_ME("domain=\"example.com");
   printf("bar is %s\n", bar);
   return 0;
}

expands to

int main(void) {
   const char bar[] = "\"domain=\\\"example.com\"";
   printf("bar is %s\n", bar);
   return 0;
}

which is OK. However

int main(void) {
   const char bar[] = QUOTE_ME("domain=\"example.com\"");
   printf("bar is %s\n", bar);
   return 0;
}

expands to

int main(void) {
   const char bar[] = "\"domain=\\\"example.com\\"\"";
   printf("bar is %s\n", bar);
   return 0;
}

which explains the "illegal escape sequence" error.
This is with VC++ 6 (with gcc, both the above are fine).

I'll keep looking for solutions ...

-- 
best regards,
randy

Re: [multi-env] illegal escape sequence

Posted by Joe Schaefer <jo...@sunstarsys.com>.
Joe Schaefer <jo...@sunstarsys.com> writes:

[...]

> Boggle: what happens when you feed that string to this macro:
>
>   #define QUOTE_ME(foo) #foo
>   const char bar[] = QUOTE_ME("rfc=out; Version=1; domain=\"example.com\"");
>
> K&R says this about #foo:

The VC6 docs even include a similar example

    <URL:
        http://msdn.microsoft.com/library/default.asp?
        url=/library/en-us/vccore98/html/_predir_stringizing_operator.asp
     >

Staring at the offending code in at.h, I can't 
see what the problem might be here so I'll just 
shut up now. I trust you guys will come up with 
a good solution.

-- 
Joe Schaefer


Re: [multi-env] illegal escape sequence

Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
At 06:56 AM 2/16/2005, Joe Schaefer wrote:
>Does VC++ think this is an illegal escape sequence as well?
>It'd be nice to know exactly what the preprocessor finds 
>objectionable here; maybe the at.h just needs the usual 
>
>#ifdef  __cplusplus
> extern "C" {
>#endif 

Nope.  extern "C" is code scope, nested deeper than the scope 
of the cpp macro preprocessor's operation, so what you propose 
should be a noop.

Meaning to try reproducing later this week or saturday.

Bill