summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2004-07-29 15:09:51 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2004-07-29 15:09:51 +0000
commit640bbab78f56c2a51fb3ee1d0f83e3bf0418d8be (patch)
tree8d78905ddc9bd8e2674bedce6bcdfda10ba6c1da
parentefe2876d927b5d028031a6023b622be44c5d5b8a (diff)
downloadzsh-640bbab78f56c2a51fb3ee1d0f83e3bf0418d8be.tar.gz
zsh-640bbab78f56c2a51fb3ee1d0f83e3bf0418d8be.tar.xz
zsh-640bbab78f56c2a51fb3ee1d0f83e3bf0418d8be.zip
20221: $LINENO in trap '...' DEBUG was wrong.
-rw-r--r--Src/exec.c6
-rw-r--r--Src/signals.c11
-rw-r--r--Test/A05execution.ztst2
3 files changed, 13 insertions, 6 deletions
diff --git a/Src/exec.c b/Src/exec.c
index ee0752035..d1c3bb98e 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -787,7 +787,8 @@ execsimple(Estate state)
     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 @@ execpline2(Estate state, wordcode pcode,
     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) {
diff --git a/Src/signals.c b/Src/signals.c
index 064feb480..6c6c28159 100644
--- a/Src/signals.c
+++ b/Src/signals.c
@@ -943,6 +943,11 @@ endtrapscope(void)
 /**/
 int intrap;
 
+/* Is the current trap a function? */
+
+/**/
+int trapisfunc;
+
 /**/
 void
 dotrapargs(int sig, int *sigtr, void *sigfn)
@@ -1001,19 +1006,19 @@ dotrapargs(int sig, int *sigtr, void *sigfn)
 	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);
 
diff --git a/Test/A05execution.ztst b/Test/A05execution.ztst
index 09ade29d8..202a4bb7a 100644
--- a/Test/A05execution.ztst
+++ b/Test/A05execution.ztst
@@ -136,7 +136,7 @@
   rm fn
 0:trap DEBUG
 >Line 1
->Line 1
+>Line 2
 
   TRAPZERR() { print Command failed; }
   true