[前][次][番号順一覧][スレッド一覧]

ruby-changes:36079

From: nobu <ko1@a...>
Date: Mon, 27 Oct 2014 17:17:35 +0900 (JST)
Subject: [ruby-changes:36079] nobu:r48160 (trunk): proc.c: fix method proc binding receiver

nobu	2014-10-27 17:17:26 +0900 (Mon, 27 Oct 2014)

  New Revision: 48160

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48160

  Log:
    proc.c: fix method proc binding receiver
    
    * proc.c (method_proc): the receiver of binding from method should
      be same as the receiver of the method.
      [ruby-core:65917] [Bug #10432]

  Modified files:
    trunk/ChangeLog
    trunk/proc.c
    trunk/test/ruby/test_proc.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 48159)
+++ ChangeLog	(revision 48160)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Oct 27 17:17:24 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* proc.c (method_proc): the receiver of binding from method should
+	  be same as the receiver of the method.
+	  [ruby-core:65917] [Bug #10432]
+
 Mon Oct 27 16:26:37 2014  Koichi Sasada  <ko1@a...>
 
 	* test/ruby/test_super.rb: add a test to check block passing.
Index: proc.c
===================================================================
--- proc.c	(revision 48159)
+++ proc.c	(revision 48160)
@@ -2365,7 +2365,10 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/proc.c#L2365
 method_proc(VALUE method)
 {
     VALUE procval;
+    struct METHOD *meth;
     rb_proc_t *proc;
+    rb_env_t *env;
+
     /*
      * class Method
      *   def to_proc
@@ -2375,9 +2378,16 @@ method_proc(VALUE method) https://github.com/ruby/ruby/blob/trunk/proc.c#L2378
      *   end
      * end
      */
+    TypedData_Get_Struct(method, struct METHOD, &method_data_type, meth);
     procval = rb_iterate(mlambda, 0, bmcall, method);
     GetProcPtr(procval, proc);
     proc->is_from_method = 1;
+    proc->block.self = meth->recv;
+    proc->block.klass = meth->defined_class;
+    GetEnvPtr(proc->envval, env);
+    env->block.self = meth->recv;
+    env->block.klass = meth->defined_class;
+    env->block.iseq = method_get_iseq(meth->me->def);
     return procval;
 }
 
Index: test/ruby/test_proc.rb
===================================================================
--- test/ruby/test_proc.rb	(revision 48159)
+++ test/ruby/test_proc.rb	(revision 48160)
@@ -202,7 +202,10 @@ class TestProc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_proc.rb#L202
   def test_method_to_proc
     b = block()
     assert_equal "OK", b.call
-    assert_instance_of(Binding, b.binding, '[ruby-core:25589]')
+    b = b.binding
+    assert_instance_of(Binding, b, '[ruby-core:25589]')
+    bug10432 = '[ruby-core:65919] [Bug #10432]'
+    assert_same(self, b.receiver, bug10432)
   end
 
   def test_block_given_method

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]