diff --git a/iseq.c b/iseq.c index 631115cce1..c38ac4dd83 100644 --- a/iseq.c +++ b/iseq.c @@ -324,6 +324,33 @@ iseq_alloc(void) return iseq; } +struct count_info { + int count; +}; + +static void +count_markables(void *ctx, VALUE obj) +{ + struct count_info * my_count = (struct count_info *)ctx; + my_count->count += 1; +} + +static VALUE +iseqw_object_count(VALUE self) +{ + rb_iseq_t * iseq = iseqw_check(self); + struct count_info my_count = {0,}; + rb_iseq_each_value(iseq, count_markables, &my_count); + return INT2NUM(my_count.count); +} + +static VALUE +iseqw_size(VALUE self) +{ + rb_iseq_t * iseq = iseqw_check(self); + return INT2NUM(iseq->body->iseq_size); +} + VALUE rb_iseq_pathobj_new(VALUE path, VALUE realpath) { @@ -3075,6 +3102,8 @@ Init_ISeq(void) rb_define_method(rb_cISeq, "first_lineno", iseqw_first_lineno, 0); rb_define_method(rb_cISeq, "trace_points", iseqw_trace_points, 0); rb_define_method(rb_cISeq, "each_child", iseqw_each_child, 0); + rb_define_method(rb_cISeq, "markable_object_count", iseqw_object_count, 0); + rb_define_method(rb_cISeq, "size", iseqw_size, 0); #if 0 /* TBD */ rb_define_private_method(rb_cISeq, "marshal_dump", iseqw_marshal_dump, 0);