ruby-changes:29340
From: nagachika <ko1@a...>
Date: Wed, 19 Jun 2013 03:22:34 +0900 (JST)
Subject: [ruby-changes:29340] nagachika:r41392 (ruby_2_0_0): merge revision(s) 41342,41359,41361: [Backport #8341]
nagachika 2013-06-19 03:22:16 +0900 (Wed, 19 Jun 2013) New Revision: 41392 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41392 Log: merge revision(s) 41342,41359,41361: [Backport #8341] test/ruby/test_proc.rb: tests for [Bug #8341] * include/ruby/intern.h, proc.c (rb_method_call_with_block): new function to invoke a Method object with a block passed as an argument. * proc.c (bmcall): use the above function to avoid a block sharing. [ruby-core:54626] [Bug #8341] * test/ruby/test_proc.rb (TestProc#test_block_persist_between_calls): run related tests. * test/ruby/test_proc.rb (TestProc#test_block_given_method_to_proc): run test for r41359. Modified directories: branches/ruby_2_0_0/ Modified files: branches/ruby_2_0_0/ChangeLog branches/ruby_2_0_0/include/ruby/intern.h branches/ruby_2_0_0/proc.c branches/ruby_2_0_0/test/ruby/test_proc.rb branches/ruby_2_0_0/version.h Index: ruby_2_0_0/include/ruby/intern.h =================================================================== --- ruby_2_0_0/include/ruby/intern.h (revision 41391) +++ ruby_2_0_0/include/ruby/intern.h (revision 41392) @@ -393,6 +393,7 @@ VALUE rb_binding_new(void); https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/include/ruby/intern.h#L393 VALUE rb_obj_method(VALUE, VALUE); VALUE rb_obj_is_method(VALUE); VALUE rb_method_call(int, VALUE*, VALUE); +VALUE rb_method_call_with_block(int, VALUE *, VALUE, VALUE); int rb_mod_method_arity(VALUE, ID); int rb_obj_method_arity(VALUE, ID); VALUE rb_protect(VALUE (*)(VALUE), VALUE, int*); Index: ruby_2_0_0/ChangeLog =================================================================== --- ruby_2_0_0/ChangeLog (revision 41391) +++ ruby_2_0_0/ChangeLog (revision 41392) @@ -1,3 +1,20 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1 +Wed Jun 19 03:06:57 2013 Kazuki Tsujimoto <kazuki@c...> + + * test/ruby/test_proc.rb (TestProc#test_block_given_method_to_proc): + run test for r41359. + +Wed Jun 19 03:06:57 2013 Kazuki Tsujimoto <kazuki@c...> + + * include/ruby/intern.h, proc.c (rb_method_call_with_block): + new function to invoke a Method object with a block passed + as an argument. + + * proc.c (bmcall): use the above function to avoid a block sharing. + [ruby-core:54626] [Bug #8341] + + * test/ruby/test_proc.rb (TestProc#test_block_persist_between_calls): + run related tests. + Tue Jun 18 02:49:20 2013 NARUSE, Yui <naruse@r...> * test/ruby/envutil.rb (assert_separately): stop_auto_run of Index: ruby_2_0_0/proc.c =================================================================== --- ruby_2_0_0/proc.c (revision 41391) +++ ruby_2_0_0/proc.c (revision 41392) @@ -28,7 +28,7 @@ VALUE rb_cMethod; https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/proc.c#L28 VALUE rb_cBinding; VALUE rb_cProc; -static VALUE bmcall(VALUE, VALUE); +static VALUE bmcall(VALUE, VALUE, int, VALUE *, VALUE); static int method_arity(VALUE); static int method_min_max_arity(VALUE, int *max); static ID attached; @@ -1525,6 +1525,13 @@ method_clone(VALUE self) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/proc.c#L1525 VALUE rb_method_call(int argc, VALUE *argv, VALUE method) { + VALUE proc = rb_block_given_p() ? rb_block_proc() : Qnil; + return rb_method_call_with_block(argc, argv, method, proc); +} + +VALUE +rb_method_call_with_block(int argc, VALUE *argv, VALUE method, VALUE pass_procval) +{ VALUE result = Qnil; /* OK */ struct METHOD *data; int state; @@ -1544,8 +1551,15 @@ rb_method_call(int argc, VALUE *argv, VA https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/proc.c#L1551 } if ((state = EXEC_TAG()) == 0) { rb_thread_t *th = GET_THREAD(); + rb_block_t *block = 0; + + if (!NIL_P(pass_procval)) { + rb_proc_t *pass_proc; + GetProcPtr(pass_procval, pass_proc); + block = &pass_proc->block; + } - PASS_PASSED_BLOCK_TH(th); + th->passed_block = block; result = rb_vm_call(th, data->recv, data->id, argc, argv, data->me, data->defined_class); } POP_TAG(); @@ -1989,11 +2003,10 @@ mlambda(VALUE method) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/proc.c#L2003 } static VALUE -bmcall(VALUE args, VALUE method) +bmcall(VALUE args, VALUE method, int argc, VALUE *argv, VALUE passed_proc) { volatile VALUE a; VALUE ret; - int argc; if (CLASS_OF(args) != rb_cArray) { args = rb_ary_new3(1, args); @@ -2002,7 +2015,7 @@ bmcall(VALUE args, VALUE method) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/proc.c#L2015 else { argc = check_argc(RARRAY_LEN(args)); } - ret = rb_method_call(argc, RARRAY_PTR(args), method); + ret = rb_method_call_with_block(argc, RARRAY_PTR(args), method, passed_proc); RB_GC_GUARD(a) = args; return ret; } Index: ruby_2_0_0/version.h =================================================================== --- ruby_2_0_0/version.h (revision 41391) +++ ruby_2_0_0/version.h (revision 41392) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1 #define RUBY_VERSION "2.0.0" #define RUBY_RELEASE_DATE "2013-06-19" -#define RUBY_PATCHLEVEL 229 +#define RUBY_PATCHLEVEL 230 #define RUBY_RELEASE_YEAR 2013 #define RUBY_RELEASE_MONTH 6 Index: ruby_2_0_0/test/ruby/test_proc.rb =================================================================== --- ruby_2_0_0/test/ruby/test_proc.rb (revision 41391) +++ ruby_2_0_0/test/ruby/test_proc.rb (revision 41392) @@ -166,6 +166,14 @@ class TestProc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_proc.rb#L166 method(:m2).to_proc end + def m1(var) + var + end + + def m_block_given? + m1(block_given?) + end + # [yarv-dev:777] block made by Method#to_proc def test_method_to_proc b = block() @@ -173,6 +181,37 @@ class TestProc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_proc.rb#L181 assert_instance_of(Binding, b.binding, '[ruby-core:25589]') end + def test_block_given_method + m = method(:m_block_given?) + assert(!m.call, "without block") + assert(m.call {}, "with block") + assert(!m.call, "without block second") + end + + def test_block_given_method_to_proc + bug8341 = '[Bug #8341]' + m = method(:m_block_given?).to_proc + assert(!m.call, "#{bug8341} without block") + assert(m.call {}, "#{bug8341} with block") + assert(!m.call, "#{bug8341} without block second") + end + + def test_block_persist_between_calls + bug8341 = '[Bug #8341]' + o = Object.new + def o.m1(top=true) + if top + [block_given?, @m.call(false)] + else + block_given? + end + end + m = o.method(:m1).to_proc + o.instance_variable_set(:@m, m) + assert_equal([true, false], m.call {}, "#{bug8341} nested with block") + assert_equal([false, false], m.call, "#{bug8341} nested without block") + end + def test_curry b = proc {|x, y, z| (x||0) + (y||0) + (z||0) } assert_equal(6, b.curry[1][2][3]) Property changes on: ruby_2_0_0 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r41342,41359,41361 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/