From 2eef9d5a5d6192d11171c0ae85d48d383d5b391e Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Mon, 10 Jun 2013 19:12:53 -0400 Subject: [PATCH] fix argument handling bug in fl_map1 need to pop after _applyn; functions might rewrite the stack to contain non-values. --- flisp.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/flisp.c b/flisp.c index ca2a2b7..693bfe6 100644 --- a/flisp.c +++ b/flisp.c @@ -2185,6 +2185,7 @@ value_t fl_map1(value_t *args, u_int32_t nargs) 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,19 +2193,19 @@ value_t fl_map1(value_t *args, u_int32_t nargs) 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; cdr_(last) = v; last = v; } - POPN(nargs); fl_free_gc_handles(2); } return first;