ruby-changes:38467
From: nagachika <ko1@a...>
Date: Wed, 20 May 2015 03:43:20 +0900 (JST)
Subject: [ruby-changes:38467] nagachika:r50548 (ruby_2_2): merge revision(s) 49922, 50111, 50112: [Backport #11012]
nagachika 2015-05-20 03:43:01 +0900 (Wed, 20 May 2015) New Revision: 50548 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50548 Log: merge revision(s) 49922,50111,50112: [Backport #11012] * proc.c: use RUBY_VM_IFUNC_P() to recognize IFUNC or not. * vm.c: ditto. * vm_dump.c: ditto. * vm_insnhelper.c: ditto. * vm_core.h: use RB_TYPE_P() instead of BUILTIN_TYPE(). * proc.c (proc_binding): replicate env from method object, and allocate the local variable area for the iseq local table. [ruby-core:68673] [Bug #11012] Modified directories: branches/ruby_2_2/ Modified files: branches/ruby_2_2/ChangeLog branches/ruby_2_2/proc.c branches/ruby_2_2/test/ruby/test_method.rb branches/ruby_2_2/version.h branches/ruby_2_2/vm.c branches/ruby_2_2/vm_core.h branches/ruby_2_2/vm_dump.c branches/ruby_2_2/vm_insnhelper.c Index: ruby_2_2/ChangeLog =================================================================== --- ruby_2_2/ChangeLog (revision 50547) +++ ruby_2_2/ChangeLog (revision 50548) @@ -1,3 +1,21 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/ChangeLog#L1 +Wed May 20 03:25:34 2015 Nobuyoshi Nakada <nobu@r...> + + * proc.c (proc_binding): replicate env from method object, and + allocate the local variable area for the iseq local table. + [ruby-core:68673] [Bug #11012] + +Wed May 20 03:25:34 2015 Koichi Sasada <ko1@a...> + + * proc.c: use RUBY_VM_IFUNC_P() to recognize IFUNC or not. + + * vm.c: ditto. + + * vm_dump.c: ditto. + + * vm_insnhelper.c: ditto. + + * vm_core.h: use RB_TYPE_P() instead of BUILTIN_TYPE(). + Wed May 20 03:10:49 2015 Nobuyoshi Nakada <nobu@r...> * benchmark/bm_hash_aref_flo.rb: make more realistic data. Index: ruby_2_2/vm_core.h =================================================================== --- ruby_2_2/vm_core.h (revision 50547) +++ ruby_2_2/vm_core.h (revision 50548) @@ -913,7 +913,7 @@ rb_block_t *rb_vm_control_frame_block_pt https://github.com/ruby/ruby/blob/trunk/ruby_2_2/vm_core.h#L913 #define RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp) \ (!RUBY_VM_VALID_CONTROL_FRAME_P((cfp), RUBY_VM_END_CONTROL_FRAME(th))) -#define RUBY_VM_IFUNC_P(ptr) (BUILTIN_TYPE(ptr) == T_NODE) +#define RUBY_VM_IFUNC_P(ptr) RB_TYPE_P((VALUE)(ptr), T_NODE) #define RUBY_VM_NORMAL_ISEQ_P(ptr) \ ((ptr) && !RUBY_VM_IFUNC_P(ptr)) Index: ruby_2_2/proc.c =================================================================== --- ruby_2_2/proc.c (revision 50547) +++ ruby_2_2/proc.c (revision 50548) @@ -719,7 +719,7 @@ proc_call(int argc, VALUE *argv, VALUE p https://github.com/ruby/ruby/blob/trunk/ruby_2_2/proc.c#L719 GetProcPtr(procval, proc); iseq = proc->block.iseq; - if (BUILTIN_TYPE(iseq) == T_NODE || iseq->param.flags.has_block) { + if (RUBY_VM_IFUNC_P(iseq) || iseq->param.flags.has_block) { if (rb_block_given_p()) { rb_proc_t *passed_proc; RB_GC_GUARD(passed_procval) = rb_block_proc(); @@ -843,7 +843,7 @@ rb_block_min_max_arity(rb_block_t *block https://github.com/ruby/ruby/blob/trunk/ruby_2_2/proc.c#L843 { rb_iseq_t *iseq = block->iseq; if (iseq) { - if (BUILTIN_TYPE(iseq) != T_NODE) { + if (!RUBY_VM_IFUNC_P(iseq)) { return rb_iseq_min_max_arity(iseq, max); } else { @@ -1717,7 +1717,7 @@ rb_mod_define_method(int argc, VALUE *ar https://github.com/ruby/ruby/blob/trunk/ruby_2_2/proc.c#L1717 rb_proc_t *proc; body = proc_dup(body); GetProcPtr(body, proc); - if (BUILTIN_TYPE(proc->block.iseq) != T_NODE) { + if (!RUBY_VM_IFUNC_P(proc->block.iseq)) { proc->block.iseq->defined_method_id = id; RB_OBJ_WRITE(proc->block.iseq->self, &proc->block.iseq->klass, mod); proc->is_lambda = TRUE; @@ -2477,22 +2477,40 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ruby_2_2/proc.c#L2477 proc_binding(VALUE self) { rb_proc_t *proc; - VALUE bindval; + VALUE bindval, envval; rb_binding_t *bind; rb_iseq_t *iseq; GetProcPtr(self, proc); + envval = proc->envval; iseq = proc->block.iseq; - if (RB_TYPE_P((VALUE)iseq, T_NODE)) { + if (RUBY_VM_IFUNC_P(iseq)) { + rb_env_t *env; if (!IS_METHOD_PROC_NODE((NODE *)iseq)) { rb_raise(rb_eArgError, "Can't create Binding from C level Proc"); } iseq = rb_method_get_iseq(RNODE(iseq)->u2.value); + GetEnvPtr(envval, env); + if (iseq && env->local_size < iseq->local_size) { + int prev_local_size = env->local_size; + int local_size = iseq->local_size; + VALUE newenvval = TypedData_Wrap_Struct(RBASIC_CLASS(envval), RTYPEDDATA_TYPE(envval), 0); + rb_env_t *newenv = xmalloc(sizeof(rb_env_t) + ((local_size + 1) * sizeof(VALUE))); + RTYPEDDATA_DATA(newenvval) = newenv; + newenv->env_size = local_size + 2; + newenv->local_size = local_size; + newenv->prev_envval = env->prev_envval; + newenv->block = env->block; + MEMCPY(newenv->env, env->env, VALUE, prev_local_size + 1); + rb_mem_clear(newenv->env + prev_local_size + 1, local_size - prev_local_size); + newenv->env[local_size + 1] = newenvval; + envval = newenvval; + } } bindval = rb_binding_alloc(rb_cBinding); GetBindingPtr(bindval, bind); - bind->env = proc->envval; + bind->env = envval; bind->blockprocval = proc->blockprocval; if (RUBY_VM_NORMAL_ISEQ_P(iseq)) { bind->path = iseq->location.path; Index: ruby_2_2/vm.c =================================================================== --- ruby_2_2/vm.c (revision 50547) +++ ruby_2_2/vm.c (revision 50548) @@ -380,7 +380,7 @@ env_mark(void * const ptr) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/vm.c#L380 RUBY_MARK_UNLESS_NULL(env->block.proc); if (env->block.iseq) { - if (BUILTIN_TYPE(env->block.iseq) == T_NODE) { + if (RUBY_VM_IFUNC_P(env->block.iseq)) { RUBY_MARK_UNLESS_NULL((VALUE)env->block.iseq); } else { @@ -768,7 +768,7 @@ invoke_block_from_c(rb_thread_t *th, con https://github.com/ruby/ruby/blob/trunk/ruby_2_2/vm.c#L768 if (SPECIAL_CONST_P(block->iseq)) { return Qnil; } - else if (BUILTIN_TYPE(block->iseq) != T_NODE) { + else if (!RUBY_VM_IFUNC_P(block->iseq)) { VALUE ret; const rb_iseq_t *iseq = block->iseq; const rb_control_frame_t *cfp; Index: ruby_2_2/version.h =================================================================== --- ruby_2_2/version.h (revision 50547) +++ ruby_2_2/version.h (revision 50548) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/version.h#L1 #define RUBY_VERSION "2.2.3" #define RUBY_RELEASE_DATE "2015-05-20" -#define RUBY_PATCHLEVEL 107 +#define RUBY_PATCHLEVEL 108 #define RUBY_RELEASE_YEAR 2015 #define RUBY_RELEASE_MONTH 5 Index: ruby_2_2/vm_dump.c =================================================================== --- ruby_2_2/vm_dump.c (revision 50547) +++ ruby_2_2/vm_dump.c (revision 50548) @@ -36,7 +36,7 @@ control_frame_dump(rb_thread_t *th, rb_c https://github.com/ruby/ruby/blob/trunk/ruby_2_2/vm_dump.c#L36 const char *magic, *iseq_name = "-", *selfstr = "-", *biseq_name = "-"; VALUE tmp; - if (cfp->block_iseq != 0 && BUILTIN_TYPE(cfp->block_iseq) != T_NODE) { + if (cfp->block_iseq != 0 && !RUBY_VM_IFUNC_P(cfp->block_iseq)) { biseq_name = ""; /* RSTRING(cfp->block_iseq->location.label)->ptr; */ } Index: ruby_2_2/vm_insnhelper.c =================================================================== --- ruby_2_2/vm_insnhelper.c (revision 50547) +++ ruby_2_2/vm_insnhelper.c (revision 50548) @@ -2073,7 +2073,7 @@ vm_invoke_block(rb_thread_t *th, rb_cont https://github.com/ruby/ruby/blob/trunk/ruby_2_2/vm_insnhelper.c#L2073 } iseq = block->iseq; - if (BUILTIN_TYPE(iseq) != T_NODE) { + if (!RUBY_VM_IFUNC_P(iseq)) { int opt_pc; const int arg_size = iseq->param.size; int is_lambda = block_proc_is_lambda(block->proc); Index: ruby_2_2/test/ruby/test_method.rb =================================================================== --- ruby_2_2/test/ruby/test_method.rb (revision 50547) +++ ruby_2_2/test/ruby/test_method.rb (revision 50548) @@ -877,4 +877,18 @@ class TestMethod < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/ruby/test_method.rb#L877 obj.bar end end + + def test_to_proc_binding + bug11012 = '[ruby-core:68673] [Bug #11012]' + class << (obj = Object.new) + src = 1000.times.map {|i|"v#{i} = nil"}.join("\n") + eval("def foo()\n""#{src}\n""end") + end + + b = obj.method(:foo).to_proc.binding + b.local_variables.each_with_index {|n, i| + b.local_variable_set(n, i) + } + assert_equal([998, 999], %w[v998 v999].map {|n| b.local_variable_get(n)}, bug11012) + end end Property changes on: ruby_2_2 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r49922,50111-50112 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/