Skip to content

Commit

Permalink
Implement declarative references for enumerator
Browse files Browse the repository at this point in the history
  • Loading branch information
eightbitraptor committed Mar 17, 2023
1 parent 405966e commit 22b3492
Showing 1 changed file with 15 additions and 36 deletions.
51 changes: 15 additions & 36 deletions enumerator.c
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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 *
Expand Down

0 comments on commit 22b3492

Please sign in to comment.