Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] issues with $SECONDS setting and expansio
- X-seq: zsh-workers 38020
- From: Stephane Chazelas <stephane.chazelas@xxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: [PATCH] issues with $SECONDS setting and expansio
- Date: Wed, 24 Feb 2016 17:09:04 +0000
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:subject:message-id:mail-followup-to:mime-version :content-disposition:user-agent; bh=k3zlkh1Q2g/9t7oPWLSi8R2Fjwr+9pZyD/l1/6RkY/o=; b=Pqal/2oKZ6LCmwvuJA9/uPmGctc1obn/YqGbk5zbYD4Jm4uv11rK/MqKQqf2p1FLbE BqRExsldX3KllWcMYFNmA68ykZ+6K1bptDsgB0YhP4/EIzT5/Lebcex9P0jv8h3+iT0D CTo6hNM9w2+9NmQ3b4dVpdiBQ6rTArtLClsZ1AxTHXt9ZkWB3zSZ3YEOW5gvaRHNsokW GL91DBBS8+JEoRA9AFx2Io6sUFVO5BJPk2SNsj4nD0crQFeNFhdbZR+4dH9GikSFqO4d bVDfvTNCLp5MRvY+B40gNryvAUvqcZwq+uqj8X9aZhEfiotIeqjAapqXDuOLp59bq1PX 1Hjg==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mail-followup-to: Zsh hackers list <zsh-workers@xxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
In, intsecondsgetfn,
(zlong)(now.tv_usec - shtimer.tv_usec) / (zlong)1000000
was always 0 because that's the difference between 2 numbers
that are both under 1000000 divided by 1000000.
Also, by setting shtimer.tv_usec to 0 instead of now.tv_usec,
we're arbitrarily adding up to 1 second to $SECONDS.
Before this patch:
$ time zsh -c 'while ((SECONDS < 1)); do :; done'
zsh -c 'while ((SECONDS < 1)); do :; done' 0.20s user 0.07s system 99% cpu 0.269 total
(SECONDS gets incremented in between 0 and 1 seconds after
startup, above 0.269 seconds. bash and mksh have similar issues
which I've also reported there).
$ zsh -c 'SECONDS=0; typeset -F SECONDS; echo $SECONDS'
0.8081650000
After the patch:
$ time ./zsh -c 'while ((SECONDS < 1)); do :; done'
./zsh -c 'while ((SECONDS < 1)); do :; done' 0.87s user 0.13s system 99% cpu 1.003 total
SECONDS reaches 1 after 1 second, consistently.
$ ./zsh -c 'SECONDS=0; typeset -F SECONDS; echo $SECONDS'
0.0000740000
diff --git a/Src/params.c b/Src/params.c
index 8bd8a8e..7c5f79f 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -3804,8 +3804,8 @@ intsecondsgetfn(UNUSED(Param pm))
gettimeofday(&now, &dummy_tz);
- return (zlong)(now.tv_sec - shtimer.tv_sec) +
- (zlong)(now.tv_usec - shtimer.tv_usec) / (zlong)1000000;
+ return (zlong)(now.tv_sec - shtimer.tv_sec -
+ (now.tv_usec < shtimer.tv_usec ? 1 : 0));
}
/* Function to set value of special parameter `SECONDS' */
@@ -3823,7 +3823,7 @@ intsecondssetfn(UNUSED(Param pm), zlong x)
shtimer.tv_sec = diff;
if ((zlong)shtimer.tv_sec != diff)
zwarn("SECONDS truncated on assignment");
- shtimer.tv_usec = 0;
+ shtimer.tv_usec = now.tv_usec;
}
/**/
Messages sorted by:
Reverse Date,
Date,
Thread,
Author