about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2002-10-29 12:58:00 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2002-10-29 12:58:00 +0000
commitc2b5a21ae53bf800a6f99daeb6ab2d192d8b07a6 (patch)
treee6dfa13d2132fe78c51ad8afe5718a94c68b176f
parentff23ebe925752236ecf28318feee0a7f40e34e8e (diff)
downloadzsh-c2b5a21ae53bf800a6f99daeb6ab2d192d8b07a6.tar.gz
zsh-c2b5a21ae53bf800a6f99daeb6ab2d192d8b07a6.tar.xz
zsh-c2b5a21ae53bf800a6f99daeb6ab2d192d8b07a6.zip
17873: When restoring SECONDS after a function call, included elapsed time.
-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");