From owner-svn-src-head@FreeBSD.ORG Sun Apr 25 20:43:19 2010 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 91AAF1065674; Sun, 25 Apr 2010 20:43:19 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 673B88FC2A; Sun, 25 Apr 2010 20:43:19 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o3PKhJ9U065717; Sun, 25 Apr 2010 20:43:19 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o3PKhJi7065713; Sun, 25 Apr 2010 20:43:19 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201004252043.o3PKhJi7065713@svn.freebsd.org> From: Jilles Tjoelker Date: Sun, 25 Apr 2010 20:43:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r207206 - head/bin/sh X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 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: Sun, 25 Apr 2010 20:43:19 -0000 Author: jilles Date: Sun Apr 25 20:43:19 2010 New Revision: 207206 URL: http://svn.freebsd.org/changeset/base/207206 Log: sh: Use stalloc for arith variable names. This is simpler than the custom memory tracker I added earlier, and is also needed by the dash arith code I plan to import. Modified: head/bin/sh/arith.y head/bin/sh/arith_lex.l head/bin/sh/expand.c Modified: head/bin/sh/arith.y ============================================================================== --- head/bin/sh/arith.y Sun Apr 25 20:40:45 2010 (r207205) +++ head/bin/sh/arith.y Sun Apr 25 20:43:19 2010 (r207206) @@ -287,7 +287,9 @@ arith_t arith(const char *s) { arith_t result; + struct stackmark smark; + setstackmark(&smark); arith_buf = arith_startbuf = s; INTOFF; @@ -295,6 +297,8 @@ arith(const char *s) arith_lex_reset(); /* Reprime lex. */ INTON; + popstackmark(&smark); + return result; } Modified: head/bin/sh/arith_lex.l ============================================================================== --- head/bin/sh/arith_lex.l Sun Apr 25 20:40:45 2010 (r207205) +++ head/bin/sh/arith_lex.l Sun Apr 25 20:43:19 2010 (r207206) @@ -51,13 +51,6 @@ __FBSDID("$FreeBSD$"); int yylex(void); -struct varname -{ - struct varname *next; - char name[1]; -}; -static struct varname *varnames; - #undef YY_INPUT #define YY_INPUT(buf,result,max) \ result = (*buf = *arith_buf++) ? 1 : YY_NULL; @@ -87,14 +80,11 @@ static struct varname *varnames; * If variable doesn't exist, we should initialize * it to zero. */ - struct varname *temp; + char *temp; if (lookupvar(yytext) == NULL) setvarsafe(yytext, "0", 0); - temp = ckmalloc(sizeof(struct varname) + - strlen(yytext)); - temp->next = varnames; - varnames = temp; - yylval.s_value = strcpy(temp->name, yytext); + temp = stalloc(strlen(yytext) + 1); + yylval.s_value = strcpy(temp, yytext); return ARITH_VAR; } @@ -140,15 +130,5 @@ static struct varname *varnames; void arith_lex_reset(void) { - struct varname *name, *next; - YY_NEW_FILE; - - name = varnames; - while (name != NULL) { - next = name->next; - ckfree(name); - name = next; - } - varnames = NULL; } Modified: head/bin/sh/expand.c ============================================================================== --- head/bin/sh/expand.c Sun Apr 25 20:40:45 2010 (r207205) +++ head/bin/sh/expand.c Sun Apr 25 20:43:19 2010 (r207206) @@ -360,7 +360,7 @@ removerecordregions(int endoff) void expari(int flag) { - char *p, *start; + char *p, *q, *start; arith_t result; int begoff; int quotes = flag & (EXP_FULL | EXP_CASE | EXP_REDIR); @@ -398,7 +398,9 @@ expari(int flag) removerecordregions(begoff); if (quotes) rmescapes(p+2); + q = grabstackstr(expdest); result = arith(p+2); + ungrabstackstr(q, expdest); fmtstr(p, DIGITS(result), ARITH_FORMAT_STR, result); while (*p++) ;