[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: incorrect error locations for command-line code
From: |
Aharon Robbins |
Subject: |
Re: incorrect error locations for command-line code |
Date: |
Wed, 06 Sep 2006 02:12:25 +0300 |
Andy,
Hi. I've applied the second patch to my sources and added a test.
Work is in progress on getting a public read-only CVS archive set up. No
news yet, but I'll announce it when it's available.
Thanks!
Arnold
> Date: Tue, 05 Sep 2006 14:57:44 -0400
> From: "Andrew J. Schorr" <address@hidden>
> Subject: incorrect error locations for command-line code
> To: address@hidden
>
> --sdtB3X0nJg68CQEu
> Content-Type: text/plain; charset=us-ascii
> Content-Disposition: inline
>
>
> Hi,
>
> It seems that using a mix of code supplied with '-f' and --source
> can lead to errors being reported with the wrong location (using
> gawk version 3.1.5). The problem is best understood with some examples:
>
> This is correct:
>
> bash-3.00$ ./gawk 'BEGIN {return junk}'
> gawk: BEGIN {return junk}
> gawk: ^ `return' used outside function context
>
> This is also correct:
>
> bash-3.00$ ./gawk --source 'BEGIN {return junk}'
> gawk: BEGIN {return junk}
> gawk: ^ `return' used outside function context
>
> But this is wrong:
>
> bash-3.00$ ./gawk -f /dev/null --source 'BEGIN {return junk}'
> gawk: /dev/null:1: BEGIN {return junk}
> gawk: /dev/null:1: ^ `return' used outside function context
>
> As you can see, the error is incorrectly reported as occurring inside
> /dev/null. It seems that awkgram.y:get_src_buf fails to reset the
> source & sourceline global variables correctly when it encounters
> the CMDLINE code.
>
> A possible patch is attached. Note that this patch changes current
> behavior slightly, in that it causes the original (correct) behavior
> above to change slightly to include a "cmd. line:1" label. Here are the
> examples with this patch in place:
>
> bash-3.00$ ./gawk 'BEGIN {return junk}'
> gawk: cmd. line:1: BEGIN {return junk}
> gawk: cmd. line:1: ^ `return' used outside function context
>
> bash-3.00$ ./gawk --source 'BEGIN {return junk}'
> gawk: cmd. line:1: BEGIN {return junk}
> gawk: cmd. line:1: ^ `return' used outside function context
>
> bash-3.00$ ./gawk -f /dev/null --source 'BEGIN {return junk}'
> gawk: cmd. line:1: BEGIN {return junk}
> gawk: cmd. line:1: ^ `return' used outside function context
>
> If that behavior is not desirable (to include the "cmd. line:1" location
> even when the command-line code does not included an embedded newline),
> then the 2nd patch can be used.
>
> Regards,
> Andy
>
>
> #####################################################################################
> This Mail Was Scanned by 012.net AntiVirus Service2- Powered by TrendMicro
> Interscan
> --sdtB3X0nJg68CQEu
> Content-Type: text/plain; charset=us-ascii
> Content-Disposition: attachment; filename="errloc1.patch"
>
> --- awkgram.y.errloc 2005-07-26 14:07:43.000000000 -0400
> +++ awkgram.y 2006-09-05 14:48:41.162413000 -0400
> @@ -1271,7 +1271,6 @@ again:
> }
> if (srcfiles[nextfile].val[l-1] == '\n') {
> /* has terminating newline, can use it directly */
> - sourceline = 1;
> lexptr = lexptr_begin = srcfiles[nextfile].val;
> /* fall through to pointer adjustment and return, below
> */
> } else {
> @@ -1295,6 +1294,8 @@ again:
> /* set vars and return */
> lexptr = lexptr_begin = buf;
> }
> + source = NULL;
> + sourceline = 1;
> lexend = lexptr + l;
> nextfile++; /* for next entry to this routine */
> return lexptr;
>
> --sdtB3X0nJg68CQEu
> Content-Type: text/plain; charset=us-ascii
> Content-Disposition: attachment; filename="errloc2.patch"
>
> --- awkgram.y.errloc 2005-07-26 14:07:43.000000000 -0400
> +++ awkgram.y 2006-09-05 14:55:04.290127000 -0400
> @@ -1272,6 +1272,7 @@ again:
> if (srcfiles[nextfile].val[l-1] == '\n') {
> /* has terminating newline, can use it directly */
> sourceline = 1;
> + source = NULL;
> lexptr = lexptr_begin = srcfiles[nextfile].val;
> /* fall through to pointer adjustment and return, below
> */
> } else {
> @@ -1293,6 +1294,8 @@ again:
> buf[++l] = '\0';
>
> /* set vars and return */
> + sourceline = 0;
> + source = NULL;
> lexptr = lexptr_begin = buf;
> }
> lexend = lexptr + l;
>
> --sdtB3X0nJg68CQEu--
>