rc: remove pointless Memcpy(),Malloc(),Realloc() and efree() wrappers

This commit is contained in:
cinap_lenrek 2016-05-15 19:58:24 +02:00
parent 7717051e3c
commit d0e510b29a
13 changed files with 46 additions and 113 deletions

View file

@ -43,7 +43,7 @@ compile(tree *t)
emiti(0); /* reference count */
outcode(t, flag['e']?1:0);
if(nerror){
efree((char *)codebuf);
free(codebuf);
return 0;
}
readhere();
@ -484,12 +484,12 @@ codefree(code *cp)
|| p->f==Xsubshell || p->f==Xtrue) p++;
else if(p->f==Xdup || p->f==Xpipefd) p+=2;
else if(p->f==Xpipe) p+=4;
else if(p->f==Xglobs) efree(p[1].s), p+=2;
else if(p->f==Xword || p->f==Xdelhere) efree((++p)->s);
else if(p->f==Xglobs) free(p[1].s), p+=2;
else if(p->f==Xword || p->f==Xdelhere) free((++p)->s);
else if(p->f==Xfn){
efree(p[2].s);
free(p[2].s);
p+=2;
}
}
efree((char *)cp);
free(cp);
}

View file

@ -68,8 +68,8 @@ popword(void)
if(p==0)
panic("popword but no word!", 0);
runq->argv->words = p->next;
efree(p->word);
efree((char *)p);
free(p->word);
free(p);
}
void
@ -78,8 +78,8 @@ freelist(word *w)
word *nw;
while(w){
nw = w->next;
efree(w->word);
efree((char *)w);
free(w->word);
free(w);
w = nw;
}
}
@ -101,7 +101,7 @@ poplist(void)
panic("poplist but no argv", 0);
freelist(p->words);
runq->argv = p->next;
efree((char *)p);
free(p);
}
int
@ -433,7 +433,7 @@ Xpopredir(void)
runq->redir = rp->next;
if(rp->type==ROPEN)
close(rp->from);
efree((char *)rp);
free(rp);
}
void
@ -444,7 +444,7 @@ Xreturn(void)
while(p->argv) poplist();
codefree(p->code);
runq = p->ret;
efree((char *)p);
free(p);
if(runq==0)
Exit(getstatus());
}
@ -541,7 +541,7 @@ Xmatch(void)
setstatus("");
break;
}
efree(subject);
free(subject);
poplist();
poplist();
}
@ -559,7 +559,7 @@ Xcase(void)
break;
}
}
efree(s);
free(s);
if(ok)
runq->pc++;
else
@ -576,8 +576,8 @@ conclist(word *lp, word *rp, word *tail)
for(end = &v;;){
ln = strlen(lp->word), rn = strlen(rp->word);
p = Newword(emalloc(ln+rn+1), (word *)0);
Memcpy(p->word, lp->word, ln);
Memcpy(p->word+ln, rp->word, rn+1);
memmove(p->word, lp->word, ln);
memmove(p->word+ln, rp->word, rn+1);
if(lp->glob || rp->glob)
p->glob = Globsize(p->word);
*end = p, end = &p->next;
@ -811,9 +811,9 @@ Xunlocal(void)
runq->local = v->next;
hid = vlook(v->name);
hid->changed = 1;
efree(v->name);
free(v->name);
freewords(v->val);
efree((char *)v);
free(v);
}
void
@ -821,9 +821,9 @@ freewords(word *w)
{
word *nw;
while(w){
efree(w->word);
free(w->word);
nw = w->next;
efree((char *)w);
free(w);
w = nw;
}
}
@ -911,7 +911,7 @@ Xrdcmds(void)
if(yyparse()){
if(!p->iflag || p->eof && !Eintr()){
if(p->cmdfile)
efree(p->cmdfile);
free(p->cmdfile);
closeio(p->cmdfd);
Xreturn(); /* should this be omitted? */
}

View file

@ -10,7 +10,6 @@ void Exit(char*);
int ForkExecute(char*, char**, int, int, int);
int Globsize(char*);
int Isatty(int);
void Memcpy(void*, void*, long);
void Noerror(void);
int Opendir(char*);
long Read(int, void*, long);

View file

@ -36,7 +36,7 @@ globsort(word *left, word *right)
for(a = left,n = 0;a!=right;a = a->next,n++) list[n] = a->word;
qsort((void *)list, n, sizeof(void *), globcmp);
for(a = left,n = 0;a!=right;a = a->next,n++) a->word = list[n];
efree((char *)list);
free(list);
}
/*
@ -112,15 +112,15 @@ globword(word *w)
memset(name, 0, w->glob);
right = w->next;
left = globdir(right, w->word, name, name);
efree(name);
free(name);
if(left == right) {
deglob(w->word);
w->glob = 0;
} else {
efree(w->word);
free(w->word);
globsort(left, right);
*w = *left;
efree(left);
free(left);
}
}

View file

@ -81,7 +81,7 @@ readhere(void)
closeio(f);
cleanhere(h->name);
nexth = h->next;
efree((char *)h);
free(h);
}
here = 0;
doprompt = 1;

View file

@ -230,7 +230,7 @@ opencore(char *s, int len)
f->fd = -1 /*open("/dev/null", 0)*/;
f->bufp = f->strp = buf;
f->ebuf = buf+len;
Memcpy(buf, s, len);
memmove(buf, s, len);
return f;
}
@ -251,8 +251,8 @@ closeio(io *io)
if(io->fd>=0)
close(io->fd);
if(io->strp)
efree(io->strp);
efree(io);
free(io->strp);
free(io);
}
int

