about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--Src/params.c17
2 files changed, 20 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 0e88e9a0d..73c41a14d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2002-10-29  Peter Stephenson  <pws@csr.com>
 
+	* 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");