From 640bbab78f56c2a51fb3ee1d0f83e3bf0418d8be Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Thu, 29 Jul 2004 15:09:51 +0000 Subject: 20221: $LINENO in trap '...' DEBUG was wrong. --- Src/exec.c | 6 ++++-- Src/signals.c | 11 ++++++++--- Test/A05execution.ztst | 2 +- 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 -- cgit 1.4.1