* back out almost all of the memory allocator related changes, as aalloc

was hard to type and hard to fix, galloc is also hard to fix, and some
  things I learned will probably improve things more but make me use the
  original form as base (especially for space savings)
* let sizeofN die though, remove even more casts
* optimise, polish
* regen Makefiles
* sprinkle a few /* CONSTCOND */ while here
This commit is contained in:
tg
2008-12-13 17:02:18 +00:00
parent 732e10c982
commit 31d1499219
19 changed files with 194 additions and 215 deletions

14
shf.c
View File

@@ -2,7 +2,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.23 2008/11/12 00:54:51 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.24 2008/12/13 17:02:17 tg Exp $");
/* flags to shf_emptybuf() */
#define EB_READSW 0x01 /* about to switch to reading */
@@ -29,7 +29,7 @@ shf_open(const char *name, int oflags, int mode, int sflags)
int fd;
/* Done before open so if alloca fails, fd won't be lost. */
shf = alloc(1, sizeof (struct shf) + bsize, ATEMP);
shf = alloc(sizeof (struct shf) + bsize, ATEMP);
shf->areap = ATEMP;
shf->buf = (unsigned char *)&shf[1];
shf->bsize = bsize;
@@ -92,12 +92,12 @@ shf_fdopen(int fd, int sflags, struct shf *shf)
if (shf) {
if (bsize) {
shf->buf = alloc(1, bsize, ATEMP);
shf->buf = alloc(bsize, ATEMP);
sflags |= SHF_ALLOCB;
} else
shf->buf = NULL;
} else {
shf = alloc(1, sizeof (struct shf) + bsize, ATEMP);
shf = alloc(sizeof (struct shf) + bsize, ATEMP);
shf->buf = (unsigned char *)&shf[1];
sflags |= SHF_ALLOCS;
}
@@ -180,7 +180,7 @@ shf_sopen(char *buf, int bsize, int sflags, struct shf *shf)
internal_errorf("shf_sopen: flags 0x%x", sflags);
if (!shf) {
shf = alloc(1, sizeof (struct shf), ATEMP);
shf = alloc(sizeof (struct shf), ATEMP);
sflags |= SHF_ALLOCS;
}
shf->areap = ATEMP;
@@ -188,7 +188,7 @@ shf_sopen(char *buf, int bsize, int sflags, struct shf *shf)
if (bsize <= 0)
bsize = 64;
sflags |= SHF_ALLOCB;
buf = alloc(1, bsize, shf->areap);
buf = alloc(bsize, shf->areap);
}
shf->fd = -1;
shf->buf = shf->rp = shf->wp = (unsigned char *)buf;
@@ -323,7 +323,7 @@ shf_emptybuf(struct shf *shf, int flags)
!(shf->flags & SHF_ALLOCB))
return EOF;
/* allocate more space for buffer */
nbuf = aresize(shf->buf, 2, shf->wbsize, shf->areap);
nbuf = aresize(shf->buf, 2 * shf->wbsize, shf->areap);
shf->rp = nbuf + (shf->rp - shf->buf);
shf->wp = nbuf + (shf->wp - shf->buf);
shf->rbsize += shf->wbsize;