shithub: femtolisp

Download patch

ref: 561e0b07e1d030695805b830be90db0838821758
parent: 8ea6157c157a1dedde97c50412f0d1a0105db269
author: JeffBezanson <jeff.bezanson@gmail.com>
date: Tue Jul 6 19:13:54 EDT 2010

fixing subtle bug where heapsize was set wrong at some points



--- a/femtolisp/flisp.c
+++ b/femtolisp/flisp.c
@@ -529,7 +529,10 @@
     fl_readstate_t *rs;
 
     curheap = tospace;
-    lim = curheap+heapsize-sizeof(cons_t);
+    if (grew)
+        lim = curheap+heapsize*2-sizeof(cons_t);
+    else
+        lim = curheap+heapsize-sizeof(cons_t);
 
     if (fl_throwing_frame > curr_frame) {
         top = fl_throwing_frame - 4;
@@ -584,14 +587,12 @@
     // more space to fill next time. if we grew tospace last time,
     // grow the other half of the heap this time to catch up.
     if (grew || ((lim-curheap) < (int)(heapsize/5)) || mustgrow) {
-        temp = LLT_REALLOC(tospace, grew ? heapsize : heapsize*2);
+        temp = LLT_REALLOC(tospace, heapsize*2);
         if (temp == NULL)
             fl_raise(memory_exception_value);
         tospace = temp;
-        if (!grew) {
+        if (grew) {
             heapsize*=2;
-        }
-        else {
             temp = bitvector_resize(consflags, heapsize/sizeof(cons_t), 1);
             if (temp == NULL)
                 fl_raise(memory_exception_value);