ruby-changes:51161
From: shyouhei <ko1@a...>
Date: Wed, 9 May 2018 14:42:13 +0900 (JST)
Subject: [ruby-changes:51161] shyouhei:r63368 (trunk): RSTRING_PTR is not guaranteed to be VALUE-aligned (retry)
shyouhei 2018-05-09 14:42:06 +0900 (Wed, 09 May 2018) New Revision: 63368 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63368 Log: RSTRING_PTR is not guaranteed to be VALUE-aligned (retry) Don't abuse struct RString to hold arbitrary memory region. Raw pointer should just suffice. Modified files: trunk/compile.c trunk/iseq.c trunk/iseq.h trunk/vm_core.h Index: compile.c =================================================================== --- compile.c (revision 63367) +++ compile.c (revision 63368) @@ -8929,7 +8929,7 @@ ibf_dump_iseq_each(struct ibf_dump *dump https://github.com/ruby/ruby/blob/trunk/compile.c#L8929 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); Index: iseq.c =================================================================== --- iseq.c (revision 63367) +++ iseq.c (revision 63368) @@ -222,7 +222,6 @@ rb_iseq_mark(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L222 } 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); Index: iseq.h =================================================================== --- iseq.h (revision 63367) +++ iseq.h (revision 63368) @@ -46,23 +46,24 @@ ISEQ_FLIP_CNT_INCREMENT(const rb_iseq_t https://github.com/ruby/ruby/blob/trunk/iseq.h#L46 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 | \ Index: vm_core.h =================================================================== --- vm_core.h (revision 63367) +++ vm_core.h (revision 63368) @@ -420,7 +420,7 @@ struct rb_iseq_constant_body { https://github.com/ruby/ruby/blob/trunk/vm_core.h#L420 struct { rb_snum_t flip_count; VALUE coverage; - VALUE original_iseq; + VALUE *original_iseq; } variable; unsigned int local_table_size; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/