summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2007-10-06 00:45:52 +0800
committerHerbert Xu <herbert@gondor.apana.org.au>2007-10-06 00:45:52 +0800
commit8e633ab936625fa1e897c5c062f70705996e7b85 (patch)
tree3e2bcf12e7584983749e6616123f8e36096b8e86 /src
parent[MEMALLOC] Made grabstackblock an inline wrapper for stalloc (diff)
downloaddash-8e633ab936625fa1e897c5c062f70705996e7b85.tar.gz
dash-8e633ab936625fa1e897c5c062f70705996e7b85.zip
[MEMALLOC] Add pushstackmark
This patch gets rid of the stack mark tracking hack by allocating a little
bit of stack memory if we're at risk of planting a stack mark which may be
grown later.  To do this a new function pushstackmark is added which lets
the user pick a bigger amount to allocate since some users do that anyway
after setting a stack mark.
Diffstat (limited to '')
-rw-r--r--src/expand.c6
-rw-r--r--src/memalloc.c26
-rw-r--r--src/memalloc.h2
-rw-r--r--src/parser.c3
4 files changed, 11 insertions, 26 deletions
diff --git a/src/expand.c b/src/expand.c
index 98ad718..e3e5d8f 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -546,10 +546,8 @@ expbackq(union node *cmd, int flag)
 	struct stackmark smark;
 
 	INTOFF;
-	setstackmark(&smark);
-	dest = expdest;
-	startloc = dest - (char *)stackblock();
-	grabstackstr(dest);
+	startloc = expdest - (char *)stackblock();
+	pushstackmark(&smark, startloc);
 	evalbackcmd(cmd, (struct backcmd *) &in);
 	popstackmark(&smark);
 
diff --git a/src/memalloc.c b/src/memalloc.c
index c8147d3..8d3e2ed 100644
--- a/src/memalloc.c
+++ b/src/memalloc.c
@@ -106,7 +106,6 @@ struct stack_block {
 
 struct stack_block stackbase;
 struct stack_block *stackp = &stackbase;
-struct stackmark *markp;
 char *stacknxt = stackbase.space;
 size_t stacknleft = MINSIZE;
 char *sstrend = stackbase.space + MINSIZE;
@@ -161,14 +160,17 @@ stunalloc(pointer p)
 
 
 
-void
-setstackmark(struct stackmark *mark)
+void pushstackmark(struct stackmark *mark, size_t len)
 {
 	mark->stackp = stackp;
 	mark->stacknxt = stacknxt;
 	mark->stacknleft = stacknleft;
-	mark->marknext = markp;
-	markp = mark;
+	grabstackblock(len);
+}
+
+void setstackmark(struct stackmark *mark)
+{
+	pushstackmark(mark, stacknxt == stackp->space && stackp != &stackbase);
 }
 
 
@@ -178,7 +180,6 @@ popstackmark(struct stackmark *mark)
 	struct stack_block *sp;
 
 	INTOFF;
-	markp = mark->marknext;
 	while (stackp != mark->stackp) {
 		sp = stackp;
 		stackp = sp->prev;
@@ -214,7 +215,6 @@ growstackblock(void)
 
 	if (stacknxt == stackp->space && stackp != &stackbase) {
 		struct stack_block *oldstackp;
-		struct stackmark *xmark;
 		struct stack_block *sp;
 		struct stack_block *prevstackp;
 		size_t grosslen;
@@ -230,18 +230,6 @@ growstackblock(void)
 		stacknxt = sp->space;
 		stacknleft = newlen;
 		sstrend = sp->space + newlen;
-
-		/*
-		 * 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 {
 		char *oldspace = stacknxt;
diff --git a/src/memalloc.h b/src/memalloc.h
index 282dbb0..ad6015d 100644
--- a/src/memalloc.h
+++ b/src/memalloc.h
@@ -40,7 +40,6 @@ struct stackmark {
 	struct stack_block *stackp;
 	char *stacknxt;
 	size_t stacknleft;
-	struct stackmark *marknext;
 };
 
 
@@ -54,6 +53,7 @@ pointer ckrealloc(pointer, size_t);
 char *savestr(const char *);
 pointer stalloc(size_t);
 void stunalloc(pointer);
+void pushstackmark(struct stackmark *mark, size_t len);
 void setstackmark(struct stackmark *);
 void popstackmark(struct stackmark *);
 void growstackblock(void);
diff --git a/src/parser.c b/src/parser.c
index f49ee7d..d0e0553 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -1487,8 +1487,7 @@ setprompt(int which)
 	show = !el;
 #endif
 	if (show) {
-		setstackmark(&smark);
-		stalloc(stackblocksize());
+		pushstackmark(&smark, stackblocksize());
 		out2str(getprompt(NULL));
 		popstackmark(&smark);
 	}