git: 9front

Download patch

ref: 332f070e5a51e5fcc1f2f17f15f67aa98a01b5f4
parent: 1a98f8ec9795764239130594bfbe61ac131922e3
author: stanley lieber <stanley.lieber@gmail.com>
date: Mon Apr 4 16:22:56 EDT 2011

erik's patches to lift 8192 byte word size restriction

--- a/sys/src/cmd/rc/havefork.c
+++ b/sys/src/cmd/rc/havefork.c
@@ -71,18 +71,26 @@
 	}
 }
 
-enum { Wordmax = 8192, };
+char*
+erealloc(char *p, long n)
+{
+	p = realloc(p, n);		/* botch, should be Realloc */
+	if(p==0)
+		panic("Can't realloc %d bytes\n", n);
+	return p;
+}
 
 /*
  * Who should wait for the exit from the fork?
  */
+enum { Stralloc = 100, };
+
 void
 Xbackq(void)
 {
-	int c, pid;
+	int c, l, pid;
 	int pfd[2];
-	char wd[Wordmax + 1];
-	char *s, *ewd = &wd[Wordmax], *stop;
+	char *s, *wd, *ewd, *stop;
 	struct io *f;
 	var *ifs = vlook("ifs");
 	word *v, *nextv;
@@ -108,18 +116,16 @@
 		addwaitpid(pid);
 		close(pfd[PWR]);
 		f = openfd(pfd[PRD]);
-		s = wd;
+		s = wd = ewd = 0;
 		v = 0;
-		/*
-		 * this isn't quite right for utf.  stop could have utf
-		 * in it, and we're processing the input as bytes, not
-		 * utf encodings of runes.  further, if we run out of
-		 * room in wd, we can chop in the middle of a utf encoding
-		 * (not to mention stepping on one of the bytes).
-		 * presotto's Strings seem like the right data structure here.
-		 */
 		while((c = rchr(f))!=EOF){
-			if(strchr(stop, c) || s==ewd){
+			if(s==ewd){
+				l = s-wd;
+				wd = erealloc(wd, l+Stralloc);
+				ewd = wd+l+Stralloc-1;
+				s = wd+l;
+			}
+			if(strchr(stop, c)){
 				if(s!=wd){
 					*s='\0';
 					v = newword(wd, v);
@@ -132,6 +138,8 @@
 			*s='\0';
 			v = newword(wd, v);
 		}
+		if(wd)
+			efree(wd);
 		closeio(f);
 		Waitfor(pid, 0);
 		/* v points to reversed arglist -- reverse it onto argv */
@@ -231,4 +239,4 @@
 	}
 	addwaitpid(pid);
 	return pid;
-}
+}
\ No newline at end of file
--- a/sys/src/cmd/rc/haventfork.c
+++ b/sys/src/cmd/rc/haventfork.c
@@ -51,12 +51,23 @@
 	setvar("apid", newword(buf, (word *)0));
 }
 
+char*
+erealloc(char *p, long n)
+{
+	p = realloc(p, n);		/* botch, should be Realloc */
+	if(p==0)
+		panic("Can't realloc %d bytes\n", n);
+	return p;
+}
+
+enum { Stralloc = 100, };
+
 void
 Xbackq(void)
 {
-	char wd[8193], **argv;
-	int c;
-	char *s, *ewd=&wd[8192], *stop;
+	char **argv;
+	int c, l;
+	char *s, *wd, *ewd, *stop;
 	struct io *f;
 	var *ifs = vlook("ifs");
 	word *v, *nextv;
@@ -84,14 +95,20 @@
 	}
 
 	f = openfd(pfd[0]);
-	s = wd;
+		s = wd = ewd = 0;
 	v = 0;
 	while((c=rchr(f))!=EOF){
-		if(strchr(stop, c) || s==ewd){
+		if(s==ewd){
+			l = s-wd;
+			wd = erealloc(wd, l+Stralloc);
+			ewd = wd+l+Stralloc-1;
+			s = wd+l;
+		}
+		if(strchr(stop, c)){
 			if(s!=wd){
 				*s='\0';
-				v=newword(wd, v);
-				s=wd;
+				v = newword(wd, v);
+				s = wd;
 			}
 		}
 		else *s++=c;
@@ -100,6 +117,8 @@
 		*s='\0';
 		v=newword(wd, v);
 	}
+	if(wd)
+		efree(wd);
 	closeio(f);
 	Waitfor(pid, 1);
 	/* v points to reversed arglist -- reverse it onto argv */
@@ -208,4 +227,4 @@
 	}
 	free(argv);
 	return -1;
-}
+}
\ No newline at end of file
--