* [PATCH] POSIXBUILTINS: quieten 'unset -f nonexistentfunc'
@ 2017-10-11 18:44 Martijn Dekker
2017-11-02 19:04 ` Martijn Dekker
0 siblings, 1 reply; 3+ messages in thread
From: Martijn Dekker @ 2017-10-11 18:44 UTC (permalink / raw)
To: Zsh hackers list
[-- Attachment #1: Type: text/plain, Size: 599 bytes --]
Doing 'unset -f' on an unset function outputs an error message and
causes an unsuccessful exit status. All other shells quietly ignore it.
POSIX specifies for 'unset' that "Unsetting a variable or function that
was not previously set shall not be considered an error [...]".
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_29_03
If I have figured this out correctly, then the attached patch causes
'unset -f nonexistent_function' to be quiet and return status 0 if
POSIXBUILTINS is active, without changing the behaviour of 'unfunction'
and 'unhash -f'.
- Martijn
[-- Attachment #2: unset-f-quieten.patch --]
[-- Type: text/plain, Size: 1553 bytes --]
diff --git a/Src/builtin.c b/Src/builtin.c
index 84a2bee..0ff9e4f 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -125,7 +125,7 @@ static struct builtin builtins[] =
BUILTIN("unalias", 0, bin_unhash, 0, -1, BIN_UNALIAS, "ams", NULL),
BUILTIN("unfunction", 0, bin_unhash, 1, -1, BIN_UNFUNCTION, "m", "f"),
BUILTIN("unhash", 0, bin_unhash, 1, -1, BIN_UNHASH, "adfms", NULL),
- BUILTIN("unset", BINF_PSPECIAL, bin_unset, 1, -1, 0, "fmv", NULL),
+ BUILTIN("unset", BINF_PSPECIAL, bin_unset, 1, -1, BIN_UNSET, "fmv", NULL),
BUILTIN("unsetopt", 0, bin_setopt, 0, -1, BIN_UNSETOPT, NULL, NULL),
BUILTIN("wait", 0, bin_fg, 0, -1, BIN_WAIT, NULL, NULL),
BUILTIN("whence", 0, bin_whence, 0, -1, 0, "acmpvfsSwx:", NULL),
@@ -4158,6 +4158,10 @@ bin_unhash(char *name, char **argv, Options ops, int func)
for (; *argv; argv++) {
if ((hn = ht->removenode(ht, *argv))) {
ht->freenode(hn);
+ } else if (func == BIN_UNSET && isset(POSIXBUILTINS)) {
+ /* POSIX: unset: "Unsetting a variable or function that was *
+ * not previously set shall not be considered an error." */
+ returnval = 0;
} else {
zwarnnam(name, "no such hash table element: %s", *argv);
returnval = 1;
diff --git a/Src/hashtable.h b/Src/hashtable.h
index 3606e97..21398e1 100644
--- a/Src/hashtable.h
+++ b/Src/hashtable.h
@@ -62,6 +62,7 @@
#define BIN_UNHASH 28
#define BIN_UNALIAS 29
#define BIN_UNFUNCTION 30
+#define BIN_UNSET 31
/* These currently depend on being 0 and 1. */
#define BIN_SETOPT 0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] POSIXBUILTINS: quieten 'unset -f nonexistentfunc'
2017-10-11 18:44 [PATCH] POSIXBUILTINS: quieten 'unset -f nonexistentfunc' Martijn Dekker
@ 2017-11-02 19:04 ` Martijn Dekker
2017-11-02 20:04 ` Peter Stephenson
0 siblings, 1 reply; 3+ messages in thread
From: Martijn Dekker @ 2017-11-02 19:04 UTC (permalink / raw)
To: Zsh hackers list
Op 11-10-17 om 19:44 schreef Martijn Dekker:
> Doing 'unset -f' on an unset function outputs an error message and
> causes an unsuccessful exit status. All other shells quietly ignore it.
> POSIX specifies for 'unset' that "Unsetting a variable or function that
> was not previously set shall not be considered an error [...]".
> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_29_03
>
> If I have figured this out correctly, then the attached patch causes
> 'unset -f nonexistent_function' to be quiet and return status 0 if
> POSIXBUILTINS is active, without changing the behaviour of 'unfunction'
> and 'unhash -f'.
Was this overlooked, or rejected?
Thanks,
- M.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] POSIXBUILTINS: quieten 'unset -f nonexistentfunc'
2017-11-02 19:04 ` Martijn Dekker
@ 2017-11-02 20:04 ` Peter Stephenson
0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2017-11-02 20:04 UTC (permalink / raw)
To: Martijn Dekker; +Cc: Zsh hackers list
On Thu, 2 Nov 2017 19:04:40 +0000
Martijn Dekker <martijn@inlv.org> wrote:
> Op 11-10-17 om 19:44 schreef Martijn Dekker:
> > Doing 'unset -f' on an unset function outputs an error message and
> > causes an unsuccessful exit status. All other shells quietly ignore it.
> > POSIX specifies for 'unset' that "Unsetting a variable or function that
> > was not previously set shall not be considered an error [...]".
> > http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_29_03
> >
> > If I have figured this out correctly, then the attached patch causes
> > 'unset -f nonexistent_function' to be quiet and return status 0 if
> > POSIXBUILTINS is active, without changing the behaviour of 'unfunction'
> > and 'unhash -f'.
>
> Was this overlooked, or rejected?
Just got missed; I've committed it.
pws
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-11-02 20:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-11 18:44 [PATCH] POSIXBUILTINS: quieten 'unset -f nonexistentfunc' Martijn Dekker
2017-11-02 19:04 ` Martijn Dekker
2017-11-02 20:04 ` Peter Stephenson
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).