zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk (Zsh hackers list)
Subject: Re: PATCH: SECONDS can be floating point
Date: Tue, 29 Oct 2002 11:23:18 +0000	[thread overview]
Message-ID: <1390.1035890598@csr.com> (raw)
In-Reply-To: "Peter Stephenson"'s message of "Tue, 29 Oct 2002 10:40:25 GMT." <23260.1035888025@csr.com>

While I'm at it, this makes a local SECONDS work a bit better... it's
not logically tied to the other patch but it's now more useful to have
the problem fixed, since you might want to use `typeset -F seconds' in a
function to get more precision locally.

The problem was that if you made SECONDS local, then on return to the
parent function, the time spent in the lower function didn't appear in
the value of SECONDS, hence if you were using it for overall timing ---
which is a natural thing to do --- you could miscount completely,
depending arbitrarily on the behaviour of nested functions.  This fixes
the problem by restoring SECONDS to include the elapsed time spent in
the function.  Of course, the accuracy won't be perfect, but it wouldn't
be anyway.

I think there may still be a problem if you do `typeset SECONDS=value'
inside a function that value may remain added in on return but I haven't
looked at this in detail.

Index: Src/params.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/params.c,v
retrieving revision 1.67
diff -u -r1.67 params.c
--- Src/params.c	29 Oct 2002 10:31:16 -0000	1.67
+++ Src/params.c	29 Oct 2002 11:10:16 -0000
@@ -3484,7 +3484,24 @@
 	    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");

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


  reply	other threads:[~2002-10-29 11:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-28 18:55 Peter Stephenson
2002-10-29 10:40 ` Peter Stephenson
2002-10-29 11:23   ` Peter Stephenson [this message]
2002-10-29 17:52     ` Wayne Davison
2002-10-29 18:08     ` Wayne Davison
2002-10-29 18:13       ` Peter Stephenson
2002-10-30 21:17 ` PATCH: my "SECONDS can be floating point" tweaks Wayne Davison
2002-10-31  5:09   ` Bart Schaefer
2002-10-31 18:53     ` Wayne Davison
2002-10-31 10:34   ` Peter Stephenson
2002-10-31 18:53     ` Wayne Davison

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1390.1035890598@csr.com \
    --to=pws@csr.com \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).