shithub: riscv

Download patch

ref: 78aa56ab320d75624bd19d079c32b58108357a90
parent: 548f7f971f5938c1b54481e0542d5b19e0fe37de
author: Ori Bernstein <ori@eigenstate.org>
date: Wed Aug 9 14:44:24 EDT 2023

bar, fontsel: use heap allocated biobuf

with libthread, we want to avoid using a lot of stack,
and biobuf uses a lot of stack. Bfdopen puts the biobuf
on the stack.

--- a/sys/src/cmd/bar.c
+++ b/sys/src/cmd/bar.c
@@ -196,18 +196,18 @@
 static void
 auxproc(void *c)
 {
-	Biobuf b;
+	Biobuf *b;
 	char *s;
 
 	threadsetname("aux");
-	Binit(&b, 0, OREAD);
+	b = Bfdopen(0, OREAD);
 	for(;;){
-		s = Brdstr(&b, '\n', 1);
+		s = Brdstr(b, '\n', 1);
 		if(s == nil)
 			break;
 		sendp(c, s);
 	}
-	Bterm(&b);
+	Bterm(b);
 
 	threadexits(nil);
 }
--- a/sys/src/cmd/fontsel.c
+++ b/sys/src/cmd/fontsel.c
@@ -238,21 +238,22 @@
 static void
 loadtext(int f)
 {
-	Biobuf b;
+	Biobuf *b;
 	int i;
 
-	if(f < 0 || Binit(&b, f, OREAD) != 0)
+	if(f < 0)
 		sysfatal("loadtext: %r");
-
+	if((b = Bfdopen(f, OREAD)) == nil)
+		sysfatal("loadtext: %r");
 	text = nil;
 	for(i = 0; i < 256; i++){
 		if((text = realloc(text, (i+1)*sizeof(char*))) == nil)
 			sysfatal("memory");
-		if((text[i] = Brdstr(&b, '\n', 1)) == nil)
+		if((text[i] = Brdstr(b, '\n', 1)) == nil)
 			break;
 	}
 
-	close(f);
+	Bterm(b);
 }
 
 void