From: Jilles Tjoelker <jilles@stack.nl>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: dash@vger.kernel.org, pape@smarden.org
Subject: Re: [PATCH 1/4] [VAR] Add localvars nesting
Date: Wed, 26 May 2010 23:55:33 +0200 [thread overview]
Message-ID: <20100526215533.GA5679@stack.nl> (raw)
In-Reply-To: <E1OHELf-0006sP-9S@gondolin.me.apana.org.au>
On Wed, May 26, 2010 at 09:00:31PM +1000, Herbert Xu wrote:
> [VAR] Add localvars nesting
> This patch adds localvars nesting infrastructure so we can reuse
> the localvars mechanism for command evaluation.
localvars could already nest, it's just that this change makes the
nesting explicit instead of on the C stack.
Further comments inline.
> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
> ---
> ChangeLog | 4 ++++
> src/eval.c | 7 ++-----
> src/var.c | 50 ++++++++++++++++++++++++++++++++++++++++++++------
> src/var.h | 1 +
> 4 files changed, 51 insertions(+), 11 deletions(-)
> diff --git a/ChangeLog b/ChangeLog
> index ee78154..7285a23 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,7 @@
> +2010-05-24 Herbert Xu <herbert@gondor.apana.org.au>
> +
> + * Add localvars nesting.
> +
> 2010-05-03 Gerrit Pape <pape@smarden.org>
>
> * Fix command -- crash.
> diff --git a/src/eval.c b/src/eval.c
> index 62d9d5d..8d2767c 100644
> --- a/src/eval.c
> +++ b/src/eval.c
> @@ -928,20 +928,17 @@ STATIC int
> evalfun(struct funcnode *func, int argc, char **argv, int flags)
> {
> volatile struct shparam saveparam;
> - struct localvar *volatile savelocalvars;
> struct jmploc *volatile savehandler;
> struct jmploc jmploc;
> int e;
>
> saveparam = shellparam;
> - savelocalvars = localvars;
> if ((e = setjmp(jmploc.loc))) {
> goto funcdone;
> }
> INTOFF;
> savehandler = handler;
> handler = &jmploc;
> - localvars = NULL;
> shellparam.malloc = 0;
> func->count++;
> funcnest++;
> @@ -950,13 +947,13 @@ evalfun(struct funcnode *func, int argc, char **argv, int flags)
> shellparam.p = argv + 1;
> shellparam.optind = 1;
> shellparam.optoff = -1;
> + pushlocalvars();
> evaltree(&func->n, flags & EV_TESTED);
> + poplocalvars();
> funcdone:
> INTOFF;
> funcnest--;
> freefunc(func);
> - poplocalvars();
> - localvars = savelocalvars;
> freeparam(&shellparam);
> shellparam = saveparam;
> handler = savehandler;
This change does not do poplocalvars() if the function was exited with
an error. While this is normally not a problem because the shell exits
or executes the RESET actions, 'command eval', 'command .' and 'fc' will
"catch" any errors and continue normally.
Example (with the below "disallow local outside a function" change):
dash -c 'f() { unset xyz; ${xyz?}; }; command eval f; local i'
> diff --git a/src/var.c b/src/var.c
> index 2737fb1..de1a5f5 100644
> [...]
> @@ -446,6 +456,9 @@ localcmd(int argc, char **argv)
> {
> char *name;
>
> + if (!localvar_stack)
> + sh_error("not in a function");
> +
> argv = argptr;
> while ((name = *argv++) != NULL) {
> mklocal(name);
This change (failing local outside functions), while a good idea, should
be mentioned in the commit message/changelog, as it might break certain
scripts.
(Note that in mksh local is an alias for typeset, which will work
outside functions.)
--
Jilles Tjoelker
next prev parent reply other threads:[~2010-05-26 21:55 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <201004052231.28372.j6t@kdbg.org>
[not found] ` <201004052257.58768.j6t@kdbg.org>
[not found] ` <20100407094356.GA16716@squonk.masqnet>
[not found] ` <201004072033.59546.j6t@kdbg.org>
[not found] ` <20100408081737.GA8018@squonk.masqnet>
[not found] ` <chaz20100408104928.GA3959@yahoo.fr>
[not found] ` <20100408111617.GB11737@squonk.masqnet>
[not found] ` <20100409033953.GA32629@gondor.apana.org.au>
[not found] ` <20100409082602.GA12973@squonk.masqnet>
2010-05-26 10:59 ` Assignment with command: export only, or sets variable, too? Herbert Xu
2010-05-26 11:00 ` [PATCH 1/4] [VAR] Add localvars nesting Herbert Xu
2010-05-26 21:55 ` Jilles Tjoelker [this message]
2010-05-27 3:34 ` Herbert Xu
2010-05-27 7:16 ` [PATCH 1/2] [REDIR] Move null redirect checks into caller Herbert Xu
2010-05-27 7:16 ` [PATCH 2/2] [REDIR] Fix popredir on abnormal exit from built-in Herbert Xu
2010-05-26 11:00 ` [PATCH 2/4] [VAR] Fix poplocalvar leak Herbert Xu
2010-05-26 11:00 ` [PATCH 3/4] [VAR] Move unsetvar functionality into setvareq Herbert Xu
2010-05-26 11:00 ` [PATCH 4/4] [VAR] Replace cmdenviron with localvars Herbert Xu
2010-05-26 22:37 ` Jilles Tjoelker
2010-05-27 3:51 ` Herbert Xu
2010-05-29 13:45 ` Jilles Tjoelker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100526215533.GA5679@stack.nl \
--to=jilles@stack.nl \
--cc=dash@vger.kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=pape@smarden.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox