Date: Sun, 25 Apr 2010 20:43:19 +0000 (UTC) From: Jilles Tjoelker <jilles@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r207206 - head/bin/sh Message-ID: <201004252043.o3PKhJi7065713@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
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++) ;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201004252043.o3PKhJi7065713>