From 22b349294b923990eba299bcf17aa6b1543df700 Mon Sep 17 00:00:00 2001 From: Matt Valentine-House Date: Thu, 16 Mar 2023 22:26:34 +0000 Subject: Implement declarative references for enumerator --- enumerator.c | 51 +++++++++++++++------------------------------------ 1 file changed, 15 insertions(+), 36 deletions(-) (limited to 'enumerator.c') diff --git a/enumerator.c b/enumerator.c index b2f8855503..b33c171371 100644 --- a/enumerator.c +++ b/enumerator.c @@ -188,6 +188,18 @@ struct enumerator { int kw_splat; }; +RUBY_REFERENCES_START(enumerator_refs) + REF_EDGE(enumerator, obj), + REF_EDGE(enumerator, args), + REF_EDGE(enumerator, fib), + REF_EDGE(enumerator, dst), + REF_EDGE(enumerator, lookahead), + REF_EDGE(enumerator, feedvalue), + REF_EDGE(enumerator, stop_exc), + REF_EDGE(enumerator, size), + REF_EDGE(enumerator, procs), +RUBY_REFERENCES_END + static VALUE rb_cGenerator, rb_cYielder, rb_cEnumProducer; struct generator { @@ -237,39 +249,6 @@ struct enum_product { VALUE rb_cArithSeq; -/* - * Enumerator - */ -static void -enumerator_mark(void *p) -{ - struct enumerator *ptr = p; - rb_gc_mark_movable(ptr->obj); - rb_gc_mark_movable(ptr->args); - rb_gc_mark_movable(ptr->fib); - rb_gc_mark_movable(ptr->dst); - rb_gc_mark_movable(ptr->lookahead); - rb_gc_mark_movable(ptr->feedvalue); - rb_gc_mark_movable(ptr->stop_exc); - rb_gc_mark_movable(ptr->size); - rb_gc_mark_movable(ptr->procs); -} - -static void -enumerator_compact(void *p) -{ - struct enumerator *ptr = p; - ptr->obj = rb_gc_location(ptr->obj); - ptr->args = rb_gc_location(ptr->args); - ptr->fib = rb_gc_location(ptr->fib); - ptr->dst = rb_gc_location(ptr->dst); - ptr->lookahead = rb_gc_location(ptr->lookahead); - ptr->feedvalue = rb_gc_location(ptr->feedvalue); - ptr->stop_exc = rb_gc_location(ptr->stop_exc); - ptr->size = rb_gc_location(ptr->size); - ptr->procs = rb_gc_location(ptr->procs); -} - #define enumerator_free RUBY_TYPED_DEFAULT_FREE static size_t @@ -281,12 +260,12 @@ enumerator_memsize(const void *p) static const rb_data_type_t enumerator_data_type = { "enumerator", { - enumerator_mark, + REFS_LIST_PTR(enumerator_refs), enumerator_free, enumerator_memsize, - enumerator_compact, + NULL, }, - 0, 0, RUBY_TYPED_FREE_IMMEDIATELY + 0, NULL, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_DECL_MARKING }; static struct enumerator * -- cgit v1.2.1