From 13da0e5ed3d3d4be6d1f9cc9d786ff4e0f2edd68 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 29 Aug 2021 07:29:09 -0700 Subject: seq_iter: fix gc issues. * lib.h (struct seq_iter_ops): New operation, mark. (seq_iter_ops_init): Default the mark operation to seq_iter_mark_op. (seq_iter_ops_init_nomark): New macro. * lib.c (seq_iter_mark_op): New static function. (si_range_cnum_ops, si_range_chr_ops, si_rev_range_cnum_ops, si_rev_range_chr_ops, si_chr_ops): Initialize with seq_iter_ops_init_nomark so that the iterator has no mark operation. All other iterator types have the above new static function as their mark op. (seq_iter_mark): Simplified: if the iterator has a mark op, call it. (seq_next, iter_step): If the iterator has a mark op, that means that the seq_get operation is likely replacing one heap object with another, and so mut(iter) must be called to inform the garbage collector of the assignment. --- lib.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib.h') diff --git a/lib.h b/lib.h index 3365183c..76ad19b2 100644 --- a/lib.h +++ b/lib.h @@ -421,9 +421,11 @@ typedef struct seq_iter { struct seq_iter_ops { int (*get)(struct seq_iter *, val *pval); int (*peek)(struct seq_iter *, val *pval); + void (*mark)(struct seq_iter *); }; -#define seq_iter_ops_init(get, peek) { get, peek } +#define seq_iter_ops_init(get, peek) { get, peek, seq_iter_mark_op } +#define seq_iter_ops_init_nomark(get, peek) { get, peek, 0 } extern const seq_kind_t seq_kind_tab[MAXTYPE+1]; -- cgit v1.2.3