shithub: femtolisp

Download patch

ref: ea8a8d710c4f29b31a9222f64b75184122ed335d
parent: e732a668e856a6eebd755eddbbc37f6b822f3217
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Mon Nov 11 15:06:14 EST 2024

vector_grow: import partial change by Jeff Bezanson from Julia

This is from f105aa40efb5e200b316ec72446c787a2f94faa9.

--- a/read.c
+++ b/read.c
@@ -450,7 +450,7 @@
 // NOTE: this is NOT an efficient operation. it is only used by the
 // reader, and requires at least 1 and up to 3 garbage collections!
 static value_t
-vector_grow(value_t v)
+vector_grow(value_t v, bool rewrite_refs)
 {
 	size_t i, s = vector_size(v);
 	size_t d = vector_grow_amt(s);
@@ -462,7 +462,7 @@
 		vector_elt(newv, i) = vector_elt(v, i);
 	// use gc to rewrite references from the old vector to the new
 	FL(stack)[FL(sp)-1] = newv;
-	if(s > 0){
+	if(s > 0 && rewrite_refs){
 		((size_t*)ptr(v))[0] |= 0x1;
 		vector_elt(v, 0) = newv;
 		gc(0);
@@ -482,7 +482,7 @@
 		if(ios_eof(RS))
 			parse_error("unexpected end of input");
 		if(i >= vector_size(v)){
-			v = FL(stack)[FL(sp)-1] = vector_grow(v);
+			v = FL(stack)[FL(sp)-1] = vector_grow(v, label != UNBOUND);
 			if(label != UNBOUND)
 				ptrhash_put(&FL(readstate)->backrefs, (void*)label, (void*)v);
 		}