From owner-svn-src-head@FreeBSD.ORG Fri Jan 24 16:40:52 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 988ED40B; Fri, 24 Jan 2014 16:40:52 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 7882F115C; Fri, 24 Jan 2014 16:40:52 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id s0OGeqsu021573; Fri, 24 Jan 2014 16:40:52 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id s0OGepC0021562; Fri, 24 Jan 2014 16:40:51 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201401241640.s0OGepC0021562@svn.freebsd.org> From: Jilles Tjoelker Date: Fri, 24 Jan 2014 16:40:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r261125 - in head/bin/sh: . tests/builtins X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Jan 2014 16:40:52 -0000 Author: jilles Date: Fri Jan 24 16:40:51 2014 New Revision: 261125 URL: http://svnweb.freebsd.org/changeset/base/261125 Log: sh: Solve the alias recursion problem in a less hackish way. Add the space to avoid alias recursion when the alias is expanded, not when it is added. As a result, displaying an alias via command -v, command -V or type no longer erroneously appends a space. Adjust the tests so they now require this bug to be absent. Modified: head/bin/sh/alias.c head/bin/sh/input.c head/bin/sh/tests/builtins/command3.0.stdout head/bin/sh/tests/builtins/command5.0.stdout head/bin/sh/tests/builtins/command6.0.stdout Modified: head/bin/sh/alias.c ============================================================================== --- head/bin/sh/alias.c Fri Jan 24 15:34:22 2014 (r261124) +++ head/bin/sh/alias.c Fri Jan 24 16:40:51 2014 (r261125) @@ -68,18 +68,7 @@ setalias(const char *name, const char *v if (equal(name, ap->name)) { INTOFF; ckfree(ap->val); - /* See HACK below. */ -#ifdef notyet ap->val = savestr(val); -#else - { - size_t len = strlen(val); - ap->val = ckmalloc(len + 2); - memcpy(ap->val, val, len); - ap->val[len] = ' '; - ap->val[len+1] = '\0'; - } -#endif INTON; return; } @@ -88,34 +77,7 @@ setalias(const char *name, const char *v INTOFF; ap = ckmalloc(sizeof (struct alias)); ap->name = savestr(name); - /* - * XXX - HACK: in order that the parser will not finish reading the - * alias value off the input before processing the next alias, we - * dummy up an extra space at the end of the alias. This is a crock - * and should be re-thought. The idea (if you feel inclined to help) - * is to avoid alias recursions. The mechanism used is: when - * expanding an alias, the value of the alias is pushed back on the - * input as a string and a pointer to the alias is stored with the - * string. The alias is marked as being in use. When the input - * routine finishes reading the string, it marks the alias not - * in use. The problem is synchronization with the parser. Since - * it reads ahead, the alias is marked not in use before the - * resulting token(s) is next checked for further alias sub. The - * H A C K is that we add a little fluff after the alias value - * so that the string will not be exhausted. This is a good - * idea ------- ***NOT*** - */ -#ifdef notyet ap->val = savestr(val); -#else /* hack */ - { - size_t len = strlen(val); - ap->val = ckmalloc(len + 2); - memcpy(ap->val, val, len); - ap->val[len] = ' '; /* fluff */ - ap->val[len+1] = '\0'; - } -#endif ap->flag = 0; ap->next = *app; *app = ap; @@ -207,14 +169,8 @@ comparealiases(const void *p1, const voi static void printalias(const struct alias *a) { - char *p; - out1fmt("%s=", a->name); - /* Don't print the space added above. */ - p = a->val + strlen(a->val) - 1; - *p = '\0'; out1qstr(a->val); - *p = ' '; out1c('\n'); } Modified: head/bin/sh/input.c ============================================================================== --- head/bin/sh/input.c Fri Jan 24 15:34:22 2014 (r261124) +++ head/bin/sh/input.c Fri Jan 24 16:40:51 2014 (r261125) @@ -226,7 +226,14 @@ preadbuffer(void) int more; char savec; - if (parsefile->strpush) { + while (parsefile->strpush) { + /* + * Add a space to the end of an alias to ensure that the + * alias remains in use while parsing its last word. + * This avoids alias recursions. + */ + if (parsenleft == -1 && parsefile->strpush->ap != NULL) + return ' '; popstring(); if (--parsenleft >= 0) return (*parsenextc++); Modified: head/bin/sh/tests/builtins/command3.0.stdout ============================================================================== --- head/bin/sh/tests/builtins/command3.0.stdout Fri Jan 24 15:34:22 2014 (r261124) +++ head/bin/sh/tests/builtins/command3.0.stdout Fri Jan 24 16:40:51 2014 (r261125) @@ -4,4 +4,4 @@ true fun break if -alias foo='bar ' +alias foo=bar Modified: head/bin/sh/tests/builtins/command5.0.stdout ============================================================================== --- head/bin/sh/tests/builtins/command5.0.stdout Fri Jan 24 15:34:22 2014 (r261124) +++ head/bin/sh/tests/builtins/command5.0.stdout Fri Jan 24 16:40:51 2014 (r261125) @@ -5,4 +5,4 @@ fun is a shell function break is a special shell builtin if is a shell keyword { is a shell keyword -foo is an alias for bar +foo is an alias for bar Modified: head/bin/sh/tests/builtins/command6.0.stdout ============================================================================== --- head/bin/sh/tests/builtins/command6.0.stdout Fri Jan 24 15:34:22 2014 (r261124) +++ head/bin/sh/tests/builtins/command6.0.stdout Fri Jan 24 16:40:51 2014 (r261125) @@ -4,4 +4,4 @@ fun is a shell function break is a special shell builtin if is a shell keyword { is a shell keyword -foo is an alias for bar +foo is an alias for bar