Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Bug in zsh versions 4.1.1 and 4.2.0



"Dieter Lambrecht" wrote:
> Hi,
>
> the following zsh-script running on Linux (Suse-Linux-Desktop)
>
> #! /home/bzq090/aps4_main/aps4/test/package/zsh/zsh-4.2.0/Src/zsh
> emulate -L zsh
>
> trap 'print $LINENO' DEBUG
>
> echo $LINENO
> echo $LINENO
>
>
>
> gives the following output:
>
> 1
> 6
> 1
> 7
> 1
>
>
> Contrary to the information in  "Z SHELL Manual" p. 85, LINENO is not
> updated correctly if used with the trap-builtin.

Yes, that's a real bug, the documentation is correct.  This must have
got broken when the wordcode execution stuff came in, since I remember
sweating blood over this some years ago.  It's been masked by the fact
that the buggy behaviour is encoded into the test suite; that's fixed
below as well.  I'm surprised nobody noticed it before since it makes
detailed debugging a good deal harder.  Maybe people now rely on PS4,
which gets the correct line number.

(I think the explanation for the test suite is that the first test,
TRAPDEBUG, is correct, also as per documentation.  The example got
copied for trap '...' debug, and since it worked without alteration, no
one noticed this was wrong.  The behaviour for TRAPDEBUG probably isn't
all that useful, actually; I think I decided somewhat arbitrarily
that it would respect the normal function convention.  There's no prior
art in that case.)

Index: Src/exec.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
retrieving revision 1.68
diff -u -r1.68 exec.c
--- Src/exec.c	26 Jul 2004 13:18:14 -0000	1.68
+++ Src/exec.c	29 Jul 2004 14:48:59 -0000
@@ -787,7 +787,8 @@
     if (errflag)
 	return (lastval = 1);

-    if (code)
+    /* In evaluated traps, don't modify the line number. */
+    if ((!intrap || trapisfunc) && code)
 	lineno = code - 1;

     code = wc_code(*state->pc++);
@@ -1258,7 +1259,8 @@
     if (breaks || retflag)
 	return;

-    if (WC_PIPE_LINENO(pcode))
+    /* In evaluated traps, don't modify the line number. */
+    if ((!intrap || trapisfunc) && WC_PIPE_LINENO(pcode))
 	lineno = WC_PIPE_LINENO(pcode) - 1;

     if (pline_level == 1) {
Index: Src/signals.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/signals.c,v
retrieving revision 1.29
diff -u -r1.29 signals.c
--- Src/signals.c	26 Jul 2004 13:18:14 -0000	1.29
+++ Src/signals.c	29 Jul 2004 14:49:01 -0000
@@ -943,6 +943,11 @@
 /**/
 int intrap;

+/* Is the current trap a function? */
+
+/**/
+int trapisfunc;
+
 /**/
 void
 dotrapargs(int sig, int *sigtr, void *sigfn)
@@ -1001,19 +1006,19 @@
 	zaddlinknode(args, num);

 	trapreturn = -1;	/* incremented by doshfunc */
+	trapisfunc = isfunc = 1;
+
 	sfcontext = SFC_SIGNAL;
 	doshfunc(name, sigfn, args, 0, 1);
 	sfcontext = osc;
 	freelinklist(args, (FreeFunc) NULL);
 	zsfree(name);

-	isfunc = 1;
     } else {
 	trapreturn = -2;	/* not incremented, used at current level */
+	trapisfunc = isfunc = 0;

 	execode(sigfn, 1, 0);
-
-	isfunc = 0;
     }
     runhookdef(AFTERTRAPHOOK, NULL);

Index: Test/A05execution.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/A05execution.ztst,v
retrieving revision 1.3
diff -u -r1.3 A05execution.ztst
--- Test/A05execution.ztst	22 Aug 2001 15:59:27 -0000	1.3
+++ Test/A05execution.ztst	29 Jul 2004 14:49:01 -0000
@@ -136,7 +136,7 @@
   rm fn
 0:trap DEBUG
 >Line 1
->Line 1
+>Line 2

   TRAPZERR() { print Command failed; }
   true

--
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************



Messages sorted by: Reverse Date, Date, Thread, Author