From 962624e8c343e3968fbb55160b8a14b460400bc0 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Sun, 19 Jun 2011 16:26:10 +0000 Subject: 29491: remove some variables set but not used --- Src/utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Src/utils.c') diff --git a/Src/utils.c b/Src/utils.c index 066710e1e..d50311637 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -4689,7 +4689,7 @@ addunprintable(char *v, const char *u, const char *uend) mod_export char * quotestring(const char *s, char **e, int instring) { - const char *u, *tt; + const char *u; char *v; int alloclen; char *buf; @@ -4740,7 +4740,7 @@ quotestring(const char *s, char **e, int instring) break; } - tt = quotestart = v = buf = zshcalloc(alloclen); + quotestart = v = buf = zshcalloc(alloclen); DPUTS(instring < QT_BACKSLASH || instring == QT_BACKTICK || instring > QT_SINGLE_OPTIONAL, -- cgit v1.2.3 From 45913f43e54beacca4feb614bbe80089cec6f490 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 25 Jul 2011 10:20:09 +0000 Subject: 29561: Allow closing of fd's not recorded by the shell --- ChangeLog | 7 ++++++- Src/exec.c | 18 ++++++++++++------ Src/utils.c | 28 +++++++++++++--------------- 3 files changed, 31 insertions(+), 22 deletions(-) (limited to 'Src/utils.c') diff --git a/ChangeLog b/ChangeLog index 3f8e821c9..b5a2baddf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-07-25 Peter Stephenson + + * 29561: Src/exec.c, Src/utils.c, Test/A04redirect.ztst: Allow + closing of file descriptors not recorded internally by the shell. + 2011-07-22 Mikael Magnusson * 29596: Completion/compinit: Fix syntax to work with KSH_ARRAYS @@ -15154,5 +15159,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5406 $ +* $Revision: 1.5407 $ ***************************************************** diff --git a/Src/exec.c b/Src/exec.c index f5b59a36e..6320f6a67 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -2975,17 +2975,16 @@ execcmd(Estate state, int input, int output, int how, int last1) fn->fd1 = (int)getintvalue(v); if (errflag) bad = 1; - else if (fn->fd1 > max_zsh_fd) - bad = 3; - else if (fn->fd1 >= 10 && + else if (fn->fd1 <= max_zsh_fd) { + if (fn->fd1 >= 10 && fdtable[fn->fd1] == FDT_INTERNAL) - bad = 4; + bad = 3; + } } if (bad) { const char *bad_msg[] = { "parameter %s does not contain a file descriptor", "can't close file descriptor from readonly parameter %s", - "file descriptor %d out of range, not closed", "file descriptor %d used by shell, not closed" }; if (bad > 2) @@ -2995,11 +2994,18 @@ execcmd(Estate state, int input, int output, int how, int last1) execerr(); } } + /* + * Note we may attempt to close an fd beyond max_zsh_fd: + * OK as long as we never look in fdtable for it. + */ if (!forked && fn->fd1 < 10 && save[fn->fd1] == -2) save[fn->fd1] = movefd(fn->fd1); if (fn->fd1 < 10) closemn(mfds, fn->fd1); - zclose(fn->fd1); + if (zclose(fn->fd1) < 0) { + zwarn("failed to close file descriptor %d: %e", + fn->fd1, errno); + } break; case REDIR_MERGEIN: case REDIR_MERGEOUT: diff --git a/Src/utils.c b/Src/utils.c index d50311637..f460c0fb3 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -1802,22 +1802,20 @@ zclose(int fd) { if (fd >= 0) { /* - * We sometimes zclose() an fd twice where the second - * time is a catch-all in case there was a failure using - * the fd. This is harmless but we need to trap it - * for the error check here. + * Careful: we allow closing of arbitrary fd's, beyond + * max_zsh_fd. In that case we don't try anything clever. */ - DPUTS2(fd > max_zsh_fd && fdtable[fd] != FDT_UNUSED, - "BUG: fd is %d, max_zsh_fd is %d", fd, max_zsh_fd); - if (fdtable[fd] == FDT_FLOCK) - fdtable_flocks--; - fdtable[fd] = FDT_UNUSED; - while (max_zsh_fd > 0 && fdtable[max_zsh_fd] == FDT_UNUSED) - max_zsh_fd--; - if (fd == coprocin) - coprocin = -1; - if (fd == coprocout) - coprocout = -1; + if (fd <= max_zsh_fd) { + if (fdtable[fd] == FDT_FLOCK) + fdtable_flocks--; + fdtable[fd] = FDT_UNUSED; + while (max_zsh_fd > 0 && fdtable[max_zsh_fd] == FDT_UNUSED) + max_zsh_fd--; + if (fd == coprocin) + coprocin = -1; + if (fd == coprocout) + coprocout = -1; + } return close(fd); } return -1; -- cgit v1.2.3 From a3ae9f5d126ee235301322d3ee370e6b2235090c Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Thu, 4 Aug 2011 08:30:50 +0000 Subject: 29643: set incompfunc to zero when executing hook or trap function --- Src/Zle/zle_main.c | 5 ----- Src/signals.c | 4 +++- Src/utils.c | 12 +++++++++++- 3 files changed, 14 insertions(+), 7 deletions(-) (limited to 'Src/utils.c') diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c index 771ff2cf0..3cdc3b2ed 100644 --- a/Src/Zle/zle_main.c +++ b/Src/Zle/zle_main.c @@ -53,11 +53,6 @@ mod_export int zlecs, zlell; /**/ mod_export int incompctlfunc; -/* != 0 if we are in a new style completion function */ - -/**/ -mod_export int incompfunc; - /* != 0 if completion module is loaded */ /**/ diff --git a/Src/signals.c b/Src/signals.c index a848acdbe..81949843f 100644 --- a/Src/signals.c +++ b/Src/signals.c @@ -1184,7 +1184,7 @@ dotrapargs(int sig, int *sigtr, void *sigfn) traplocallevel = locallevel; runhookdef(BEFORETRAPHOOK, NULL); if (*sigtr & ZSIG_FUNC) { - int osc = sfcontext; + int osc = sfcontext, old_incompfunc = incompfunc; HashNode hn = gettrapnode(sig, 0); args = znewlinklist(); @@ -1210,8 +1210,10 @@ dotrapargs(int sig, int *sigtr, void *sigfn) trapisfunc = isfunc = 1; sfcontext = SFC_SIGNAL; + incompfunc = 0; doshfunc((Shfunc)sigfn, args, 1); sfcontext = osc; + incompfunc= old_incompfunc; freelinklist(args, (FreeFunc) NULL); zsfree(name); } else { diff --git a/Src/utils.c b/Src/utils.c index f460c0fb3..439b43aa9 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -40,6 +40,11 @@ mod_export char *scriptname; /* is sometimes a function name */ /**/ mod_export char *scriptfilename; +/* != 0 if we are in a new style completion function */ + +/**/ +mod_export int incompfunc; + #ifdef MULTIBYTE_SUPPORT struct widechar_array { wchar_t *chars; @@ -1232,8 +1237,10 @@ callhookfunc(char *name, LinkList lnklst, int arrayp, int *retval) * to a list of jobs generated in a hook. */ int osc = sfcontext, osm = stopmsg, stat = 1, ret = 0; + int old_incompfunc = incompfunc; sfcontext = SFC_HOOK; + incompfunc = 0; if ((shfunc = getshfunc(name))) { ret = doshfunc(shfunc, lnklst, 1); @@ -1262,6 +1269,7 @@ callhookfunc(char *name, LinkList lnklst, int arrayp, int *retval) sfcontext = osc; stopmsg = osm; + incompfunc = old_incompfunc; if (retval) *retval = ret; @@ -3216,7 +3224,7 @@ getshfunc(char *nam) char ** subst_string_by_func(Shfunc func, char *arg1, char *orig) { - int osc = sfcontext, osm = stopmsg; + int osc = sfcontext, osm = stopmsg, old_incompfunc = incompfunc; LinkList l = newlinklist(); char **ret; @@ -3225,6 +3233,7 @@ subst_string_by_func(Shfunc func, char *arg1, char *orig) addlinknode(l, arg1); addlinknode(l, orig); sfcontext = SFC_SUBST; + incompfunc = 0; if (doshfunc(func, l, 1)) ret = NULL; @@ -3233,6 +3242,7 @@ subst_string_by_func(Shfunc func, char *arg1, char *orig) sfcontext = osc; stopmsg = osm; + incompfunc = old_incompfunc; return ret; } -- cgit v1.2.3 From 815e52cdbf0a62bf795d5af8e7089aaca5709806 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 17 Aug 2011 19:00:08 +0000 Subject: users/16253, users/16255: a nulstring should be split like an empty string --- ChangeLog | 7 +++++-- Src/utils.c | 4 ++++ Test/D04parameter.ztst | 5 +++++ 3 files changed, 14 insertions(+), 2 deletions(-) (limited to 'Src/utils.c') diff --git a/ChangeLog b/ChangeLog index bd9d9229b..76eb0d1dc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,9 @@ 2011-08-17 Peter Stephenson - * Anthony R Fletcher: users/16260: + * users/16253, users/16255: Src/utils.c, Test/D04parameter.ztst: + A nulstring should be split like an empty string. + + * Anthony R Fletcher: users/16260: Completion/Unix/Command/_systemctl: new completion. 2011-08-17 Nikolai Weibull @@ -15294,5 +15297,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5437 $ +* $Revision: 1.5438 $ ***************************************************** diff --git a/Src/utils.c b/Src/utils.c index 439b43aa9..c8d021c66 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -3176,6 +3176,10 @@ sepsplit(char *s, char *sep, int allownull, int heap) int n, sl; char *t, *tt, **r, **p; + /* Null string? Treat as empty string. */ + if (s[0] == Nularg && !s[1]) + s++; + if (!sep) return spacesplit(s, allownull, heap, 0); diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst index 8f95420dd..71c79687f 100644 --- a/Test/D04parameter.ztst +++ b/Test/D04parameter.ztst @@ -1453,3 +1453,8 @@ print ${foo:5:-6} 1:Regression test for total length < 0 in array ?(eval):2: substring expression: 3 < 5 + + foo=(${(0)"$(print -n)"}) + print ${#foo} +0:Nularg removed from split empty string +>0 -- cgit v1.2.3 From 188abdd708a9a03ff44b5361d028a9953701250e Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Sun, 2 Oct 2011 01:10:11 +0000 Subject: 29799: swap order of RESET_PROMPT / REFRESH in adjustwinsize(). --- ChangeLog | 6 +++++- Src/utils.c | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'Src/utils.c') diff --git a/ChangeLog b/ChangeLog index 2b7f1e15c..1b67dccfa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2011-09-25 Barton E. Schaefer + * 29799: Src/utils.c: swap order of RESET_PROMPT / REFRESH in + adjustwinsize() so that the cursor is moved to the start of a + multi-line prompt before the prompt is actually displayed. + * 29769: Src/signals.c: handle thisjob == -1 (no foreground job) when checking for whether a background job is allowed to suspend. @@ -15447,5 +15451,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5473 $ +* $Revision: 1.5474 $ ***************************************************** diff --git a/Src/utils.c b/Src/utils.c index c8d021c66..41bf0b149 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -1691,8 +1691,8 @@ adjustwinsize(int from) winchanged = #endif /* TIOCGWINSZ */ resetneeded = 1; - zleentry(ZLE_CMD_REFRESH); zleentry(ZLE_CMD_RESET_PROMPT); + zleentry(ZLE_CMD_REFRESH); } } -- cgit v1.2.3 From 7c5173ba0fd41027ec32d4f7cf29deaaadbec1e4 Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Tue, 15 Nov 2011 15:08:56 +0000 Subject: users/16581: skip correction shortcut based on command table search when the word is not in command position; on rejected command correction, reset incremental path hashing. --- ChangeLog | 11 +++++++++-- Src/utils.c | 22 +++++++++++++--------- 2 files changed, 22 insertions(+), 11 deletions(-) (limited to 'Src/utils.c') diff --git a/ChangeLog b/ChangeLog index 0182247df..71376d100 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-11-15 Barton E. Schaefer + + * users/16581: Src/utils.c: it seems wrong to shortcut correction + of words not in command position by comparing them to the command + tables, so don't; if a command correction is rejected, reset the + incremental path hashing so the new command can be "learned". + 2011-11-14 Peter Stephenson * gi1242: users/16578: Completion/Unix/Command/_lp: lpadmin, @@ -117,7 +124,7 @@ * 29815: Doc/Makefile.in: include mod_langinfo in documentation. -2011-09-25 Barton E. Schaefer +2011-09-25 Barton E. Schaefer * 29799: Src/utils.c: swap order of RESET_PROMPT / REFRESH in adjustwinsize() so that the cursor is moved to the start of a @@ -15570,5 +15577,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5498 $ +* $Revision: 1.5499 $ ***************************************************** diff --git a/Src/utils.c b/Src/utils.c index 41bf0b149..6c2ea98d5 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -2498,16 +2498,18 @@ spckword(char **s, int hist, int cmd, int ask) return; if (!(*s)[0] || !(*s)[1]) return; - if (shfunctab->getnode(shfunctab, *s) || - builtintab->getnode(builtintab, *s) || - cmdnamtab->getnode(cmdnamtab, *s) || - aliastab->getnode(aliastab, *s) || - reswdtab->getnode(reswdtab, *s)) - return; - else if (isset(HASHLISTALL)) { - cmdnamtab->filltable(cmdnamtab); - if (cmdnamtab->getnode(cmdnamtab, *s)) + if (cmd) { + if (shfunctab->getnode(shfunctab, *s) || + builtintab->getnode(builtintab, *s) || + cmdnamtab->getnode(cmdnamtab, *s) || + aliastab->getnode(aliastab, *s) || + reswdtab->getnode(reswdtab, *s)) return; + else if (isset(HASHLISTALL)) { + cmdnamtab->filltable(cmdnamtab); + if (cmdnamtab->getnode(cmdnamtab, *s)) + return; + } } t = *s; if (*t == Tilde || *t == Equals || *t == String) @@ -2621,6 +2623,8 @@ spckword(char **s, int hist, int cmd, int ask) fflush(shout); zbeep(); x = getquery("nyae \t", 0); + if (cmd && x == 'n') + pathchecked = path; } else x = 'n'; } else -- cgit v1.2.3