shithub: femtolisp

Download patch

ref: 3293630c84681d130a7d102e0c12331f69e89d70
parent: a0707331b8b358023e63c3123e3abe49de450dc4
author: Jeff Bezanson <jeff.bezanson@gmail.com>
date: Mon Jun 10 15:12:53 EDT 2013

fix argument handling bug in fl_map1
need to pop after _applyn; functions might rewrite the stack to
contain non-values.

--- a/flisp.c
+++ b/flisp.c
@@ -2185,6 +2185,7 @@
             Stack[argSP+i] = cdr_(Stack[argSP+i]);
         }
         v = _applyn(nargs-1);
+        POPN(nargs);
         PUSH(v);
         v = mk_cons();
         car_(v) = POP(); cdr_(v) = NIL;
@@ -2192,12 +2193,13 @@
         fl_gc_handle(&first);
         fl_gc_handle(&last);
         while (iscons(Stack[argSP+1])) {
-            Stack[SP-nargs] = Stack[argSP];
+            PUSH(Stack[argSP]);
             for(i=1; i < nargs; i++) {
-                Stack[SP-nargs+i] = car(Stack[argSP+i]);
+                PUSH(car(Stack[argSP+i]));
                 Stack[argSP+i] = cdr_(Stack[argSP+i]);
             }
             v = _applyn(nargs-1);
+            POPN(nargs);
             PUSH(v);
             v = mk_cons();
             car_(v) = POP(); cdr_(v) = NIL;
@@ -2204,7 +2206,6 @@
             cdr_(last) = v;
             last = v;
         }
-        POPN(nargs);
         fl_free_gc_handles(2);
     }
     return first;