Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/sh - it is wrong to put inton/intoff arount ckmalloc(), ...
details: https://anonhg.NetBSD.org/src/rev/5a6ebbb9ad63
branches: trunk
changeset: 537887:5a6ebbb9ad63
user: christos <christos%NetBSD.org@localhost>
date: Mon Oct 07 14:26:49 2002 +0000
description:
- it is wrong to put inton/intoff arount ckmalloc(), because the code
around it is the one that does this.
- whitespace fixes.
diffstat:
bin/sh/memalloc.c | 83 +++++++++++++++++++++++++-----------------------------
1 files changed, 38 insertions(+), 45 deletions(-)
diffs (218 lines):
diff -r ed65901c56f0 -r 5a6ebbb9ad63 bin/sh/memalloc.c
--- a/bin/sh/memalloc.c Mon Oct 07 14:26:08 2002 +0000
+++ b/bin/sh/memalloc.c Mon Oct 07 14:26:49 2002 +0000
@@ -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
@@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)memalloc.c 8.3 (Berkeley) 5/4/95";
#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 /* not lint */
@@ -65,9 +65,7 @@
{
pointer p;
- INTOFF;
p = malloc(nbytes);
- INTON;
if (p == NULL)
error("Out of space");
return p;
@@ -83,8 +81,8 @@
pointer p;
int nbytes;
{
-
- if ((p = realloc(p, nbytes)) == NULL)
+ p = realloc(p, nbytes);
+ if (p == NULL)
error("Out of space");
return p;
}
@@ -97,7 +95,7 @@
char *
savestr(s)
char *s;
- {
+{
char *p;
p = ckmalloc(strlen(s) + 1);
@@ -117,7 +115,6 @@
#define MINSIZE 504 /* minimum size of a block */
-
struct stack_block {
struct stack_block *prev;
char space[MINSIZE];
@@ -131,8 +128,6 @@
int sstrnleft;
int herefd = -1;
-
-
pointer
stalloc(nbytes)
int nbytes;
@@ -165,7 +160,7 @@
void
stunalloc(p)
pointer p;
- {
+{
if (p == NULL) { /*DEBUG */
write(2, "stunalloc\n", 10);
abort();
@@ -179,7 +174,7 @@
void
setstackmark(mark)
struct stackmark *mark;
- {
+{
mark->stackp = stackp;
mark->stacknxt = stacknxt;
mark->stacknleft = stacknleft;
@@ -191,7 +186,7 @@
void
popstackmark(mark)
struct stackmark *mark;
- {
+{
struct stack_block *sp;
INTOFF;
@@ -218,48 +213,49 @@
*/
void
-growstackblock() {
- char *p;
+growstackblock()
+{
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) {
+ struct stack_block *oldstackp;
+ struct stackmark *xmark;
+ struct stack_block *sp;
+
INTOFF;
oldstackp = stackp;
sp = stackp;
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;
stackp = sp;
stacknxt = sp->space;
stacknleft = newlen;
- {
- /* Stack marks pointing to the start of the old block
- * must be relocated to point to the new block
- */
- struct stackmark *xmark;
- xmark = markp;
- while (xmark != NULL && xmark->stackp == oldstackp) {
- xmark->stackp = stackp;
- xmark->stacknxt = stacknxt;
- xmark->stacknleft = stacknleft;
- xmark = xmark->marknext;
- }
+
+ /*
+ * Stack marks pointing to the start of the old block
+ * must be relocated to point to the new block
+ */
+ xmark = markp;
+ while (xmark != NULL && xmark->stackp == oldstackp) {
+ xmark->stackp = stackp;
+ xmark->stacknxt = stacknxt;
+ xmark->stacknleft = stacknleft;
+ xmark = xmark->marknext;
}
INTON;
} else {
- p = stalloc(newlen);
- memcpy(p, oldspace, oldlen);
+ char *oldspace = stacknxt;
+ int oldlen = stacknleft;
+ char *p = stalloc(newlen);
+
+ (void)memcpy(p, oldspace, oldlen);
stacknxt = p; /* free the space */
stacknleft += newlen; /* we just allocated */
}
}
-
-
void
grabstackblock(len)
int len;
@@ -269,8 +265,6 @@
stacknleft -= len;
}
-
-
/*
* The following routines are somewhat easier to use that the above.
* The user declares a variable of type STACKSTR, which may be declared
@@ -289,9 +283,9 @@
* is space for at least one character.
*/
-
char *
-growstackstr() {
+growstackstr()
+{
int len = stackblocksize();
if (herefd >= 0 && len >= 1024) {
xwrite(herefd, stackblock(), len);
@@ -303,27 +297,26 @@
return stackblock() + len;
}
-
/*
* Called from CHECKSTRSPACE.
*/
char *
-makestrspace() {
+makestrspace()
+{
int len = stackblocksize() - sstrnleft;
growstackblock();
sstrnleft = stackblocksize() - len;
return stackblock() + len;
}
-
-
void
ungrabstackstr(s, p)
char *s;
char *p;
- {
+{
stacknleft += stacknxt - s;
stacknxt = s;
sstrnleft = stacknleft - (p - s);
+
}
Home |
Main Index |
Thread Index |
Old Index