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

Re: [PATCH] enable elaped time with incappendhistory



On Sat, 05 Oct 2013 22:04:50 +0100
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx> wrote:
> On Sat, 5 Oct 2013 20:50:10 +0800
> Han Pingtian <hanpt@xxxxxxxxxxxxxxxxxx> wrote:
> > Could you please reveiw this patch? Thanks in advance.
> > 
> > If incappendhistory being set, the command line will be written before
> > it has finished. So elaped time doesn't work. Looks like this patch
> > lets it working again. And sharehistory will still cause the command
> > line written before it has finished.
> 
> It's probably not going to help much simply staring at it.  I use
> INCAPPENDHISTORY, so I've committed this and I'll see how it works.

I'm doing that and something appears to be broken...

It's got into a state where it's calling savehistfile() and
readhistfile() recursively from a readhistfile() and
is consequently being very slow.  This is actually from an "fc -p
<filename>" in a ZLE script.  I don't think INCAPPENDHISTORY is relevant
in this case, so maybe it just needs more tests for when to apply the
modified code.  Note that HISTLEXWORDS is set; I think that's important
because that's how we get from histsplitwords() down into bufferwords().

Adding the test for "strin" in hbegin() in the patch below seems to
remove the unwanted behaviour.  Comparing with the code around, I think
we also don't want to do this in the case HA_NOINC is present in
histactive.  I'll commit this immediately to remove the pathology, but
there may be more tweaks.

For what it's worth, here's the backtrace, though the stuff towards the
end isn't likely to be interesting.  (I've slightly edited the make line
that's being searched for but that shouldn't be relevant.)  I'll attach
the script, which is the history-beginning-local I think I posted some
weeks ago, though probably the only interesting bit is the fc.

