From patchwork Tue May 15 06:37:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 10400053 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 459646019C for ; Tue, 15 May 2018 06:37:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 184A328672 for ; Tue, 15 May 2018 06:37:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0CEA428676; Tue, 15 May 2018 06:37:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9527828672 for ; Tue, 15 May 2018 06:37:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752441AbeEOGhX (ORCPT ); Tue, 15 May 2018 02:37:23 -0400 Received: from orcrist.hmeau.com ([104.223.48.154]:45636 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752334AbeEOGhW (ORCPT ); Tue, 15 May 2018 02:37:22 -0400 Received: from gondobar.mordor.me.apana.org.au ([192.168.128.4] helo=gondobar) by deadmen.hmeau.com with esmtps (Exim 4.89 #2 (Debian)) id 1fITaK-0005W6-QL for ; Tue, 15 May 2018 14:37:20 +0800 Received: from herbert by gondobar with local (Exim 4.89) (envelope-from ) id 1fITaJ-0000Va-Sn; Tue, 15 May 2018 14:37:20 +0800 Subject: [v2 PATCH 9/12] eval: Replace external use of mklocal with listsetvar References: <20180515063602.u6jdebjzcr6ve2dh@gondor.apana.org.au> To: DASH Mailing List Message-Id: From: Herbert Xu Date: Tue, 15 May 2018 14:37:19 +0800 Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds support for listsetvar to be used for setting local variables in bulk through the VLOCAL flag. It also removes the use of mklocal in evalcommand, and replaces it with listsetvar. Signed-off-by: Herbert Xu --- src/eval.c | 16 ++++++++-------- src/var.c | 16 ++++++++++------ src/var.h | 2 +- 3 files changed, 19 insertions(+), 15 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/src/eval.c b/src/eval.c index 1b803db..c160500 100644 --- a/src/eval.c +++ b/src/eval.c @@ -714,6 +714,7 @@ evalcommand(union node *cmd, int flags) int execcmd; int status; char **nargv; + int vflags; errlinno = lineno = cmd->ncmd.linno; if (funcline) @@ -769,8 +770,6 @@ evalcommand(union node *cmd, int flags) spp = varlist.lastp; expandarg(argp, &varlist, EXP_VARTILDE); - mklocal((*spp)->text); - /* * Modify the command lookup path, if a PATH= assignment * is present @@ -852,6 +851,13 @@ bail: jp = NULL; + if (cmdentry.cmdtype == CMDBUILTIN && (spclbltin > 0 || argc == 0)) + vflags = execcmd && argc > 1 ? VEXPORT : 0; + else + vflags = VLOCAL | (cmdentry.cmdtype == CMDNORMAL ? + VEXPORT | VNOFUNC : 0); + listsetvar(varlist.list, vflags); + /* Execute the command. */ switch (cmdentry.cmdtype) { default: @@ -863,16 +869,10 @@ bail: break; FORCEINTON; } - listsetvar(varlist.list, VEXPORT|VSTACK); shellexec(argv, path, cmdentry.u.index); /* NOTREACHED */ case CMDBUILTIN: - if (spclbltin > 0 || argc == 0) { - poplocalvars(1); - if (execcmd && argc > 1) - listsetvar(varlist.list, VEXPORT); - } if (evalbltin(cmdentry.u.cmd, argc, argv, flags) && !(exception == EXERROR && spclbltin <= 0)) { raise: diff --git a/src/var.c b/src/var.c index 604ab1f..bb05aa8 100644 --- a/src/var.c +++ b/src/var.c @@ -108,6 +108,7 @@ STATIC struct var *vartab[VTABSIZE]; STATIC struct var **hashvar(const char *); STATIC int vpcmp(const void *, const void *); STATIC struct var **findvar(struct var **, const char *); +static void mklocal(char *name, int flags); /* * Initialize the varable symbol tables and import the environment @@ -318,7 +319,10 @@ listsetvar(struct strlist *list, int flags) return; INTOFF; do { - setvareq(lp->text, flags); + if (flags & VLOCAL) + mklocal(lp->text, flags & ~VLOCAL); + else + setvareq(lp->text, flags); } while ((lp = lp->next)); INTON; } @@ -468,7 +472,7 @@ localcmd(int argc, char **argv) argv = argptr; while ((name = *argv++) != NULL) { - mklocal(name); + mklocal(name, 0); } return 0; } @@ -481,7 +485,7 @@ localcmd(int argc, char **argv) * "-" as a special case. */ -void mklocal(char *name) +static void mklocal(char *name, int flags) { struct localvar *lvp; struct var **vpp; @@ -502,16 +506,16 @@ void mklocal(char *name) eq = strchr(name, '='); if (vp == NULL) { if (eq) - vp = setvareq(name, VSTRFIXED); + vp = setvareq(name, VSTRFIXED | flags); else - vp = setvar(name, NULL, VSTRFIXED); + vp = setvar(name, NULL, VSTRFIXED | flags); lvp->flags = VUNSET; } else { lvp->text = vp->text; lvp->flags = vp->flags; vp->flags |= VSTRFIXED|VTEXTFIXED; if (eq) - setvareq(name, 0); + setvareq(name, flags); } } lvp->vp = vp; diff --git a/src/var.h b/src/var.h index 55fed1b..a5bd8d7 100644 --- a/src/var.h +++ b/src/var.h @@ -50,6 +50,7 @@ #define VNOFUNC 0x40 /* don't call the callback function */ #define VNOSET 0x80 /* do not set variable - just readonly test */ #define VNOSAVE 0x100 /* when text is on the heap before setvareq */ +#define VLOCAL 0x200 /* Tell listsetvar to call mklocal */ struct var { @@ -147,7 +148,6 @@ char **listvars(int, int, char ***); int showvars(const char *, int, int); int exportcmd(int, char **); int localcmd(int, char **); -void mklocal(char *); struct localvar_list *pushlocalvars(void); void poplocalvars(int); void unwindlocalvars(struct localvar_list *stop);