mirror of https://github.com/tildeclub/ex-vi.git
malloc fixes
This commit is contained in:
parent
48c2d1ea7d
commit
687283420e
11
ex_re.c
11
ex_re.c
|
@ -73,7 +73,7 @@
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
#ifdef DOSCCS
|
#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
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -981,12 +981,8 @@ compile1(void)
|
||||||
cp = "Badly formed re|Missing closing delimiter "
|
cp = "Badly formed re|Missing closing delimiter "
|
||||||
"for regular expression";
|
"for regular expression";
|
||||||
break;
|
break;
|
||||||
case 41:
|
|
||||||
cp = "No remembered search string.";
|
|
||||||
break;
|
|
||||||
case 42:
|
case 42:
|
||||||
cp = "Unmatched \\( or \\)|More \\('s than \\)'s in "
|
cp = "\\( \\) Imbalance";
|
||||||
"regular expression or vice-versa";
|
|
||||||
break;
|
break;
|
||||||
case 43:
|
case 43:
|
||||||
cp = "Awash in \\('s!|Too many \\('d subexressions "
|
cp = "Awash in \\('s!|Too many \\('d subexressions "
|
||||||
|
@ -1005,7 +1001,8 @@ compile1(void)
|
||||||
cp = "Missing ]";
|
cp = "Missing ]";
|
||||||
break;
|
break;
|
||||||
case 67:
|
case 67:
|
||||||
cp = "Illegal byte sequence.";
|
cp = "Illegal byte sequence|Regular expression "
|
||||||
|
"has illegal byte sequence";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
cp = "Unknown regexp error code!!";
|
cp = "Unknown regexp error code!!";
|
||||||
|
|
17
malloc.c
17
malloc.c
|
@ -36,7 +36,7 @@
|
||||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* 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
|
#ifdef VMUNIX
|
||||||
|
@ -127,7 +127,7 @@ static int allock(void);
|
||||||
|
|
||||||
union store { union store *ptr;
|
union store { union store *ptr;
|
||||||
ALIGN dummy[NALIGN];
|
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*/
|
static union store allocs[2]; /*initial arena*/
|
||||||
|
@ -178,8 +178,11 @@ malloc(size_t nbytes)
|
||||||
for(temp=0; ; ) {
|
for(temp=0; ; ) {
|
||||||
if(!testbusy(p->ptr)) {
|
if(!testbusy(p->ptr)) {
|
||||||
while(!testbusy((q=p->ptr)->ptr)) {
|
while(!testbusy((q=p->ptr)->ptr)) {
|
||||||
|
int ua = p->ptr==allocp;
|
||||||
ASSERT(q>p&&q<alloct);
|
ASSERT(q>p&&q<alloct);
|
||||||
p->ptr = q->ptr;
|
p->ptr = q->ptr;
|
||||||
|
if (ua)
|
||||||
|
allocp = p->ptr;
|
||||||
}
|
}
|
||||||
if(q>=p+nw && p+nw>=p)
|
if(q>=p+nw && p+nw>=p)
|
||||||
goto found;
|
goto found;
|
||||||
|
@ -229,7 +232,7 @@ found:
|
||||||
void
|
void
|
||||||
free(register void *ap)
|
free(register void *ap)
|
||||||
{
|
{
|
||||||
register union store *p = (union store *)ap;
|
register union store *p = ap;
|
||||||
|
|
||||||
if (ap == NULL)
|
if (ap == NULL)
|
||||||
return;
|
return;
|
||||||
|
@ -263,11 +266,11 @@ realloc(void *ap, size_t nbytes)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if(testbusy(p[-1].ptr))
|
if(testbusy(p[-1].ptr))
|
||||||
free((char *)p);
|
free(p);
|
||||||
onw = p[-1].ptr - p;
|
onw = p[-1].ptr - p;
|
||||||
q = (union store *)malloc(nbytes);
|
q = malloc(nbytes);
|
||||||
if(q==NULL || q==p)
|
if(q==NULL || q==p)
|
||||||
return((char *)q);
|
return(q);
|
||||||
s = p;
|
s = p;
|
||||||
t = q;
|
t = q;
|
||||||
nw = (nbytes+WORD-1)/WORD;
|
nw = (nbytes+WORD-1)/WORD;
|
||||||
|
@ -277,7 +280,7 @@ realloc(void *ap, size_t nbytes)
|
||||||
*t++ = *s++;
|
*t++ = *s++;
|
||||||
if(q<p && q+nw>=p)
|
if(q<p && q+nw>=p)
|
||||||
(q+(q+nw-p))->ptr = allocx;
|
(q+(q+nw-p))->ptr = allocx;
|
||||||
return((char *)q);
|
return(q);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef debug
|
#ifdef debug
|
||||||
|
|
30
mapmalloc.c
30
mapmalloc.c
|
@ -36,7 +36,7 @@
|
||||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* 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
|
#ifdef VMUNIX
|
||||||
|
@ -87,6 +87,7 @@ botch(char *s)
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
static int allock(void *);
|
static int allock(void *);
|
||||||
|
#ifdef debugprint
|
||||||
void dump(const char *msg, uintptr_t t)
|
void dump(const char *msg, uintptr_t t)
|
||||||
{
|
{
|
||||||
const char hex[] = "0123456789ABCDEF";
|
const char hex[] = "0123456789ABCDEF";
|
||||||
|
@ -100,6 +101,9 @@ void dump(const char *msg, uintptr_t t)
|
||||||
write(2, "\n", 1);
|
write(2, "\n", 1);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
#define dump(a, b)
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
#define ASSERT(p)
|
#define ASSERT(p)
|
||||||
#define dump(a, b)
|
#define dump(a, b)
|
||||||
#endif
|
#endif
|
||||||
|
@ -151,7 +155,7 @@ static struct pool *pool0;
|
||||||
union store { union store *ptr;
|
union store { union store *ptr;
|
||||||
struct pool *pool;
|
struct pool *pool;
|
||||||
ALIGN dummy[NALIGN];
|
ALIGN dummy[NALIGN];
|
||||||
/*int calloc;*/ /*calloc clears an array of integers*/
|
INT callocsp; /*calloc clears an array of integers*/
|
||||||
};
|
};
|
||||||
|
|
||||||
struct pool {
|
struct pool {
|
||||||
|
@ -177,7 +181,7 @@ map(void *addr, size_t len)
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
static int fd = -1;
|
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))
|
fcntl(fd,F_SETFD,FD_CLOEXEC)<0))
|
||||||
return(MAP_FAILED);
|
return(MAP_FAILED);
|
||||||
#else /* MAP_ANON */
|
#else /* MAP_ANON */
|
||||||
|
@ -197,17 +201,17 @@ malloc(size_t nbytes)
|
||||||
struct pool *o;
|
struct pool *o;
|
||||||
register int nw;
|
register int nw;
|
||||||
static int temp; /*coroutines assume no auto*/
|
static int temp; /*coroutines assume no auto*/
|
||||||
static size_t poolblock = 32768;
|
static size_t poolblock = 0100000;
|
||||||
|
|
||||||
if (nbytes == 0)
|
if (nbytes == 0)
|
||||||
nbytes = 1;
|
nbytes = 1;
|
||||||
if(pool0==0||pool0==MAP_FAILED) { /*first time*/
|
if(pool0==0 || pool0==MAP_FAILED) { /*first time*/
|
||||||
if((pool0 = map(NULL, poolblock)) == MAP_FAILED) {
|
if((pool0=map(NULL, poolblock))==MAP_FAILED) {
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
pool0->Brk = (char *)pool0->Dummy;
|
pool0->Brk = (char *)pool0->Dummy;
|
||||||
pool0->End = (char *)pool0 + poolblock;
|
pool0->End = (char *)pool0+poolblock;
|
||||||
}
|
}
|
||||||
o = pool0;
|
o = pool0;
|
||||||
first: if(allocs[0].ptr==0) { /*first time for this pool*/
|
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; ; ) {
|
for(temp=0; ; ) {
|
||||||
if(!testbusy(p->ptr)) {
|
if(!testbusy(p->ptr)) {
|
||||||
while(!testbusy((q=p->ptr)->ptr)) {
|
while(!testbusy((q=p->ptr)->ptr)) {
|
||||||
|
int ua = p->ptr==allocp;
|
||||||
ASSERT(q>p&&q<alloct);
|
ASSERT(q>p&&q<alloct);
|
||||||
p->ptr = q->ptr;
|
p->ptr = q->ptr;
|
||||||
|
if (ua)
|
||||||
|
allocp = p->ptr;
|
||||||
}
|
}
|
||||||
if(q>=p+nw && p+nw>=p)
|
if(q>=p+nw && p+nw>=p)
|
||||||
goto found;
|
goto found;
|
||||||
|
@ -334,7 +341,7 @@ realloc(void *ap, size_t nbytes)
|
||||||
free(p);
|
free(p);
|
||||||
onw = p[-2].ptr - p;
|
onw = p[-2].ptr - p;
|
||||||
o = p[-1].pool;
|
o = p[-1].pool;
|
||||||
q = (union store *)malloc(nbytes);
|
q = malloc(nbytes);
|
||||||
if(q==NULL || q==p)
|
if(q==NULL || q==p)
|
||||||
return(q);
|
return(q);
|
||||||
s = p;
|
s = p;
|
||||||
|
@ -344,7 +351,7 @@ realloc(void *ap, size_t nbytes)
|
||||||
onw = nw;
|
onw = nw;
|
||||||
while(onw--!=0)
|
while(onw--!=0)
|
||||||
*t++ = *s++;
|
*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;
|
(q+(q+nw-p))->ptr = allocx;
|
||||||
return(q);
|
return(q);
|
||||||
}
|
}
|
||||||
|
@ -363,10 +370,9 @@ allock(void *ao)
|
||||||
x++;
|
x++;
|
||||||
}
|
}
|
||||||
ASSERT(p==alloct);
|
ASSERT(p==alloct);
|
||||||
return(x==1|p==allocp);
|
ASSERT(x==1|p==allocp);
|
||||||
#else
|
|
||||||
return(1);
|
|
||||||
#endif
|
#endif
|
||||||
|
return(1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue