diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-20 16:38:54 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-20 16:38:54 +0000 |
commit | 597906c436f57d96deec5c57e5ba50bf3a95a5b7 (patch) | |
tree | 9462bf5b40a7cb7623d8214f32e070f95df8e0cc | |
parent | e7b43cf59fe6472442026cc3d3d57a5e502371f5 (diff) | |
download | busybox-w32-597906c436f57d96deec5c57e5ba50bf3a95a5b7.tar.gz busybox-w32-597906c436f57d96deec5c57e5ba50bf3a95a5b7.tar.bz2 busybox-w32-597906c436f57d96deec5c57e5ba50bf3a95a5b7.zip |
ash: introduce and use stzalloc and ckzalloc.
function old new delta
stzalloc - 29 +29
ckzalloc - 29 +29
recordregion 108 102 -6
cmdlookup 158 152 -6
pipeline 188 181 -7
parseheredoc 135 128 -7
makename 42 35 -7
list 355 348 -7
setvareq 221 212 -9
aliascmd 324 311 -13
pushfile 83 69 -14
readtoken1 2872 2849 -23
parse_command 1430 1391 -39
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 0/11 up/down: 58/-138) Total: -80 bytes
text data bss dec hex filename
577227 706 23740 601673 92e49 busybox_old
577147 706 23740 601593 92df9 busybox_unstripped
-rw-r--r-- | shell/ash.c | 104 |
1 files changed, 60 insertions, 44 deletions
diff --git a/shell/ash.c b/shell/ash.c index 25c8fa521..65f94f682 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -1185,6 +1185,12 @@ ckmalloc(size_t nbytes) | |||
1185 | return ckrealloc(NULL, nbytes); | 1185 | return ckrealloc(NULL, nbytes); |
1186 | } | 1186 | } |
1187 | 1187 | ||
1188 | static void * | ||
1189 | ckzalloc(size_t nbytes) | ||
1190 | { | ||
1191 | return memset(ckmalloc(nbytes), 0, nbytes); | ||
1192 | } | ||
1193 | |||
1188 | /* | 1194 | /* |
1189 | * Make a copy of a string in safe storage. | 1195 | * Make a copy of a string in safe storage. |
1190 | */ | 1196 | */ |
@@ -1238,6 +1244,12 @@ stalloc(size_t nbytes) | |||
1238 | return p; | 1244 | return p; |
1239 | } | 1245 | } |
1240 | 1246 | ||
1247 | static void * | ||
1248 | stzalloc(size_t nbytes) | ||
1249 | { | ||
1250 | return memset(stalloc(nbytes), 0, nbytes); | ||
1251 | } | ||
1252 | |||
1241 | static void | 1253 | static void |
1242 | stunalloc(void *p) | 1254 | stunalloc(void *p) |
1243 | { | 1255 | { |
@@ -2028,9 +2040,9 @@ setvareq(char *s, int flags) | |||
2028 | if (flags & VNOSET) | 2040 | if (flags & VNOSET) |
2029 | return; | 2041 | return; |
2030 | /* not found */ | 2042 | /* not found */ |
2031 | vp = ckmalloc(sizeof(*vp)); | 2043 | vp = ckzalloc(sizeof(*vp)); |
2032 | vp->next = *vpp; | 2044 | vp->next = *vpp; |
2033 | vp->func = NULL; | 2045 | /*vp->func = NULL; - ckzalloc did it */ |
2034 | *vpp = vp; | 2046 | *vpp = vp; |
2035 | } | 2047 | } |
2036 | if (!(flags & (VTEXTFIXED|VSTACK|VNOSAVE))) | 2048 | if (!(flags & (VTEXTFIXED|VSTACK|VNOSAVE))) |
@@ -3072,11 +3084,11 @@ setalias(const char *name, const char *val) | |||
3072 | ap->flag &= ~ALIASDEAD; | 3084 | ap->flag &= ~ALIASDEAD; |
3073 | } else { | 3085 | } else { |
3074 | /* not found */ | 3086 | /* not found */ |
3075 | ap = ckmalloc(sizeof(struct alias)); | 3087 | ap = ckzalloc(sizeof(struct alias)); |
3076 | ap->name = ckstrdup(name); | 3088 | ap->name = ckstrdup(name); |
3077 | ap->val = ckstrdup(val); | 3089 | ap->val = ckstrdup(val); |
3078 | ap->flag = 0; | 3090 | /*ap->flag = 0; - ckzalloc did it */ |
3079 | ap->next = 0; | 3091 | /*ap->next = NULL;*/ |
3080 | *app = ap; | 3092 | *app = ap; |
3081 | } | 3093 | } |
3082 | INT_ON; | 3094 | INT_ON; |
@@ -5222,8 +5234,8 @@ recordregion(int start, int end, int nulonly) | |||
5222 | ifsp = &ifsfirst; | 5234 | ifsp = &ifsfirst; |
5223 | } else { | 5235 | } else { |
5224 | INT_OFF; | 5236 | INT_OFF; |
5225 | ifsp = ckmalloc(sizeof(*ifsp)); | 5237 | ifsp = ckzalloc(sizeof(*ifsp)); |
5226 | ifsp->next = NULL; | 5238 | /*ifsp->next = NULL; - ckzalloc did it */ |
5227 | ifslastp->next = ifsp; | 5239 | ifslastp->next = ifsp; |
5228 | INT_ON; | 5240 | INT_ON; |
5229 | } | 5241 | } |
@@ -6139,7 +6151,7 @@ ifsbreakup(char *string, struct arglist *arglist) | |||
6139 | continue; | 6151 | continue; |
6140 | } | 6152 | } |
6141 | *q = '\0'; | 6153 | *q = '\0'; |
6142 | sp = stalloc(sizeof(*sp)); | 6154 | sp = stzalloc(sizeof(*sp)); |
6143 | sp->text = start; | 6155 | sp->text = start; |
6144 | *arglist->lastp = sp; | 6156 | *arglist->lastp = sp; |
6145 | arglist->lastp = &sp->next; | 6157 | arglist->lastp = &sp->next; |
@@ -6155,7 +6167,8 @@ ifsbreakup(char *string, struct arglist *arglist) | |||
6155 | if (strchr(ifs, *p) == NULL ) { | 6167 | if (strchr(ifs, *p) == NULL ) { |
6156 | p = q; | 6168 | p = q; |
6157 | break; | 6169 | break; |
6158 | } else if (strchr(defifs, *p) == NULL) { | 6170 | } |
6171 | if (strchr(defifs, *p) == NULL) { | ||
6159 | if (ifsspc) { | 6172 | if (ifsspc) { |
6160 | p++; | 6173 | p++; |
6161 | ifsspc = 0; | 6174 | ifsspc = 0; |
@@ -6179,7 +6192,7 @@ ifsbreakup(char *string, struct arglist *arglist) | |||
6179 | return; | 6192 | return; |
6180 | 6193 | ||
6181 | add: | 6194 | add: |
6182 | sp = stalloc(sizeof(*sp)); | 6195 | sp = stzalloc(sizeof(*sp)); |
6183 | sp->text = start; | 6196 | sp->text = start; |
6184 | *arglist->lastp = sp; | 6197 | *arglist->lastp = sp; |
6185 | arglist->lastp = &sp->next; | 6198 | arglist->lastp = &sp->next; |
@@ -6211,7 +6224,7 @@ addfname(const char *name) | |||
6211 | { | 6224 | { |
6212 | struct strlist *sp; | 6225 | struct strlist *sp; |
6213 | 6226 | ||
6214 | sp = stalloc(sizeof(*sp)); | 6227 | sp = stzalloc(sizeof(*sp)); |
6215 | sp->text = ststrdup(name); | 6228 | sp->text = ststrdup(name); |
6216 | *exparg.lastp = sp; | 6229 | *exparg.lastp = sp; |
6217 | exparg.lastp = &sp->next; | 6230 | exparg.lastp = &sp->next; |
@@ -6481,7 +6494,7 @@ expandarg(union node *arg, struct arglist *arglist, int flag) | |||
6481 | } else { | 6494 | } else { |
6482 | if (flag & EXP_REDIR) /*XXX - for now, just remove escapes */ | 6495 | if (flag & EXP_REDIR) /*XXX - for now, just remove escapes */ |
6483 | rmescapes(p); | 6496 | rmescapes(p); |
6484 | sp = stalloc(sizeof(*sp)); | 6497 | sp = stzalloc(sizeof(*sp)); |
6485 | sp->text = p; | 6498 | sp->text = p; |
6486 | *exparg.lastp = sp; | 6499 | *exparg.lastp = sp; |
6487 | exparg.lastp = &sp->next; | 6500 | exparg.lastp = &sp->next; |
@@ -6644,7 +6657,7 @@ tryexec(char *cmd, char **argv, char **envp) | |||
6644 | ap += 2; | 6657 | ap += 2; |
6645 | argv++; | 6658 | argv++; |
6646 | while ((*ap++ = *argv++)) | 6659 | while ((*ap++ = *argv++)) |
6647 | ; | 6660 | continue; |
6648 | argv = new; | 6661 | argv = new; |
6649 | goto repeat; | 6662 | goto repeat; |
6650 | } | 6663 | } |
@@ -6781,9 +6794,9 @@ cmdlookup(const char *name, int add) | |||
6781 | pp = &cmdp->next; | 6794 | pp = &cmdp->next; |
6782 | } | 6795 | } |
6783 | if (add && cmdp == NULL) { | 6796 | if (add && cmdp == NULL) { |
6784 | cmdp = *pp = ckmalloc(sizeof(struct tblentry) - ARB | 6797 | cmdp = *pp = ckzalloc(sizeof(struct tblentry) - ARB |
6785 | + strlen(name) + 1); | 6798 | + strlen(name) + 1); |
6786 | cmdp->next = NULL; | 6799 | /*cmdp->next = NULL; - ckzalloc did it */ |
6787 | cmdp->cmdtype = CMDUNKNOWN; | 6800 | cmdp->cmdtype = CMDUNKNOWN; |
6788 | strcpy(cmdp->cmdname, name); | 6801 | strcpy(cmdp->cmdname, name); |
6789 | } | 6802 | } |
@@ -8903,11 +8916,11 @@ pushfile(void) | |||
8903 | parsefile->lleft = parselleft; | 8916 | parsefile->lleft = parselleft; |
8904 | parsefile->nextc = parsenextc; | 8917 | parsefile->nextc = parsenextc; |
8905 | parsefile->linno = plinno; | 8918 | parsefile->linno = plinno; |
8906 | pf = ckmalloc(sizeof(*pf)); | 8919 | pf = ckzalloc(sizeof(*pf)); |
8907 | pf->prev = parsefile; | 8920 | pf->prev = parsefile; |
8908 | pf->fd = -1; | 8921 | pf->fd = -1; |
8909 | pf->strpush = NULL; | 8922 | /*pf->strpush = NULL; - ckzalloc did it */ |
8910 | pf->basestrpush.prev = NULL; | 8923 | /*pf->basestrpush.prev = NULL;*/ |
8911 | parsefile = pf; | 8924 | parsefile = pf; |
8912 | } | 8925 | } |
8913 | 8926 | ||
@@ -9537,9 +9550,9 @@ list(int nlflag) | |||
9537 | n2->npipe.backgnd = 1; | 9550 | n2->npipe.backgnd = 1; |
9538 | } else { | 9551 | } else { |
9539 | if (n2->type != NREDIR) { | 9552 | if (n2->type != NREDIR) { |
9540 | n3 = stalloc(sizeof(struct nredir)); | 9553 | n3 = stzalloc(sizeof(struct nredir)); |
9541 | n3->nredir.n = n2; | 9554 | n3->nredir.n = n2; |
9542 | n3->nredir.redirect = NULL; | 9555 | /*n3->nredir.redirect = NULL; - stzalloc did it */ |
9543 | n2 = n3; | 9556 | n2 = n3; |
9544 | } | 9557 | } |
9545 | n2->type = NBACKGND; | 9558 | n2->type = NBACKGND; |
@@ -9629,9 +9642,9 @@ pipeline(void) | |||
9629 | tokpushback = 1; | 9642 | tokpushback = 1; |
9630 | n1 = parse_command(); | 9643 | n1 = parse_command(); |
9631 | if (readtoken() == TPIPE) { | 9644 | if (readtoken() == TPIPE) { |
9632 | pipenode = stalloc(sizeof(struct npipe)); | 9645 | pipenode = stzalloc(sizeof(struct npipe)); |
9633 | pipenode->type = NPIPE; | 9646 | pipenode->type = NPIPE; |
9634 | pipenode->npipe.backgnd = 0; | 9647 | /*pipenode->npipe.backgnd = 0; - stzalloc did it */ |
9635 | lp = stalloc(sizeof(struct nodelist)); | 9648 | lp = stalloc(sizeof(struct nodelist)); |
9636 | pipenode->npipe.cmdlist = lp; | 9649 | pipenode->npipe.cmdlist = lp; |
9637 | lp->n = n1; | 9650 | lp->n = n1; |
@@ -9660,9 +9673,9 @@ makename(void) | |||
9660 | { | 9673 | { |
9661 | union node *n; | 9674 | union node *n; |
9662 | 9675 | ||
9663 | n = stalloc(sizeof(struct narg)); | 9676 | n = stzalloc(sizeof(struct narg)); |
9664 | n->type = NARG; | 9677 | n->type = NARG; |
9665 | n->narg.next = NULL; | 9678 | /*n->narg.next = NULL; - stzalloc did it */ |
9666 | n->narg.text = wordtext; | 9679 | n->narg.text = wordtext; |
9667 | n->narg.backquote = backquotelist; | 9680 | n->narg.backquote = backquotelist; |
9668 | return n; | 9681 | return n; |
@@ -9762,8 +9775,9 @@ simplecmd(void) | |||
9762 | checkkwd = savecheckkwd; | 9775 | checkkwd = savecheckkwd; |
9763 | switch (readtoken()) { | 9776 | switch (readtoken()) { |
9764 | case TWORD: | 9777 | case TWORD: |
9765 | n = stalloc(sizeof(struct narg)); | 9778 | n = stzalloc(sizeof(struct narg)); |
9766 | n->type = NARG; | 9779 | n->type = NARG; |
9780 | /*n->narg.next = NULL; - stzalloc did it */ | ||
9767 | n->narg.text = wordtext; | 9781 | n->narg.text = wordtext; |
9768 | n->narg.backquote = backquotelist; | 9782 | n->narg.backquote = backquotelist; |
9769 | if (savecheckkwd && isassignment(wordtext)) { | 9783 | if (savecheckkwd && isassignment(wordtext)) { |
@@ -9887,8 +9901,9 @@ parse_command(void) | |||
9887 | if (readtoken() == TIN) { | 9901 | if (readtoken() == TIN) { |
9888 | app = ≈ | 9902 | app = ≈ |
9889 | while (readtoken() == TWORD) { | 9903 | while (readtoken() == TWORD) { |
9890 | n2 = stalloc(sizeof(struct narg)); | 9904 | n2 = stzalloc(sizeof(struct narg)); |
9891 | n2->type = NARG; | 9905 | n2->type = NARG; |
9906 | /*n2->narg.next = NULL; - stzalloc did it */ | ||
9892 | n2->narg.text = wordtext; | 9907 | n2->narg.text = wordtext; |
9893 | n2->narg.backquote = backquotelist; | 9908 | n2->narg.backquote = backquotelist; |
9894 | *app = n2; | 9909 | *app = n2; |
@@ -9899,11 +9914,11 @@ parse_command(void) | |||
9899 | if (lasttoken != TNL && lasttoken != TSEMI) | 9914 | if (lasttoken != TNL && lasttoken != TSEMI) |
9900 | raise_error_unexpected_syntax(-1); | 9915 | raise_error_unexpected_syntax(-1); |
9901 | } else { | 9916 | } else { |
9902 | n2 = stalloc(sizeof(struct narg)); | 9917 | n2 = stzalloc(sizeof(struct narg)); |
9903 | n2->type = NARG; | 9918 | n2->type = NARG; |
9919 | /*n2->narg.next = NULL; - stzalloc did it */ | ||
9904 | n2->narg.text = (char *)dolatstr; | 9920 | n2->narg.text = (char *)dolatstr; |
9905 | n2->narg.backquote = NULL; | 9921 | /*n2->narg.backquote = NULL;*/ |
9906 | n2->narg.next = NULL; | ||
9907 | n1->nfor.args = n2; | 9922 | n1->nfor.args = n2; |
9908 | /* | 9923 | /* |
9909 | * Newline or semicolon here is optional (but note | 9924 | * Newline or semicolon here is optional (but note |
@@ -9923,11 +9938,11 @@ parse_command(void) | |||
9923 | n1->type = NCASE; | 9938 | n1->type = NCASE; |
9924 | if (readtoken() != TWORD) | 9939 | if (readtoken() != TWORD) |
9925 | raise_error_unexpected_syntax(TWORD); | 9940 | raise_error_unexpected_syntax(TWORD); |
9926 | n1->ncase.expr = n2 = stalloc(sizeof(struct narg)); | 9941 | n1->ncase.expr = n2 = stzalloc(sizeof(struct narg)); |
9927 | n2->type = NARG; | 9942 | n2->type = NARG; |
9943 | /*n2->narg.next = NULL; - stzalloc did it */ | ||
9928 | n2->narg.text = wordtext; | 9944 | n2->narg.text = wordtext; |
9929 | n2->narg.backquote = backquotelist; | 9945 | n2->narg.backquote = backquotelist; |
9930 | n2->narg.next = NULL; | ||
9931 | do { | 9946 | do { |
9932 | checkkwd = CHKKWD | CHKALIAS; | 9947 | checkkwd = CHKKWD | CHKALIAS; |
9933 | } while (readtoken() == TNL); | 9948 | } while (readtoken() == TNL); |
@@ -9944,8 +9959,9 @@ parse_command(void) | |||
9944 | cp->type = NCLIST; | 9959 | cp->type = NCLIST; |
9945 | app = &cp->nclist.pattern; | 9960 | app = &cp->nclist.pattern; |
9946 | for (;;) { | 9961 | for (;;) { |
9947 | *app = ap = stalloc(sizeof(struct narg)); | 9962 | *app = ap = stzalloc(sizeof(struct narg)); |
9948 | ap->type = NARG; | 9963 | ap->type = NARG; |
9964 | /*ap->narg.next = NULL; - stzalloc did it */ | ||
9949 | ap->narg.text = wordtext; | 9965 | ap->narg.text = wordtext; |
9950 | ap->narg.backquote = backquotelist; | 9966 | ap->narg.backquote = backquotelist; |
9951 | if (readtoken() != TPIPE) | 9967 | if (readtoken() != TPIPE) |
@@ -9953,7 +9969,7 @@ parse_command(void) | |||
9953 | app = &ap->narg.next; | 9969 | app = &ap->narg.next; |
9954 | readtoken(); | 9970 | readtoken(); |
9955 | } | 9971 | } |
9956 | ap->narg.next = NULL; | 9972 | //ap->narg.next = NULL; |
9957 | if (lasttoken != TRP) | 9973 | if (lasttoken != TRP) |
9958 | raise_error_unexpected_syntax(TRP); | 9974 | raise_error_unexpected_syntax(TRP); |
9959 | cp->nclist.body = list(2); | 9975 | cp->nclist.body = list(2); |
@@ -9971,10 +9987,10 @@ parse_command(void) | |||
9971 | *cpp = NULL; | 9987 | *cpp = NULL; |
9972 | goto redir; | 9988 | goto redir; |
9973 | case TLP: | 9989 | case TLP: |
9974 | n1 = stalloc(sizeof(struct nredir)); | 9990 | n1 = stzalloc(sizeof(struct nredir)); |
9975 | n1->type = NSUBSHELL; | 9991 | n1->type = NSUBSHELL; |
9976 | n1->nredir.n = list(0); | 9992 | n1->nredir.n = list(0); |
9977 | n1->nredir.redirect = NULL; | 9993 | /*n1->nredir.redirect = NULL; - stzalloc did it */ |
9978 | t = TRP; | 9994 | t = TRP; |
9979 | break; | 9995 | break; |
9980 | case TBEGIN: | 9996 | case TBEGIN: |
@@ -10003,7 +10019,7 @@ parse_command(void) | |||
10003 | *rpp = NULL; | 10019 | *rpp = NULL; |
10004 | if (redir) { | 10020 | if (redir) { |
10005 | if (n1->type != NSUBSHELL) { | 10021 | if (n1->type != NSUBSHELL) { |
10006 | n2 = stalloc(sizeof(struct nredir)); | 10022 | n2 = stzalloc(sizeof(struct nredir)); |
10007 | n2->type = NREDIR; | 10023 | n2->type = NREDIR; |
10008 | n2->nredir.n = n1; | 10024 | n2->nredir.n = n1; |
10009 | n1 = n2; | 10025 | n1 = n2; |
@@ -10301,7 +10317,7 @@ parseredir: { | |||
10301 | char fd = *out; | 10317 | char fd = *out; |
10302 | union node *np; | 10318 | union node *np; |
10303 | 10319 | ||
10304 | np = stalloc(sizeof(struct nfile)); | 10320 | np = stzalloc(sizeof(struct nfile)); |
10305 | if (c == '>') { | 10321 | if (c == '>') { |
10306 | np->nfile.fd = 1; | 10322 | np->nfile.fd = 1; |
10307 | c = pgetc(); | 10323 | c = pgetc(); |
@@ -10316,13 +10332,13 @@ parseredir: { | |||
10316 | pungetc(); | 10332 | pungetc(); |
10317 | } | 10333 | } |
10318 | } else { /* c == '<' */ | 10334 | } else { /* c == '<' */ |
10319 | np->nfile.fd = 0; | 10335 | /*np->nfile.fd = 0; - stzalloc did it */ |
10320 | c = pgetc(); | 10336 | c = pgetc(); |
10321 | switch (c) { | 10337 | switch (c) { |
10322 | case '<': | 10338 | case '<': |
10323 | if (sizeof(struct nfile) != sizeof(struct nhere)) { | 10339 | if (sizeof(struct nfile) != sizeof(struct nhere)) { |
10324 | np = stalloc(sizeof(struct nhere)); | 10340 | np = stzalloc(sizeof(struct nhere)); |
10325 | np->nfile.fd = 0; | 10341 | /*np->nfile.fd = 0; - stzalloc did it */ |
10326 | } | 10342 | } |
10327 | np->type = NHERE; | 10343 | np->type = NHERE; |
10328 | heredoc = stalloc(sizeof(struct heredoc)); | 10344 | heredoc = stalloc(sizeof(struct heredoc)); |
@@ -10573,8 +10589,8 @@ parsebackq: { | |||
10573 | nlpp = &bqlist; | 10589 | nlpp = &bqlist; |
10574 | while (*nlpp) | 10590 | while (*nlpp) |
10575 | nlpp = &(*nlpp)->next; | 10591 | nlpp = &(*nlpp)->next; |
10576 | *nlpp = stalloc(sizeof(**nlpp)); | 10592 | *nlpp = stzalloc(sizeof(**nlpp)); |
10577 | (*nlpp)->next = NULL; | 10593 | /* (*nlpp)->next = NULL; - stzalloc did it */ |
10578 | parsebackquote = oldstyle; | 10594 | parsebackquote = oldstyle; |
10579 | 10595 | ||
10580 | if (oldstyle) { | 10596 | if (oldstyle) { |
@@ -10930,9 +10946,9 @@ parseheredoc(void) | |||
10930 | } | 10946 | } |
10931 | readtoken1(pgetc(), here->here->type == NHERE? SQSYNTAX : DQSYNTAX, | 10947 | readtoken1(pgetc(), here->here->type == NHERE? SQSYNTAX : DQSYNTAX, |
10932 | here->eofmark, here->striptabs); | 10948 | here->eofmark, here->striptabs); |
10933 | n = stalloc(sizeof(struct narg)); | 10949 | n = stzalloc(sizeof(struct narg)); |
10934 | n->narg.type = NARG; | 10950 | n->narg.type = NARG; |
10935 | n->narg.next = NULL; | 10951 | /*n->narg.next = NULL; - stzalloc did it */ |
10936 | n->narg.text = wordtext; | 10952 | n->narg.text = wordtext; |
10937 | n->narg.backquote = backquotelist; | 10953 | n->narg.backquote = backquotelist; |
10938 | here->here->nhere.doc = n; | 10954 | here->here->nhere.doc = n; |