View file

@ -144,7 +144,7 @@ Vinit(void)
setvar(ent[i].name, val);
vlook(ent[i].name)->changed = 0;
close(f);
efree(buf);
free(buf);
}
}
}
@ -335,7 +335,7 @@ Execute(word *args, word *path)
rerrstr(file, sizeof file);
setstatus(file);
pfmt(err, "%s: %s\n", argv[1], file);
efree((char *)argv);
free(argv);
}
#define NDIR 256 /* shoud be a better way */
@ -574,24 +574,6 @@ Abort(void)
Exit("aborting");
}
void
Memcpy(void *a, void *b, long n)
{
memmove(a, b, n);
}
void*
Malloc(ulong n)
{
return malloc(n);
}
void*
Realloc(void *p, ulong n)
{
return realloc(p, n);
}
int *waitpids;
int nwaitpids;

View file

@ -97,12 +97,8 @@ var *gvar[NVAR]; /* hash for globals */
#define new(type) ((type *)emalloc(sizeof(type)))
void *Malloc(ulong);
void *Realloc(void *, ulong);
void *emalloc(long);
void *erealloc(void *, long);
void efree(void *);
char *estrdup(char*);
#define NOFILE 128 /* should come from <param.h> */

View file

@ -235,8 +235,8 @@ execshift(void)
star = vlook("*");
for(;star->val;--n){
a = star->val->next;
efree(star->val->word);
efree(star->val);
free(star->val->word);
free(star->val);
star->val = a;
star->changed = 1;
}
@ -295,7 +295,7 @@ execeval(void)
cmdline[len] = '\n';
poplist();
execcmds(opencore(cmdline, len+1));
efree(cmdline);
free(cmdline);
}
union code dotcmds[14];
@ -376,7 +376,7 @@ execdot(void)
/* free caller's copy of $* */
av = p->argv;
p->argv = av->next;
efree(av);
free(av);
/* push $0 value */
pushlist();
pushword(zero);

View file

@ -6,7 +6,7 @@
void *
emalloc(long n)
{
void *p = Malloc(n);
void *p = malloc(n);
if(p==0)
panic("Can't malloc %d bytes", n);
return p;
@ -15,20 +15,12 @@ emalloc(long n)
void*
erealloc(void *p, long n)
{
p = Realloc(p, n);
p = realloc(p, n);
if(p==0 && n!=0)
panic("Can't realloc %d bytes\n", n);
return p;
}
void
efree(void *p)
{
if(p)
free(p);
else pfmt(err, "free 0\n");
}
char*
estrdup(char *s)
{
@ -37,7 +29,7 @@ estrdup(char *s)
n = strlen(s)+1;
d = emalloc(n);
Memcpy(d, s, n);
memmove(d, s, n);
return d;
}

View file

@ -27,8 +27,8 @@ freenodes(void)
for(t = treenodes;t;t = u){
u = t->next;
if(t->str)
efree(t->str);
efree(t);
free(t->str);
free(t);
}
treenodes = 0;
}
@ -143,6 +143,6 @@ freetree(tree *p)
freetree(p->child[1]);
freetree(p->child[2]);
if(p->str)
efree(p->str);
efree(p);
free(p->str);
free(p);
}

View file

@ -277,8 +277,8 @@ register struct word *args, *path;
Bad:
setstatus(msg);
pfmt(err, "%s: %s\n", argv[1], msg);
efree(env);
efree(argv);
free(env);
free(argv);
}
#define NDIR 14 /* should get this from param.h */
Globsize(p)
@ -464,21 +464,3 @@ execumask(){ /* wrong -- should fork before writing */
setstatus("");
poplist();
}
Memcpy(a, b, n)
void *a, *b;
long n;
{
memmove(a, b, n);
}
void*
Malloc(n)
{
return (void *)malloc(n);
}
void*
Realloc(void *p, ulong n)
{
return realloc(p, n);
}

View file

@ -84,7 +84,7 @@ Vinit(void)
setvar(ent[i].name, val);
vlook(ent[i].name)->changed = 0;
close(f);
efree(buf);
free(buf);
}
}
}
@ -301,7 +301,7 @@ Execute(word *args, word *path)
rerrstr(file, sizeof file);
setstatus(file);
pfmt(err, "%s: %s\n", argv[1], file);
efree(argv);
free(argv);
}
#define NDIR 256 /* shoud be a better way */
@ -547,21 +547,3 @@ Abort(void)
flush(err);
Exit("aborting");
}
void
Memcpy(void *a, void *b, long n)
{
memmove(a, b, n);
}
void*
Malloc(ulong n)
{
return malloc(n);
}
void*
Realloc(void *p, ulong n)
{
return realloc(p, n);
}