From 19b366998feb811a976cb8de46c60bc1bf61b124 Mon Sep 17 00:00:00 2001 From: ko1 Date: Wed, 2 Dec 2015 08:20:35 +0000 Subject: * iseq.h: introduce ISEQ_ORIGINAL_ISEQ() and ISEQ_ORIGINAL_ISEQ_ALLOC() macro. * compile.c: use them to access original iseq buffer. * iseq.c: ditto. * vm_core.h: rename iseq field to support this fix. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52862 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 11 +++++++++++ compile.c | 14 +++++++------- iseq.c | 4 ++-- iseq.h | 9 ++++++--- vm_core.h | 2 +- 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5649cbc230..cab13e1310 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Wed Dec 2 17:19:02 2015 Koichi Sasada + + * iseq.h: introduce ISEQ_ORIGINAL_ISEQ() and + ISEQ_ORIGINAL_ISEQ_ALLOC() macro. + + * compile.c: use them to access original iseq buffer. + + * iseq.c: ditto. + + * vm_core.h: rename iseq field to support this fix. + Wed Dec 2 17:10:32 2015 Koichi Sasada * iseq.h: introduce ISEQ_FLIP_CNT_INCREMENT() macro. diff --git a/compile.c b/compile.c index a53d276c4c..fabba758f6 100644 --- a/compile.c +++ b/compile.c @@ -641,26 +641,26 @@ rb_vm_insn_addr2insn(const void *addr) /* cold path */ VALUE * rb_iseq_original_iseq(const rb_iseq_t *iseq) /* cold path */ { - if (iseq->variable_body->iseq) return iseq->variable_body->iseq; + VALUE *original_code; - iseq->variable_body->iseq = ALLOC_N(VALUE, iseq->body->iseq_size); - - MEMCPY(iseq->variable_body->iseq, iseq->body->iseq_encoded, VALUE, iseq->body->iseq_size); + if (ISEQ_ORIGINAL_ISEQ(iseq)) return ISEQ_ORIGINAL_ISEQ(iseq); + original_code = ISEQ_ORIGINAL_ISEQ_ALLOC(iseq, iseq->body->iseq_size); + MEMCPY(ISEQ_ORIGINAL_ISEQ(iseq), iseq->body->iseq_encoded, VALUE, iseq->body->iseq_size); #if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE { unsigned int i; for (i = 0; i < iseq->body->iseq_size; /* */ ) { - const void *addr = (const void *)iseq->variable_body->iseq[i]; + const void *addr = (const void *)original_code[i]; const int insn = rb_vm_insn_addr2insn(addr); - iseq->variable_body->iseq[i] = insn; + original_code[i] = insn; i += insn_len(insn); } } #endif - return iseq->variable_body->iseq; + return original_code; } /*********************************************/ diff --git a/iseq.c b/iseq.c index 66fd11f3f7..3a539170a3 100644 --- a/iseq.c +++ b/iseq.c @@ -92,7 +92,7 @@ rb_iseq_free(const rb_iseq_t *iseq) ruby_xfree((void *)iseq->body->param.keyword); } compile_data_free(ISEQ_COMPILE_DATA(iseq)); - ruby_xfree(iseq->variable_body->iseq); + ruby_xfree(iseq->variable_body->iseq_); ruby_xfree(iseq->variable_body); ruby_xfree(iseq->body); } @@ -157,7 +157,7 @@ iseq_memsize(const rb_iseq_t *iseq) if (variable_body) { size += sizeof(struct rb_iseq_variable_body); - if (variable_body->iseq && body) { + if (variable_body->iseq_ && body) { size += body->iseq_size * sizeof(VALUE); } } diff --git a/iseq.h b/iseq.h index 03cb8b3efb..73416ab327 100644 --- a/iseq.h +++ b/iseq.h @@ -23,10 +23,13 @@ rb_call_info_kw_arg_bytes(int keyword_len) return sizeof(struct rb_call_info_kw_arg) + sizeof(VALUE) * (keyword_len - 1); } -#define ISEQ_COMPILE_DATA(iseq) (iseq)->compile_data_ -#define ISEQ_COVERAGE(iseq) (iseq)->variable_body->coverage_ -#define ISEQ_COVERAGE_SET(iseq, cov) RB_OBJ_WRITE((iseq), &(iseq)->variable_body->coverage_, cov) +#define ISEQ_COMPILE_DATA(iseq) (iseq)->compile_data_ +#define ISEQ_COVERAGE(iseq) (iseq)->variable_body->coverage_ +#define ISEQ_COVERAGE_SET(iseq, cov) RB_OBJ_WRITE((iseq), &(iseq)->variable_body->coverage_, cov) #define ISEQ_FLIP_CNT_INCREMENT(iseq) ((iseq)->variable_body->flip_cnt_++) +#define ISEQ_ORIGINAL_ISEQ(iseq) (iseq)->variable_body->iseq_ +#define ISEQ_ORIGINAL_ISEQ_ALLOC(iseq, size) (ISEQ_ORIGINAL_ISEQ(iseq) = ALLOC_N(VALUE, size)) + RUBY_SYMBOL_EXPORT_BEGIN /* compile.c */ diff --git a/vm_core.h b/vm_core.h index 103b974afe..377b6a964e 100644 --- a/vm_core.h +++ b/vm_core.h @@ -392,7 +392,7 @@ struct rb_iseq_variable_body { /* original iseq, before encoding * used for debug/dump (TODO: union with compile_data) */ - VALUE *iseq; + VALUE *iseq_; }; /* T_IMEMO/iseq */ -- cgit v1.2.3