switch to a (nmemb,size) API from a (nmemb*size) API

cost: text += (308, 256, 4, -100)
This commit is contained in:
tg
2008-11-12 00:54:52 +00:00
parent 246b762af7
commit 4d3fc2413e
16 changed files with 136 additions and 140 deletions

38
tree.c
View File

@@ -2,7 +2,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.22 2008/11/11 23:50:31 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.23 2008/11/12 00:54:51 tg Exp $");
#define INDENT 4
@@ -421,7 +421,7 @@ tcopy(struct op *t, PArea ap)
if (t == NULL)
return NULL;
r = (struct op *)alloc(sizeof (struct op), ap);
r = alloc(1, sizeof (struct op), ap);
r->type = t->type;
r->u.evalflags = t->u.evalflags;
@@ -436,8 +436,8 @@ tcopy(struct op *t, PArea ap)
else {
for (tw = (const char **)t->vars; *tw++ != NULL; )
;
rw = r->vars = (char **)alloc((tw -
(const char **)t->vars + 1) * sizeof (*tw), ap);
rw = r->vars = alloc((tw - (const char **)t->vars + 1),
sizeof (*tw), ap);
for (tw = (const char **)t->vars; *tw != NULL; )
*rw++ = wdcopy(*tw++, ap);
*rw = NULL;
@@ -448,8 +448,8 @@ tcopy(struct op *t, PArea ap)
else {
for (tw = t->args; *tw++ != NULL; )
;
r->args = (const char **)(rw = (char **)alloc((tw -
t->args + 1) * sizeof (*tw), ap));
r->args = (const char **)(rw = alloc((tw - t->args + 1),
sizeof (*tw), ap));
for (tw = t->args; *tw != NULL; )
*rw++ = wdcopy(*tw++, ap);
*rw = NULL;
@@ -468,7 +468,7 @@ char *
wdcopy(const char *wp, PArea ap)
{
size_t len = wdscan(wp, EOS) - wp;
return memcpy(alloc(len, ap), wp, len);
return memcpy(alloc(1, len, ap), wp, len);
}
/* return the position of prefix c in wp plus 1 */
@@ -618,13 +618,13 @@ iocopy(struct ioword **iow, PArea ap)
for (ior = iow; *ior++ != NULL; )
;
ior = (struct ioword **)alloc((ior - iow + 1) * sizeof (*ior), ap);
ior = alloc((ior - iow + 1), sizeof (struct ioword *), ap);
for (i = 0; iow[i] != NULL; i++) {
struct ioword *p, *q;
p = iow[i];
q = (struct ioword *)alloc(sizeof (*p), ap);
q = alloc(1, sizeof (struct ioword), ap);
ior[i] = q;
*q = *p;
if (p->name != NULL)
@@ -651,12 +651,12 @@ tfree(struct op *t, PArea ap)
return;
if (t->str != NULL)
afree((void*)t->str, ap);
afree(t->str, ap);
if (t->vars != NULL) {
for (w = t->vars; *w != NULL; w++)
afree((void*)*w, ap);
afree((void*)t->vars, ap);
afree(*w, ap);
afree(t->vars, ap);
}
if (t->args != NULL) {
@@ -664,8 +664,8 @@ tfree(struct op *t, PArea ap)
/* XXX we assume the caller is right */
cw.ro = t->args;
for (w = cw.rw; *w != NULL; w++)
afree((void*)*w, ap);
afree((void*)t->args, ap);
afree(*w, ap);
afree(t->args, ap);
}
if (t->ioact != NULL)
@@ -674,7 +674,7 @@ tfree(struct op *t, PArea ap)
tfree(t->left, ap);
tfree(t->right, ap);
afree((void*)t, ap);
afree(t, ap);
}
static void
@@ -685,12 +685,12 @@ iofree(struct ioword **iow, PArea ap)
for (iop = iow; (p = *iop++) != NULL; ) {
if (p->name != NULL)
afree((void*)p->name, ap);
afree(p->name, ap);
if (p->delim != NULL)
afree((void*)p->delim, ap);
afree(p->delim, ap);
if (p->heredoc != NULL)
afree((void*)p->heredoc, ap);
afree((void*)p, ap);
afree(p->heredoc, ap);
afree(p, ap);
}
afree(iow, ap);
}