summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-27 08:17:26 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-27 08:17:26 +0000
commite45b215fdd16f4fefc8f97f2391ef532f10c8f50 (patch)
tree55ea62bd06a3c3ad12fab42fbededf22b9e84fa5
parent9bcf16f01a7d5d3b1e4c19b146a9426b44891a35 (diff)
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48160 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--proc.c10
-rw-r--r--test/ruby/test_proc.rb5
3 files changed, 20 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 69dca31c31..30a2513a61 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Mon Oct 27 17:17:24 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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@atdot.net>
* test/ruby/test_super.rb: add a test to check block passing.
diff --git a/proc.c b/proc.c
index 00512ec49c..a4b8c82a25 100644
--- a/proc.c
+++ b/proc.c
@@ -2365,7 +2365,10 @@ static VALUE
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)
* 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;
}
diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb
index 28ba8c9b57..17778dfede 100644
--- a/test/ruby/test_proc.rb
+++ b/test/ruby/test_proc.rb
@@ -202,7 +202,10 @@ class TestProc < Test::Unit::TestCase
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