#0  0x08091bba in zfree (p=0x99a1898, sz=0) at mem.c:1323
#1  0x080927a9 in free (p=0x99a1898) at mem.c:1487
#2  0x08088097 in lexrestore () at lex.c:342
#3  0x0807cb70 in bufferwords (list=0xb338a010, buf=0x99d20bf "make -s", index=0x0, flags=4) at hist.c:3088
#4  0x0807d06b in histsplitwords (lineptr=0x99d20bf "make -s", wordsp=0xbfa9585c, nwordsp=0xbfa95854, nwordposp=0xbfa95858, uselex=1) at hist.c:3136
#5  0x0807d744 in readhistfile (fn=0x99b8b00 ".zsh_local_history", err=0, readflags=0) at hist.c:2397
#6  0x0807c4cc in savehistfile (fn=0x99b8b00 ".zsh_local_history", err=0, writeflags=32771) at hist.c:2635
#7  0x0807c749 in hbegin (dohist=0) at hist.c:932
#8  0x0807c8b8 in strinbeg (dohist=0) at hist.c:808
#9  0x0807c9ea in bufferwords (list=0xb3397010, buf=0x99c8f8f "unit make", index=0x0, flags=4) at hist.c:2951
#10 0x0807d06b in histsplitwords (lineptr=0x99c8f8f "unit make", wordsp=0xbfa95b3c, nwordsp=0xbfa95b34, nwordposp=0xbfa95b38, uselex=1) at hist.c:3136
#11 0x0807d744 in readhistfile (fn=0xb42d4008 ".zsh_local_history", err=1, readflags=32768) at hist.c:2397
#12 0x0805baf9 in bin_fc (nam=0xb42d3ff0 "fc", argv=<value optimized out>, ops=0xbfa95e24, func=16) at builtin.c:1385
#13 0x0805f2d1 in execbuiltin (args=0xb42d3fc0, bn=0x80d70ec) at builtin.c:450
#14 0x0806c361 in execcmd (state=0xbfa978f4, input=0, output=0, how=2, last1=2) at exec.c:3247
#15 0x0806c88f in execpline2 (state=0xbfa978f4, pcode=<value optimized out>, how=2, input=0, output=0, last1=0) at exec.c:1683
#16 0x0806cc25 in execpline (state=0xbfa978f4, slcode=<value optimized out>, how=2, last1=0) at exec.c:1470
#17 0x0806d994 in execlist (state=0xbfa978f4, dont_change_job=1, exiting=0) at exec.c:1253
#18 0x0808c8fc in execif (state=0xbfa978f4, do_exec=0) at loop.c:515
#19 0x0806b8ea in execcmd (state=0xbfa978f4, input=0, output=0, how=18, last1=2) at exec.c:3206
#20 0x0806c88f in execpline2 (state=0xbfa978f4, pcode=<value optimized out>, how=18, input=0, output=0, last1=0) at exec.c:1683
#21 0x0806cc25 in execpline (state=0xbfa978f4, slcode=<value optimized out>, how=18, last1=0) at exec.c:1470
#22 0x0806d994 in execlist (state=0xbfa978f4, dont_change_job=1, exiting=0) at exec.c:1253
#23 0x0808c8fc in execif (state=0xbfa978f4, do_exec=0) at loop.c:515
#24 0x0806b8ea in execcmd (state=0xbfa978f4, input=0, output=0, how=18, last1=2) at exec.c:3206
#25 0x0806c88f in execpline2 (state=0xbfa978f4, pcode=<value optimized out>, how=18, input=0, output=0, last1=0) at exec.c:1683
#26 0x0806cc25 in execpline (state=0xbfa978f4, slcode=<value optimized out>, how=18, last1=0) at exec.c:1470
#27 0x0806d994 in execlist (state=0xbfa978f4, dont_change_job=1, exiting=0) at exec.c:1253
#28 0x0808ba9b in execfor (state=0xbfa978f4, do_exec=0) at loop.c:159
#29 0x0806b8ea in execcmd (state=0xbfa978f4, input=0, output=0, how=2, last1=2) at exec.c:3206
#30 0x0806c88f in execpline2 (state=0xbfa978f4, pcode=<value optimized out>, how=2, input=0, output=0, last1=0) at exec.c:1683
#31 0x0806cc25 in execpline (state=0xbfa978f4, slcode=<value optimized out>, how=2, last1=0) at exec.c:1470
#32 0x0806d994 in execlist (state=0xbfa978f4, dont_change_job=1, exiting=0) at exec.c:1253
#33 0x0808cd6a in exectry (state=0xbfa978f4, do_exec=0) at loop.c:648
#34 0x0806b8ea in execcmd (state=0xbfa978f4, input=0, output=0, how=2, last1=2) at exec.c:3206
#35 0x0806c88f in execpline2 (state=0xbfa978f4, pcode=<value optimized out>, how=2, input=0, output=0, last1=0) at exec.c:1683
#36 0x0806cc25 in execpline (state=0xbfa978f4, slcode=<value optimized out>, how=2, last1=0) at exec.c:1470
#37 0x0806d994 in execlist (state=0xbfa978f4, dont_change_job=1, exiting=0) at exec.c:1253
#38 0x0806df36 in execode (p=0x99b5b08, dont_change_job=1, exiting=0, context=0x80cadd5 "shfunc") at exec.c:1065
#39 0x08067ffd in runshfunc (prog=0x99b5b08, wrap=0x0, name=0xb42d33f0 "history-beginning-local") at exec.c:4834
#40 0x08068622 in doshfunc (shfunc=0x98dc318, doshargs=0x0, noreturnval=1) at exec.c:4725
#41 0x0052c808 in execzlefunc (func=0x9908420, args=<value optimized out>, set_bindk=0) at zle_main.c:1380
#42 0x0052cd0a in zlecore () at zle_main.c:1063
#43 0x0052d895 in zleread (lp=0x80eb540, rp=0x0, flags=7, context=0, init=0x549615 "zle-line-init", finish=0x549605 "zle-line-finish") at zle_main.c:1247
#44 0x0052eb83 in zle_main_entry (cmd=1, ap=0xbfa97f54 "\001") at zle_main.c:1908
#45 0x08081232 in zleentry (cmd=1) at init.c:1464
#46 0x08081e5a in inputline () at input.c:283
#47 ingetc () at input.c:219
#48 0x0807b1ec in ihgetc () at hist.c:282
#49 0x0808a6ee in gettok () at lex.c:714
#50 zshlex () at lex.c:395
#51 0x080a6f89 in parse_event () at parse.c:451
#52 0x0807e6b9 in loop (toplevel=1, justonce=0) at init.c:132
#53 0x0808179e in zsh_main (argc=1, argv=0xbfa981e4) at init.c:1619
#54 0x080530bb in main (argc=1, argv=0xbfa981e4) at ./main.c:93

pws

diff --git a/Src/hist.c b/Src/hist.c
index 1961d83..c58ce8b 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -928,7 +928,7 @@ hbegin(int dohist)
 	histactive = HA_ACTIVE | HA_NOINC;
 
     hf = getsparam("HISTFILE");
-    if (isset(INCAPPENDHISTORY))
+    if (isset(INCAPPENDHISTORY) && !(histactive & HA_NOINC) && !strin)
 	savehistfile(hf, 0, HFILE_USE_OPTIONS | HFILE_FAST);
 }
 

Attachment: history-beginning-local
Description: Binary data



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