Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Bug: time doesn't work on builtins



On Wed, Sep 4, 2024 at 7:33 AM Jun. T <takimoto-j@xxxxxxxxxxxxxxxxx> wrote:
>
> The followings still give no time statistics:
>
> % time x=1
> % time x=$(date)

Hm, that's because we're taking the code path marked /* Empty command
*/ in execcmd_exec().

I think the only relevant case is around addvars() but can't be sure;
does anyone know a straightforward way to conditionally suppress the
child times in the case where the right-hand-side does not fork?

(Hand-fuzzed patch follows)

diff --git a/Src/exec.c b/Src/exec.c
index 00278ac50..c2f813078 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -3381,7 +3386,11 @@ execcmd_exec(Estate state, Execcmd_params eparams,
                    if (varspc) {
                        /* Make sure $? is still correct for assignment */
                        lastval = old_lastval;
+                       if (how & Z_TIMED)
+                           shelltime(&shti, &chti, &then, 0);
                        addvars(state, varspc, 0);
+                       if (how & Z_TIMED)
+                           shelltime(&shti, &chti, &then, 1);
                    }
                    if (errflag)
                        lastval = 1;




Messages sorted by: Reverse Date, Date, Thread, Author