summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2011-11-24 22:43:52 -0800
committerKaz Kylheku <kaz@kylheku.com>2011-11-24 22:43:52 -0800
commite1841e6982a68ec90fc7c80901a98a66f21318b3 (patch)
tree6b87c3b3c8702c0e8dbb10c7dc6b14f2a997fc21
parentabdf06ed559fbc2f775271027f5000202bac9ff3 (diff)
downloadtxr-e1841e6982a68ec90fc7c80901a98a66f21318b3.tar.gz
txr-e1841e6982a68ec90fc7c80901a98a66f21318b3.tar.bz2
txr-e1841e6982a68ec90fc7c80901a98a66f21318b3.zip
* lib.c (getplist_f): New function.
* lib.h (getplist_f): Declared. * match.c (v_collect, h_coll): Use getplist_f to distinguish the case that :vars is explicitly specified as (). In this case, no bindings escape from the collect. * tests/008/soundex.txr: This test case broke due to using :vars () and yet counting on the variable to exist. * RELNOTES: Updated.
-rw-r--r--ChangeLog15
-rw-r--r--RELNOTES4
-rw-r--r--lib.c14
-rw-r--r--lib.h1
-rw-r--r--match.c5
-rw-r--r--tests/008/soundex.txr2
6 files changed, 38 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index d1a658c5..73ec56fd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
2011-11-24 Kaz Kylheku <kaz@kylheku.com>
+ * lib.c (getplist_f): New function.
+
+ * lib.h (getplist_f): Declared.
+
+ * match.c (v_collect, h_coll): Use getplist_f to distinguish
+ the case that :vars is explicitly specified as (). In this
+ case, no bindings escape from the collect.
+
+ * tests/008/soundex.txr: This test case broke due to using
+ :vars () and yet counting on the variable to exist.
+
+ * RELNOTES: Updated.
+
+2011-11-24 Kaz Kylheku <kaz@kylheku.com>
+
* match.c (match_funcall): Set source location info for
generated function call.
diff --git a/RELNOTES b/RELNOTES
index 810e8d0d..3058ee29 100644
--- a/RELNOTES
+++ b/RELNOTES
@@ -6,6 +6,10 @@
- Fixed regression in source location tracking (line numbers
shown in debugger and trace output).
+ - Fixed :vars () in collect/coll not working as intended.
+ This should prevent any bindings from being collected, and
+ allows iteration with collect without accumulating memory.
+
TXR 043
2011-11-23
diff --git a/lib.c b/lib.c
index 1076bb2c..440b258e 100644
--- a/lib.c
+++ b/lib.c
@@ -677,6 +677,20 @@ val getplist(val list, val key)
return nil;
}
+val getplist_f(val list, val key, val *found)
+{
+ for (; list; list = cdr(cdr(list))) {
+ val ind = first(list);
+ if (eq(ind, key)) {
+ *found = t;
+ return second(list);
+ }
+ }
+
+ *found = nil;
+ return nil;
+}
+
val proper_plist_to_alist(val list)
{
list_collect_decl (out, tail);
diff --git a/lib.h b/lib.h
index 4ad5e7a0..e6677a51 100644
--- a/lib.h
+++ b/lib.h
@@ -315,6 +315,7 @@ val listp(val obj);
val proper_listp(val obj);
val length(val list);
val getplist(val list, val key);
+val getplist_f(val list, val key, val *found);
val proper_plist_to_alist(val list);
val improper_plist_to_alist(val list, val boolean_keys);
val num(cnum val);
diff --git a/match.c b/match.c
index dce83a45..7f34efc9 100644
--- a/match.c
+++ b/match.c
@@ -2261,7 +2261,8 @@ static val v_collect(match_files_ctx *c)
val mintimes = getplist(args, mintimes_k);
val maxtimes = getplist(args, maxtimes_k);
val lines = getplist(args, lines_k);
- val vars = getplist(args, vars_k);
+ val have_vars;
+ val vars = getplist_f(args, vars_k, &have_vars);
cnum cmax = nump(gap) ? c_num(gap) : (nump(max) ? c_num(max) : 0);
cnum cmin = nump(gap) ? c_num(gap) : (nump(min) ? c_num(min) : 0);
cnum mincounter = cmin, maxcounter = 0;
@@ -2356,7 +2357,7 @@ static val v_collect(match_files_ctx *c)
val binding = car(iter);
val vars_binding = assoc(vars, car(binding));
- if (!vars || vars_binding) {
+ if (!have_vars || vars_binding) {
val existing = assoc(bindings_coll, car(binding));
bindings_coll = acons_new(bindings_coll, car(binding),
diff --git a/tests/008/soundex.txr b/tests/008/soundex.txr
index d01fb76d..b192bb62 100644
--- a/tests/008/soundex.txr
+++ b/tests/008/soundex.txr
@@ -56,7 +56,7 @@
@###
@# process arguments and list soundex codes
@###
-@(collect :vars ())
+@(collect :vars (input))
@input
@ (output :filter (:fun soundex))
@input