zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk
Cc: "Dieter Lambrecht" <dieter.lambrecht@db.com>
Subject: Re: Bug in zsh versions 4.1.1 and 4.2.0
Date: Thu, 29 Jul 2004 15:56:59 +0100	[thread overview]
Message-ID: <200407291457.i6TEv0Yl023430@news01.csr.com> (raw)
In-Reply-To: ""Dieter Lambrecht""'s message of "Thu, 29 Jul 2004 16:14:51 +0200." <OF2FAC436C.8E25764D-ONC1256EE0.004CD3F4-C1256EE0.004E48BB@db.com>

"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@csr.com>                  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
**********************************************************************


      reply	other threads:[~2004-07-29 14:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-29 14:14 Dieter Lambrecht
2004-07-29 14:56 ` Peter Stephenson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200407291457.i6TEv0Yl023430@news01.csr.com \
    --to=pws@csr.com \
    --cc=dieter.lambrecht@db.com \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).