ruby-changes:39592
From: nagachika <ko1@a...>
Date: Tue, 25 Aug 2015 01:13:47 +0900 (JST)
Subject: [ruby-changes:39592] nagachika:r51673 (ruby_2_2): * insns.def (defineclass): introduce an ad-hoc patch to avoid
nagachika 2015-08-25 01:13:22 +0900 (Tue, 25 Aug 2015) New Revision: 51673 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51673 Log: * insns.def (defineclass): introduce an ad-hoc patch to avoid an issue reported on [Bug #10871]. This patch does not fix completely. For example, method definition in a block (like 1.times{def ...; end}) still causes same issue. To solve all, we need a huge patch and it seems difficult for stable branch. Use Ruby 2.3 and later to solve this issue completely. (See [Bug #10943]) Modified files: branches/ruby_2_2/ChangeLog branches/ruby_2_2/insns.def branches/ruby_2_2/version.h Index: ruby_2_2/insns.def =================================================================== --- ruby_2_2/insns.def (revision 51672) +++ ruby_2_2/insns.def (revision 51673) @@ -914,6 +914,8 @@ defineclass https://github.com/ruby/ruby/blob/trunk/ruby_2_2/insns.def#L914 (VALUE val) { VALUE klass; + VALUE class_iseq_val = class_iseq->self; + rb_iseq_t *orig_class_iseq = NULL; rb_vm_defineclass_type_t type = VM_DEFINECLASS_TYPE(flags); switch (type) { @@ -963,7 +965,18 @@ defineclass https://github.com/ruby/ruby/blob/trunk/ruby_2_2/insns.def#L965 case VM_DEFINECLASS_TYPE_SINGLETON_CLASS: /* val is dummy. classdef returns class scope value */ /* super is dummy */ - klass = rb_singleton_class(cbase); + { + klass = rb_singleton_class(cbase); + + /* Copy iseq to duplicate cref_stack place. + * This is ad-hoc solution for [Bug #10871]. + * and this does not solve more complicated source code with singleton class. + * If you need to solve everything, use Ruby 2.3 and later. + */ + orig_class_iseq = class_iseq; + class_iseq_val = rb_iseq_clone(class_iseq->self, cbase); + GetISeqPtr(class_iseq_val, class_iseq); + } break; case VM_DEFINECLASS_TYPE_MODULE: /* val is dummy. classdef returns class scope value */ @@ -992,12 +1005,18 @@ defineclass https://github.com/ruby/ruby/blob/trunk/ruby_2_2/insns.def#L1005 } COPY_CREF(class_iseq->cref_stack, vm_cref_push(th, klass, NOEX_PUBLIC, NULL)); + if (orig_class_iseq) { + COPY_CREF(orig_class_iseq->cref_stack, vm_cref_push(th, klass, NOEX_PUBLIC, NULL)); + } /* enter scope */ vm_push_frame(th, class_iseq, VM_FRAME_MAGIC_CLASS, klass, 0, VM_ENVVAL_BLOCK_PTR(GET_BLOCK_PTR()), class_iseq->iseq_encoded, GET_SP(), class_iseq->local_size, 0, class_iseq->stack_max); + + RB_GC_GUARD(class_iseq_val); + RESTORE_REGS(); NEXT_INSN(); } Index: ruby_2_2/ChangeLog =================================================================== --- ruby_2_2/ChangeLog (revision 51672) +++ ruby_2_2/ChangeLog (revision 51673) @@ -1,3 +1,16 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/ChangeLog#L1 +Tue Aug 25 01:01:01 2015 Koichi Sasada <ko1@a...> + + * insns.def (defineclass): introduce an ad-hoc patch to avoid + an issue reported on [Bug #10871]. + + This patch does not fix completely. For example, method definition + in a block (like 1.times{def ...; end}) still causes same issue. + To solve all, we need a huge patch and it seems difficult for + stable branch. + + Use Ruby 2.3 and later to solve this issue completely. + (See [Bug #10943]) + Tue Aug 18 22:52:50 2015 NAKAMURA Usaku <usa@r...> * tool/downloader.rb: support old versions of ruby. Index: ruby_2_2/version.h =================================================================== --- ruby_2_2/version.h (revision 51672) +++ ruby_2_2/version.h (revision 51673) @@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/version.h#L1 #define RUBY_VERSION "2.2.4" -#define RUBY_RELEASE_DATE "2015-08-19" -#define RUBY_PATCHLEVEL 174 +#define RUBY_RELEASE_DATE "2015-08-25" +#define RUBY_PATCHLEVEL 175 #define RUBY_RELEASE_YEAR 2015 #define RUBY_RELEASE_MONTH 8 -#define RUBY_RELEASE_DAY 19 +#define RUBY_RELEASE_DAY 25 #include "ruby/version.h" -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/