- it is wrong to put inton/intoff arount ckmalloc(), because the code

around it is the one that does this.
- whitespace fixes.
This commit is contained in:
christos 2002-10-07 14:26:49 +00:00
parent 202746f803
commit 1ce87c4b29
1 changed files with 38 additions and 45 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: memalloc.c,v 1.24 2002/10/04 13:15:51 christos Exp $ */ /* $NetBSD: memalloc.c,v 1.25 2002/10/07 14:26:49 christos Exp $ */
/*- /*-
* Copyright (c) 1991, 1993 * Copyright (c) 1991, 1993
@ -41,7 +41,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)memalloc.c 8.3 (Berkeley) 5/4/95"; static char sccsid[] = "@(#)memalloc.c 8.3 (Berkeley) 5/4/95";
#else #else
__RCSID("$NetBSD: memalloc.c,v 1.24 2002/10/04 13:15:51 christos Exp $"); __RCSID("$NetBSD: memalloc.c,v 1.25 2002/10/07 14:26:49 christos Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
@ -65,9 +65,7 @@ ckmalloc(nbytes)
{ {
pointer p; pointer p;
INTOFF;
p = malloc(nbytes); p = malloc(nbytes);
INTON;
if (p == NULL) if (p == NULL)
error("Out of space"); error("Out of space");
return p; return p;
@ -83,8 +81,8 @@ ckrealloc(p, nbytes)
pointer p; pointer p;
int nbytes; int nbytes;
{ {
p = realloc(p, nbytes);
if ((p = realloc(p, nbytes)) == NULL) if (p == NULL)
error("Out of space"); error("Out of space");
return p; return p;
} }
@ -97,7 +95,7 @@ ckrealloc(p, nbytes)
char * char *
savestr(s) savestr(s)
char *s; char *s;
{ {
char *p; char *p;
p = ckmalloc(strlen(s) + 1); p = ckmalloc(strlen(s) + 1);
@ -117,7 +115,6 @@ savestr(s)
#define MINSIZE 504 /* minimum size of a block */ #define MINSIZE 504 /* minimum size of a block */
struct stack_block { struct stack_block {
struct stack_block *prev; struct stack_block *prev;
char space[MINSIZE]; char space[MINSIZE];
@ -131,8 +128,6 @@ int stacknleft = MINSIZE;
int sstrnleft; int sstrnleft;
int herefd = -1; int herefd = -1;
pointer pointer
stalloc(nbytes) stalloc(nbytes)
int nbytes; int nbytes;
@ -165,7 +160,7 @@ stalloc(nbytes)
void void
stunalloc(p) stunalloc(p)
pointer p; pointer p;
{ {
if (p == NULL) { /*DEBUG */ if (p == NULL) { /*DEBUG */
write(2, "stunalloc\n", 10); write(2, "stunalloc\n", 10);
abort(); abort();
@ -179,7 +174,7 @@ stunalloc(p)
void void
setstackmark(mark) setstackmark(mark)
struct stackmark *mark; struct stackmark *mark;
{ {
mark->stackp = stackp; mark->stackp = stackp;
mark->stacknxt = stacknxt; mark->stacknxt = stacknxt;
mark->stacknleft = stacknleft; mark->stacknleft = stacknleft;
@ -191,7 +186,7 @@ setstackmark(mark)
void void
popstackmark(mark) popstackmark(mark)
struct stackmark *mark; struct stackmark *mark;
{ {
struct stack_block *sp; struct stack_block *sp;
INTOFF; INTOFF;
@ -218,48 +213,49 @@ popstackmark(mark)
*/ */
void void
growstackblock() { growstackblock()
char *p; {
int newlen = SHELL_ALIGN(stacknleft * 2 + 100); int newlen = SHELL_ALIGN(stacknleft * 2 + 100);
char *oldspace = stacknxt;
int oldlen = stacknleft;
struct stack_block *sp;
struct stack_block *oldstackp;
if (stacknxt == stackp->space && stackp != &stackbase) { if (stacknxt == stackp->space && stackp != &stackbase) {
struct stack_block *oldstackp;
struct stackmark *xmark;
struct stack_block *sp;
INTOFF; INTOFF;
oldstackp = stackp; oldstackp = stackp;
sp = stackp; sp = stackp;
stackp = sp->prev; stackp = sp->prev;
sp = ckrealloc((pointer)sp, sizeof(struct stack_block) - MINSIZE + newlen); sp = ckrealloc((pointer)sp,
sizeof(struct stack_block) - MINSIZE + newlen);
sp->prev = stackp; sp->prev = stackp;
stackp = sp; stackp = sp;
stacknxt = sp->space; stacknxt = sp->space;
stacknleft = newlen; stacknleft = newlen;
{
/* Stack marks pointing to the start of the old block /*
* must be relocated to point to the new block * Stack marks pointing to the start of the old block
*/ * must be relocated to point to the new block
struct stackmark *xmark; */
xmark = markp; xmark = markp;
while (xmark != NULL && xmark->stackp == oldstackp) { while (xmark != NULL && xmark->stackp == oldstackp) {
xmark->stackp = stackp; xmark->stackp = stackp;
xmark->stacknxt = stacknxt; xmark->stacknxt = stacknxt;
xmark->stacknleft = stacknleft; xmark->stacknleft = stacknleft;
xmark = xmark->marknext; xmark = xmark->marknext;
}
} }
INTON; INTON;
} else { } else {
p = stalloc(newlen); char *oldspace = stacknxt;
memcpy(p, oldspace, oldlen); int oldlen = stacknleft;
char *p = stalloc(newlen);
(void)memcpy(p, oldspace, oldlen);
stacknxt = p; /* free the space */ stacknxt = p; /* free the space */
stacknleft += newlen; /* we just allocated */ stacknleft += newlen; /* we just allocated */
} }
} }
void void
grabstackblock(len) grabstackblock(len)
int len; int len;
@ -269,8 +265,6 @@ grabstackblock(len)
stacknleft -= len; stacknleft -= len;
} }
/* /*
* The following routines are somewhat easier to use that the above. * The following routines are somewhat easier to use that the above.
* The user declares a variable of type STACKSTR, which may be declared * The user declares a variable of type STACKSTR, which may be declared
@ -289,9 +283,9 @@ grabstackblock(len)
* is space for at least one character. * is space for at least one character.
*/ */
char * char *
growstackstr() { growstackstr()
{
int len = stackblocksize(); int len = stackblocksize();
if (herefd >= 0 && len >= 1024) { if (herefd >= 0 && len >= 1024) {
xwrite(herefd, stackblock(), len); xwrite(herefd, stackblock(), len);
@ -303,27 +297,26 @@ growstackstr() {
return stackblock() + len; return stackblock() + len;
} }
/* /*
* Called from CHECKSTRSPACE. * Called from CHECKSTRSPACE.
*/ */
char * char *
makestrspace() { makestrspace()
{
int len = stackblocksize() - sstrnleft; int len = stackblocksize() - sstrnleft;
growstackblock(); growstackblock();
sstrnleft = stackblocksize() - len; sstrnleft = stackblocksize() - len;
return stackblock() + len; return stackblock() + len;
} }
void void
ungrabstackstr(s, p) ungrabstackstr(s, p)
char *s; char *s;
char *p; char *p;
{ {
stacknleft += stacknxt - s; stacknleft += stacknxt - s;
stacknxt = s; stacknxt = s;
sstrnleft = stacknleft - (p - s); sstrnleft = stacknleft - (p - s);
} }