diff --git a/compile.c b/compile.c index 4fa3e473e2..5b5d645c07 100644 --- a/compile.c +++ b/compile.c @@ -8929,7 +8929,7 @@ ibf_dump_iseq_each(struct ibf_dump *dump, const rb_iseq_t *iseq) dump_body.ci_entries = ibf_dump_ci_entries(dump, iseq); dump_body.cc_entries = NULL; dump_body.variable.coverage = Qnil; - dump_body.variable.original_iseq = Qnil; + dump_body.variable.original_iseq = NULL; IBF_W_ALIGN(struct rb_iseq_constant_body); return IBF_WV(dump_body); diff --git a/iseq.c b/iseq.c index 74a29a6b85..67a89e1a6b 100644 --- a/iseq.c +++ b/iseq.c @@ -222,7 +222,6 @@ rb_iseq_mark(const rb_iseq_t *iseq) } rb_gc_mark(body->variable.coverage); - rb_gc_mark(body->variable.original_iseq); rb_gc_mark(body->location.label); rb_gc_mark(body->location.base_label); rb_gc_mark(body->location.pathobj); diff --git a/iseq.h b/iseq.h index de8beff1ad..6789635de3 100644 --- a/iseq.h +++ b/iseq.h @@ -46,23 +46,24 @@ ISEQ_FLIP_CNT_INCREMENT(const rb_iseq_t *iseq) static inline VALUE * ISEQ_ORIGINAL_ISEQ(const rb_iseq_t *iseq) { - VALUE str = iseq->body->variable.original_iseq; - if (RTEST(str)) return (VALUE *)RSTRING_PTR(str); - return NULL; + return iseq->body->variable.original_iseq; } static inline void ISEQ_ORIGINAL_ISEQ_CLEAR(const rb_iseq_t *iseq) { - RB_OBJ_WRITE(iseq, &iseq->body->variable.original_iseq, Qnil); + void *ptr = iseq->body->variable.original_iseq; + iseq->body->variable.original_iseq = NULL; + if (ptr) { + ruby_xfree(ptr); + } } static inline VALUE * ISEQ_ORIGINAL_ISEQ_ALLOC(const rb_iseq_t *iseq, long size) { - VALUE str = rb_str_tmp_new(size * sizeof(VALUE)); - RB_OBJ_WRITE(iseq, &iseq->body->variable.original_iseq, str); - return (VALUE *)RSTRING_PTR(str); + return iseq->body->variable.original_iseq = + ruby_xmalloc2(sizeof(VALUE), size); } #define ISEQ_TRACE_EVENTS (RUBY_EVENT_LINE | \ diff --git a/vm_core.h b/vm_core.h index a5ba1900c1..06bd93d885 100644 --- a/vm_core.h +++ b/vm_core.h @@ -420,7 +420,7 @@ struct rb_iseq_constant_body { struct { rb_snum_t flip_count; VALUE coverage; - VALUE original_iseq; + VALUE *original_iseq; } variable; unsigned int local_table_size;