malloc fixes

This commit is contained in:
Gunnar Ritter 2005-02-20 22:20:58 +00:00
parent 48c2d1ea7d
commit 687283420e
3 changed files with 32 additions and 26 deletions

11
ex_re.c
View File

@ -73,7 +73,7 @@
#ifndef lint
#ifdef DOSCCS
static char sccsid[] = "@(#)ex_re.c 1.54 (gritter) 2/20/05";
static char sccsid[] = "@(#)ex_re.c 1.55 (gritter) 2/20/05";
#endif
#endif
@ -981,12 +981,8 @@ compile1(void)
cp = "Badly formed re|Missing closing delimiter "
"for regular expression";
break;
case 41:
cp = "No remembered search string.";
break;
case 42:
cp = "Unmatched \\( or \\)|More \\('s than \\)'s in "
"regular expression or vice-versa";
cp = "\\( \\) Imbalance";
break;
case 43:
cp = "Awash in \\('s!|Too many \\('d subexressions "
@ -1005,7 +1001,8 @@ compile1(void)
cp = "Missing ]";
break;
case 67:
cp = "Illegal byte sequence.";
cp = "Illegal byte sequence|Regular expression "
"has illegal byte sequence";
break;
default:
cp = "Unknown regexp error code!!";

View File

@ -36,7 +36,7 @@
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @(#)malloc.c 1.18 (gritter) 2/18/05
* @(#)malloc.c 1.19 (gritter) 2/20/05
*/
#ifdef VMUNIX
@ -127,7 +127,7 @@ static int allock(void);
union store { union store *ptr;
ALIGN dummy[NALIGN];
/*int calloc;*/ /*calloc clears an array of integers*/
INT callocsp; /*calloc clears an array of integers*/
};
static union store allocs[2]; /*initial arena*/
@ -178,8 +178,11 @@ malloc(size_t nbytes)
for(temp=0; ; ) {
if(!testbusy(p->ptr)) {
while(!testbusy((q=p->ptr)->ptr)) {
int ua = p->ptr==allocp;
ASSERT(q>p&&q<alloct);
p->ptr = q->ptr;
if (ua)
allocp = p->ptr;
}
if(q>=p+nw && p+nw>=p)
goto found;
@ -229,7 +232,7 @@ found:
void
free(register void *ap)
{
register union store *p = (union store *)ap;
register union store *p = ap;
if (ap == NULL)
return;
@ -263,11 +266,11 @@ realloc(void *ap, size_t nbytes)
return NULL;
}
if(testbusy(p[-1].ptr))
free((char *)p);
free(p);
onw = p[-1].ptr - p;
q = (union store *)malloc(nbytes);
q = malloc(nbytes);
if(q==NULL || q==p)
return((char *)q);
return(q);
s = p;
t = q;
nw = (nbytes+WORD-1)/WORD;
@ -277,7 +280,7 @@ realloc(void *ap, size_t nbytes)
*t++ = *s++;
if(q<p && q+nw>=p)
(q+(q+nw-p))->ptr = allocx;
return((char *)q);
return(q);
}
#ifdef debug

View File

@ -36,7 +36,7 @@
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Sccsid @(#)mapmalloc.c 1.3 (gritter) 2/20/05
* Sccsid @(#)mapmalloc.c 1.4 (gritter) 2/20/05
*/
#ifdef VMUNIX
@ -87,6 +87,7 @@ botch(char *s)
abort();
}
static int allock(void *);
#ifdef debugprint
void dump(const char *msg, uintptr_t t)
{
const char hex[] = "0123456789ABCDEF";
@ -100,6 +101,9 @@ void dump(const char *msg, uintptr_t t)
write(2, "\n", 1);
}
#else
#define dump(a, b)
#endif
#else
#define ASSERT(p)
#define dump(a, b)
#endif
@ -151,7 +155,7 @@ static struct pool *pool0;
union store { union store *ptr;
struct pool *pool;
ALIGN dummy[NALIGN];
/*int calloc;*/ /*calloc clears an array of integers*/
INT callocsp; /*calloc clears an array of integers*/
};
struct pool {
@ -177,7 +181,7 @@ map(void *addr, size_t len)
int flags = 0;
static int fd = -1;
if (fd==-1&&((fd=open("/dev/zero",O_RDWR))<0||
if (fd==-1 && ((fd=open("/dev/zero",O_RDWR))<0 ||
fcntl(fd,F_SETFD,FD_CLOEXEC)<0))
return(MAP_FAILED);
#else /* MAP_ANON */
@ -197,17 +201,17 @@ malloc(size_t nbytes)
struct pool *o;
register int nw;
static int temp; /*coroutines assume no auto*/
static size_t poolblock = 32768;
static size_t poolblock = 0100000;
if (nbytes == 0)
nbytes = 1;
if(pool0==0||pool0==MAP_FAILED) { /*first time*/
if((pool0 = map(NULL, poolblock)) == MAP_FAILED) {
if(pool0==0 || pool0==MAP_FAILED) { /*first time*/
if((pool0=map(NULL, poolblock))==MAP_FAILED) {
errno = ENOMEM;
return(NULL);
}
pool0->Brk = (char *)pool0->Dummy;
pool0->End = (char *)pool0 + poolblock;
pool0->End = (char *)pool0+poolblock;
}
o = pool0;
first: if(allocs[0].ptr==0) { /*first time for this pool*/
@ -223,8 +227,11 @@ first: if(allocs[0].ptr==0) { /*first time for this pool*/
for(temp=0; ; ) {
if(!testbusy(p->ptr)) {
while(!testbusy((q=p->ptr)->ptr)) {
int ua = p->ptr==allocp;
ASSERT(q>p&&q<alloct);
p->ptr = q->ptr;
if (ua)
allocp = p->ptr;
}
if(q>=p+nw && p+nw>=p)
goto found;
@ -334,7 +341,7 @@ realloc(void *ap, size_t nbytes)
free(p);
onw = p[-2].ptr - p;
o = p[-1].pool;
q = (union store *)malloc(nbytes);
q = malloc(nbytes);
if(q==NULL || q==p)
return(q);
s = p;
@ -344,7 +351,7 @@ realloc(void *ap, size_t nbytes)
onw = nw;
while(onw--!=0)
*t++ = *s++;
if(q<p && q+nw>=p)
if(q<p && q+nw>=p && p[-1].pool==q[-1].pool)
(q+(q+nw-p))->ptr = allocx;
return(q);
}
@ -363,10 +370,9 @@ allock(void *ao)
x++;
}
ASSERT(p==alloct);
return(x==1|p==allocp);
#else
return(1);
ASSERT(x==1|p==allocp);
#endif
return(1);
}
#endif