From c2b5a21ae53bf800a6f99daeb6ab2d192d8b07a6 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 29 Oct 2002 12:58:00 +0000 Subject: 17873: When restoring SECONDS after a function call, included elapsed time. --- ChangeLog | 3 +++ Src/params.c | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/ChangeLog b/ChangeLog index 0e88e9a0d..73c41a14d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2002-10-29 Peter Stephenson + * 17873: Src/params.c: When restoring SECONDS after a function, + take account of time spent in the function. + * 17872: Src/builtin.c: Make sure `typeset SECONDS' uses a suitable type when creating a new local parameter. diff --git a/Src/params.c b/Src/params.c index 0d796871f..ce6102aa1 100644 --- a/Src/params.c +++ b/Src/params.c @@ -3484,7 +3484,24 @@ scanendscope(HashNode hn, int flags) Param tpm = pm->old; if (!strcmp(pm->nam, "SECONDS")) + { setsecondstype(pm, PM_TYPE(tpm->flags), PM_TYPE(pm->flags)); + /* + * We restore SECONDS by adding back in the elapsed + * time (from the point we reset shtimer) rather + * than restoring it completely, since SECONDS should + * run in the calling function, too. + */ + if (PM_TYPE(pm->flags) == PM_INTEGER) + { + pm->sets.ifn(pm, pm->gets.ifn(pm) + tpm->u.val); + } + else + { + pm->sets.ffn(pm, pm->gets.ffn(pm) + tpm->u.dval); + } + tpm->flags |= PM_NORESTORE; + } DPUTS(!tpm || PM_TYPE(pm->flags) != PM_TYPE(tpm->flags) || !(tpm->flags & PM_SPECIAL), "BUG: in restoring scope of special parameter"); -- cgit 1.4.1