From 114a9ee6f3e1c4670254a4e5fadd7f6f10e87b8f Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 20 Dec 2021 19:32:36 -0800 Subject: maprodo: bugfix: spurious return value. There are cases when maprodo returns a non-nil value, even though it is supposed to collect nothing. This is because though it is is collecting nothing, that nothing is sometimes converted to an alternative return type via make_like. * eval.c (prod_common): We allow the collect_fn function pointer to be null, to indicate nothing is to be collected, rather than using a stub. If collect_fn is null, we just call the mapping function without collecting its value, and at the end, we do not involve make_like and just return nil. (collect_nothing): Static function removed. (maprodo): Pass null function pointer instead of collect_nothing. --- eval.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/eval.c b/eval.c index 066a8f2a..817d6627 100644 --- a/eval.c +++ b/eval.c @@ -5725,6 +5725,7 @@ static val prod_common(val self, val fun, struct args *lists, goto out; for (;;) { + val ret; for (i = 0; i < argc; i++) args_fun->arg[i] = iter_item(args_work->arg[i]); @@ -5732,7 +5733,10 @@ static val prod_common(val self, val fun, struct args *lists, args_fun->fill = argc; args_fun->list = 0; - ptail = collect_fn(ptail, generic_funcall(fun, args_fun)); + ret = generic_funcall(fun, args_fun); + + if (collect_fn) + ptail = collect_fn(ptail, ret); for (i = argc - 1; ; i--) { val step_i = iter_step(args_work->arg[i]); @@ -5746,7 +5750,7 @@ static val prod_common(val self, val fun, struct args *lists, } } out: - return make_like(out, args_at(lists, 0)); + return collect_fn ? make_like(out, args_at(lists, 0)) : nil; } } @@ -5760,15 +5764,9 @@ val maprendv(val fun, struct args *lists) return prod_common(lit("maprend"), fun, lists, list_collect_append, mappendv); } -static loc collect_nothing(loc ptail, val obj) -{ - (void) obj; - return ptail; -} - static val maprodo(val fun, struct args *lists) { - return prod_common(lit("maprodo"), fun, lists, collect_nothing, mapdov); + return prod_common(lit("maprodo"), fun, lists, 0, mapdov); } static val symbol_value(val sym) -- cgit v1.2.3