summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2010-04-25 20:43:19 +0000
committerjilles <jilles@FreeBSD.org>2010-04-25 20:43:19 +0000
commit88403fad183ba6067547daa0d779c87bf100403f (patch)
tree0d483cc468eee9850434c86361d24e23e247d468
parent019a1d16bacaa7783b857c309ce61d655e899904 (diff)
downloadFreeBSD-src-88403fad183ba6067547daa0d779c87bf100403f.zip
FreeBSD-src-88403fad183ba6067547daa0d779c87bf100403f.tar.gz
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.
-rw-r--r--bin/sh/arith.y4
-rw-r--r--bin/sh/arith_lex.l26
-rw-r--r--bin/sh/expand.c4
3 files changed, 10 insertions, 24 deletions
diff --git a/bin/sh/arith.y b/bin/sh/arith.y
index 5db1633..28046ba 100644
--- a/bin/sh/arith.y
+++ b/bin/sh/arith.y
@@ -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;
}
diff --git a/bin/sh/arith_lex.l b/bin/sh/arith_lex.l
index f0d9cb3..aede40f 100644
--- a/bin/sh/arith_lex.l
+++ b/bin/sh/arith_lex.l
@@ -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;
}
diff --git a/bin/sh/expand.c b/bin/sh/expand.c
index ab885ac..7d98737 100644
--- a/bin/sh/expand.c
+++ b/bin/sh/expand.c
@@ -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++)
;
OpenPOWER on IntegriCloud