ref: d0e510b29af9a1d12a507f03f352b6d39adc0ace
parent: 7717051e3ce062fbdb8415e4befa5205d25e80bb
author: cinap_lenrek <[email protected]>
date: Sun May 15 15:58:24 EDT 2016
rc: remove pointless Memcpy(),Malloc(),Realloc() and efree() wrappers
--- a/sys/src/cmd/rc/code.c
+++ b/sys/src/cmd/rc/code.c
@@ -43,7 +43,7 @@
emiti(0); /* reference count */
outcode(t, flag['e']?1:0);
if(nerror){
- efree((char *)codebuf);
+ free(codebuf);
return 0;
}
readhere();
@@ -484,12 +484,12 @@
|| 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);
}
--- a/sys/src/cmd/rc/exec.c
+++ b/sys/src/cmd/rc/exec.c
@@ -68,8 +68,8 @@
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 @@
word *nw;
while(w){
nw = w->next;
- efree(w->word);
- efree((char *)w);
+ free(w->word);
+ free(w);
w = nw;
}
}
@@ -101,7 +101,7 @@
panic("poplist but no argv", 0);
freelist(p->words);
runq->argv = p->next;
- efree((char *)p);
+ free(p);
}
int
@@ -433,7 +433,7 @@
runq->redir = rp->next;
if(rp->type==ROPEN)
close(rp->from);
- efree((char *)rp);
+ free(rp);
}
void
@@ -444,7 +444,7 @@
while(p->argv) poplist();
codefree(p->code);
runq = p->ret;
- efree((char *)p);
+ free(p);
if(runq==0)
Exit(getstatus());
}
@@ -541,7 +541,7 @@
setstatus("");
break;
}
- efree(subject);
+ free(subject);
poplist();
poplist();
}
@@ -559,7 +559,7 @@
break;
}
}
- efree(s);
+ free(s);
if(ok)
runq->pc++;
else
@@ -576,8 +576,8 @@
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 @@
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 @@
{
word *nw;
while(w){
- efree(w->word);
+ free(w->word);
nw = w->next;
- efree((char *)w);
+ free(w);
w = nw;
}
}
@@ -911,7 +911,7 @@
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? */
}
--- a/sys/src/cmd/rc/fns.h
+++ b/sys/src/cmd/rc/fns.h
@@ -10,7 +10,6 @@
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);
--- a/sys/src/cmd/rc/glob.c
+++ b/sys/src/cmd/rc/glob.c
@@ -36,7 +36,7 @@
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 @@
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);
}
}
--- a/sys/src/cmd/rc/here.c
+++ b/sys/src/cmd/rc/here.c
@@ -81,7 +81,7 @@
closeio(f);
cleanhere(h->name);
nexth = h->next;
- efree((char *)h);
+ free(h);
}
here = 0;
doprompt = 1;
--- a/sys/src/cmd/rc/io.c
+++ b/sys/src/cmd/rc/io.c
@@ -230,7 +230,7 @@
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 @@
if(io->fd>=0)
close(io->fd);
if(io->strp)
- efree(io->strp);
- efree(io);
+ free(io->strp);
+ free(io);
}
int
--- a/sys/src/cmd/rc/plan9.c
+++ b/sys/src/cmd/rc/plan9.c
@@ -144,7 +144,7 @@
setvar(ent[i].name, val);
vlook(ent[i].name)->changed = 0;
close(f);
- efree(buf);
+ free(buf);
}
}
}
@@ -335,7 +335,7 @@
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 */
@@ -572,24 +572,6 @@
pfmt(err, "aborting\n");
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);
}
int *waitpids;
--- a/sys/src/cmd/rc/rc.h
+++ b/sys/src/cmd/rc/rc.h
@@ -97,12 +97,8 @@
#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> */
--- a/sys/src/cmd/rc/simple.c
+++ b/sys/src/cmd/rc/simple.c
@@ -235,8 +235,8 @@
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 @@
cmdline[len] = '\n';
poplist();
execcmds(opencore(cmdline, len+1));
- efree(cmdline);
+ free(cmdline);
}
union code dotcmds[14];
@@ -376,7 +376,7 @@
/* free caller's copy of $* */
av = p->argv;
p->argv = av->next;
- efree(av);
+ free(av);
/* push $0 value */
pushlist();
pushword(zero);
--- a/sys/src/cmd/rc/subr.c
+++ b/sys/src/cmd/rc/subr.c
@@ -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 @@
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 @@
n = strlen(s)+1;
d = emalloc(n);
- Memcpy(d, s, n);
+ memmove(d, s, n);
return d;
}
--- a/sys/src/cmd/rc/tree.c
+++ b/sys/src/cmd/rc/tree.c
@@ -27,8 +27,8 @@
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(p->child[1]);
freetree(p->child[2]);
if(p->str)
- efree(p->str);
- efree(p);
+ free(p->str);
+ free(p);
}
--- a/sys/src/cmd/rc/unix.c
+++ b/sys/src/cmd/rc/unix.c
@@ -277,8 +277,8 @@
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)
@@ -463,22 +463,4 @@
}
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);
}
--- a/sys/src/cmd/rc/win32.c
+++ b/sys/src/cmd/rc/win32.c
@@ -84,7 +84,7 @@
setvar(ent[i].name, val);
vlook(ent[i].name)->changed = 0;
close(f);
- efree(buf);
+ free(buf);
}
}
}
@@ -301,7 +301,7 @@
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 */
@@ -546,22 +546,4 @@
pfmt(err, "aborting\n");
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);
}