From owner-svn-src-all@freebsd.org Sun Nov 1 22:07:42 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6544AA24BF0; Sun, 1 Nov 2015 22:07:42 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 2FCD810C5; Sun, 1 Nov 2015 22:07:42 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tA1M7f16044436; Sun, 1 Nov 2015 22:07:41 GMT (envelope-from jilles@FreeBSD.org) Received: (from jilles@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tA1M7egG044433; Sun, 1 Nov 2015 22:07:40 GMT (envelope-from jilles@FreeBSD.org) Message-Id: <201511012207.tA1M7egG044433@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jilles set sender to jilles@FreeBSD.org using -f From: Jilles Tjoelker Date: Sun, 1 Nov 2015 22:07:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r290244 - head/bin/sh X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 01 Nov 2015 22:07:42 -0000 Author: jilles Date: Sun Nov 1 22:07:40 2015 New Revision: 290244 URL: https://svnweb.freebsd.org/changeset/base/290244 Log: sh: Avoid copying argv for simple commands. Add dummy entries before and after so arglist's array is directly usable as argv. Modified: head/bin/sh/eval.c head/bin/sh/expand.c head/bin/sh/expand.h Modified: head/bin/sh/eval.c ============================================================================== --- head/bin/sh/eval.c Sun Nov 1 21:59:56 2015 (r290243) +++ head/bin/sh/eval.c Sun Nov 1 22:07:40 2015 (r290244) @@ -750,7 +750,7 @@ isdeclarationcmd(struct narg *arg) } static void -xtracecommand(struct arglist *varlist, struct arglist *arglist) +xtracecommand(struct arglist *varlist, int argc, char **argv) { char sep = 0; const char *text, *p, *ps4; @@ -771,8 +771,8 @@ xtracecommand(struct arglist *varlist, s out2qstr(text); sep = ' '; } - for (i = 0; i < arglist->count; i++) { - text = arglist->args[i]; + for (i = 0; i < argc; i++) { + text = argv[i]; if (sep != 0) out2c(' '); out2qstr(text); @@ -849,6 +849,8 @@ evalcommand(union node *cmd, int flags, do_clearcmdentry = 0; oexitstatus = exitstatus; exitstatus = 0; + /* Add one slot at the beginning for tryexec(). */ + appendarglist(&arglist, nullstr); for (argp = cmd->ncmd.args ; argp ; argp = argp->narg.next) { if (varflag && isassignment(argp->narg.text)) { expandarg(argp, varflag == 1 ? &varlist : &arglist, @@ -858,13 +860,11 @@ evalcommand(union node *cmd, int flags, varflag = isdeclarationcmd(&argp->narg) ? 2 : 0; expandarg(argp, &arglist, EXP_FULL | EXP_TILDE); } + appendarglist(&arglist, nullstr); expredir(cmd->ncmd.redirect); - argc = arglist.count; - /* Add one slot at the beginning for tryexec(). */ - argv = stalloc(sizeof (char *) * (argc + 2)); - argv++; + argc = arglist.count - 2; + argv = &arglist.args[1]; - memcpy(argv, arglist.args, sizeof(*argv) * argc); argv[argc] = NULL; lastarg = NULL; if (iflag && funcnest == 0 && argc > 0) @@ -872,7 +872,7 @@ evalcommand(union node *cmd, int flags, /* Print the command if xflag is set. */ if (xflag) - xtracecommand(&varlist, &arglist); + xtracecommand(&varlist, argc, argv); /* Now locate the command. */ if (argc == 0) { Modified: head/bin/sh/expand.c ============================================================================== --- head/bin/sh/expand.c Sun Nov 1 21:59:56 2015 (r290243) +++ head/bin/sh/expand.c Sun Nov 1 22:07:40 2015 (r290244) @@ -114,7 +114,6 @@ static void expmeta(char *, char *, stru static int expsortcmp(const void *, const void *); static int patmatch(const char *, const char *, int); static char *cvtnum(int, char *); -static void appendarglist(struct arglist *, char *); static int collate_range_cmp(wchar_t, wchar_t); void @@ -126,7 +125,7 @@ emptyarglist(struct arglist *list) list->capacity = sizeof(list->smallarg) / sizeof(list->smallarg[0]); } -static void +void appendarglist(struct arglist *list, char *str) { char **newargs; Modified: head/bin/sh/expand.h ============================================================================== --- head/bin/sh/expand.h Sun Nov 1 21:59:56 2015 (r290243) +++ head/bin/sh/expand.h Sun Nov 1 22:07:40 2015 (r290244) @@ -52,6 +52,7 @@ struct arglist { void emptyarglist(struct arglist *); +void appendarglist(struct arglist *, char *); union node; void expandarg(union node *, struct arglist *, int); void rmescapes(char *);