From ca0607c4c219ea1c75673dd2a89831997d07754e Mon Sep 17 00:00:00 2001 From: Sebastian Gniazdowski Date: Sun, 28 May 2017 13:15:06 -0700 Subject: 41153: finish module setup only after all error conditions have been checked --- ChangeLog | 3 +++ Src/Modules/db_gdbm.c | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 15a02afa1..d97672317 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2017-05-28 Barton E. Schaefer + * Sebastian: 41153: Src/Modules/db_gdbm.c: finish module setup + only after all error conditions have been checked + * unposted: Doc/Zsh/mod_complist.yo: clarify ZLS_COLORS pattern matching contexts diff --git a/Src/Modules/db_gdbm.c b/Src/Modules/db_gdbm.c index 35254b68c..c4bb931a3 100644 --- a/Src/Modules/db_gdbm.c +++ b/Src/Modules/db_gdbm.c @@ -157,10 +157,7 @@ bin_ztie(char *nam, char **args, Options ops, UNUSED(int func)) gdbm_errno=0; dbf = gdbm_open(resource_name, 0, read_write, 0666, 0); - if(dbf) { - addmodulefd(gdbm_fdesc(dbf), FDT_MODULE); - append_tied_name(pmname); - } else { + if(dbf == NULL) { zwarnnam(nam, "error opening database file %s (%s)", resource_name, gdbm_strerror(gdbm_errno)); return 1; } @@ -172,6 +169,9 @@ bin_ztie(char *nam, char **args, Options ops, UNUSED(int func)) return 1; } + addmodulefd(gdbm_fdesc(dbf), FDT_MODULE); + append_tied_name(pmname); + tied_param->gsu.h = &gdbm_hash_gsu; /* Allocate parameter sub-gsu, fill dbf field. -- cgit 1.4.1 From 284b5aaeb08f90520ac7dc385e8921471678e7dd Mon Sep 17 00:00:00 2001 From: Sebastian Gniazdowski Date: Sun, 28 May 2017 13:17:26 -0700 Subject: 41151: propagate flags when creating new parameter --- ChangeLog | 3 +++ Src/Modules/db_gdbm.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index d97672317..eb1af3488 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,9 @@ * Sebastian: 41153: Src/Modules/db_gdbm.c: finish module setup only after all error conditions have been checked + * Sebastian: 41151: Src/Modules/db_gdbm.c: propagate flags when + creating new parameter + * unposted: Doc/Zsh/mod_complist.yo: clarify ZLS_COLORS pattern matching contexts diff --git a/Src/Modules/db_gdbm.c b/Src/Modules/db_gdbm.c index c4bb931a3..0ab0fe725 100644 --- a/Src/Modules/db_gdbm.c +++ b/Src/Modules/db_gdbm.c @@ -645,7 +645,7 @@ static Param createhash( char *name, int flags ) { Param pm; HashTable ht; - pm = createparam(name, PM_SPECIAL | PM_HASHED); + pm = createparam(name, flags | PM_SPECIAL | PM_HASHED); if (!pm) { return NULL; } -- cgit 1.4.1 From 151a4660e289c66d13b65d68ad2f10d93743d2d4 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 26 May 2017 11:06:59 +0100 Subject: 41164: Don't free a history entry if it's curline. This replaces 41113 / 94014ff65b with a simple local change for the immediate problem. It's not entirely clear if this reflects wider changes in the structure of the history code. --- ChangeLog | 5 +++++ Src/hashtable.c | 4 +++- Src/hist.c | 42 +++++++++++++++--------------------------- Src/zsh.h | 1 - 4 files changed, 23 insertions(+), 29 deletions(-) diff --git a/ChangeLog b/ChangeLog index eb1af3488..03592c04d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2017-05-26 Peter Stephenson + + * 41164: Src/hashtable.c, Src/hist.c, Src/zsh.h: Don't free a + history entry if it's the current line. This replaces 41113. + 2017-05-28 Barton E. Schaefer * Sebastian: 41153: Src/Modules/db_gdbm.c: finish module setup diff --git a/Src/hashtable.c b/Src/hashtable.c index c34744cd8..6ec2ed220 100644 --- a/Src/hashtable.c +++ b/Src/hashtable.c @@ -1445,10 +1445,12 @@ freehistdata(Histent he, int unlink) if (!he) return; + if (he == &curline) + return; + if (!(he->node.flags & (HIST_DUP | HIST_TMPSTORE))) removehashnode(histtab, he->node.nam); - DPUTS(he->node.nam == chline, "Attempt to free chline in history data"); zsfree(he->node.nam); if (he->nwords) zfree(he->words, he->nwords*2*sizeof(short)); diff --git a/Src/hist.c b/Src/hist.c index 4c1039b67..350688d2d 100644 --- a/Src/hist.c +++ b/Src/hist.c @@ -87,9 +87,6 @@ mod_export zlong curhist; /**/ struct histent curline; -/***/ -int curline_linked; - /* current line count of allocated history entries */ /**/ @@ -264,9 +261,6 @@ hist_context_save(struct hist_stack *hs, int toplevel) */ hs->cstack = cmdstack; hs->csp = cmdsp; - hs->curline_linked = curline_linked; - - unlinkcurline(); stophist = 0; chline = NULL; @@ -306,9 +300,6 @@ hist_context_restore(const struct hist_stack *hs, int toplevel) zfree(cmdstack, CMDSTACKSZ); cmdstack = hs->cstack; cmdsp = hs->csp; - unlinkcurline(); - if (hs->curline_linked) - linkcurline(); } /* @@ -999,7 +990,6 @@ nohwe(void) /* these functions handle adding/removing curline to/from the hist_ring */ -/**/ static void linkcurline(void) { @@ -1012,15 +1002,11 @@ linkcurline(void) hist_ring = &curline; } curline.histnum = ++curhist; - curline_linked = 1; } -/**/ static void unlinkcurline(void) { - if (!curline_linked) - return; curline.up->down = curline.down; curline.down->up = curline.up; if (hist_ring == &curline) { @@ -1030,7 +1016,6 @@ unlinkcurline(void) hist_ring = curline.up; } curhist--; - curline_linked = 0; } /* initialize the history mechanism */ @@ -1050,7 +1035,6 @@ hbegin(int dohist) stophist = (!interact || unset(SHINSTDIN)) ? 2 : 0; else stophist = 0; - DPUTS(chline != NULL, "chline set at start of history"); /* * pws: We used to test for "|| (inbufflags & INP_ALIAS)" * in this test, but at this point we don't have input @@ -1308,10 +1292,11 @@ putoldhistentryontop(short keep_going) Histent prepnexthistent(void) { - Histent he; - int relink_curline = curline_linked; + Histent he; + int curline_in_ring = hist_ring == &curline; - unlinkcurline(); + if (curline_in_ring) + unlinkcurline(); if (hist_ring && hist_ring->node.flags & HIST_TMPSTORE) { curhist--; freehistnode(&hist_ring->node); @@ -1335,7 +1320,7 @@ prepnexthistent(void) he = hist_ring; } he->histnum = ++curhist; - if (relink_curline) + if (curline_in_ring) linkcurline(); return he; } @@ -1410,7 +1395,8 @@ hend(Eprog prog) queue_signals(); if (histdone & HISTFLAG_SETTY) settyinfo(&shttyinfo); - unlinkcurline(); + if (!(histactive & HA_NOINC)) + unlinkcurline(); if (histactive & HA_NOINC) { zfree(chline, hlinesz); zfree(chwords, chwordlen*sizeof(short)); @@ -3638,7 +3624,7 @@ int pushhiststack(char *hf, zlong hs, zlong shs, int level) { struct histsave *h; - int relink_curline = curline_linked; + int curline_in_ring = (histactive & HA_ACTIVE) && hist_ring == &curline; if (histsave_stack_pos == histsave_stack_size) { histsave_stack_size += 5; @@ -3646,7 +3632,8 @@ pushhiststack(char *hf, zlong hs, zlong shs, int level) histsave_stack_size * sizeof (struct histsave)); } - unlinkcurline(); + if (curline_in_ring) + unlinkcurline(); h = &histsave_stack[histsave_stack_pos++]; @@ -3681,7 +3668,7 @@ pushhiststack(char *hf, zlong hs, zlong shs, int level) savehistsiz = shs; inithist(); /* sets histtab */ - if (relink_curline) + if (curline_in_ring) linkcurline(); return histsave_stack_pos; @@ -3693,12 +3680,13 @@ int pophiststack(void) { struct histsave *h; - int relink_curline = curline_linked; + int curline_in_ring = (histactive & HA_ACTIVE) && hist_ring == &curline; if (histsave_stack_pos == 0) return 0; - unlinkcurline(); + if (curline_in_ring) + unlinkcurline(); deletehashtable(histtab); zsfree(lasthist.text); @@ -3721,7 +3709,7 @@ pophiststack(void) histsiz = h->histsiz; savehistsiz = h->savehistsiz; - if (relink_curline) + if (curline_in_ring) linkcurline(); return histsave_stack_pos + 1; diff --git a/Src/zsh.h b/Src/zsh.h index 405b27490..22f73f806 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -2931,7 +2931,6 @@ struct hist_stack { void (*addtoline) _((int)); unsigned char *cstack; int csp; - int curline_linked; }; /* -- cgit 1.4.1