ruby-changes:13988
From: shugo <ko1@a...>
Date: Mon, 16 Nov 2009 16:01:59 +0900 (JST)
Subject: [ruby-changes:13988] Ruby:r25796 (trunk): * vm_insnhelper.c (vm_call_method): protected singleton methods of
shugo 2009-11-16 16:01:44 +0900 (Mon, 16 Nov 2009) New Revision: 25796 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=25796 Log: * vm_insnhelper.c (vm_call_method): protected singleton methods of an object should not be able to called from other instances of the class of the object. [ruby-core:26761] * vm_eval.c (rb_method_call_status): ditto. * test/ruby/test_module.rb (test_protected_singleton_method): ditto. Modified files: trunk/ChangeLog trunk/test/ruby/test_module.rb trunk/vm_eval.c trunk/vm_insnhelper.c Index: ChangeLog =================================================================== --- ChangeLog (revision 25795) +++ ChangeLog (revision 25796) @@ -1,3 +1,13 @@ +Mon Nov 16 15:51:53 2009 Shugo Maeda <shugo@r...> + + * vm_insnhelper.c (vm_call_method): protected singleton methods of + an object should not be able to called from other instances of the + class of the object. [ruby-core:26761] + + * vm_eval.c (rb_method_call_status): ditto. + + * test/ruby/test_module.rb (test_protected_singleton_method): ditto. + Mon Nov 16 14:03:53 2009 wanabe <s.wanabe@g...> * io.c (read_all): shift read buffer if exception occured. Index: vm_eval.c =================================================================== --- vm_eval.c (revision 25795) +++ vm_eval.c (revision 25796) @@ -343,7 +343,7 @@ if (self == Qundef) { self = th->cfp->self; } - if (!rb_obj_is_kind_of(self, rb_class_real(defined_class))) { + if (!rb_obj_is_kind_of(self, defined_class)) { return NOEX_PROTECTED; } } Index: vm_insnhelper.c =================================================================== --- vm_insnhelper.c (revision 25795) +++ vm_insnhelper.c (revision 25796) @@ -623,7 +623,7 @@ defined_class = RBASIC(defined_class)->klass; } - if (!rb_obj_is_kind_of(cfp->self, rb_class_real(defined_class))) { + if (!rb_obj_is_kind_of(cfp->self, defined_class)) { val = vm_method_missing(th, id, recv, num, blockptr, NOEX_PROTECTED); } else { Index: test/ruby/test_module.rb =================================================================== --- test/ruby/test_module.rb (revision 25795) +++ test/ruby/test_module.rb (revision 25796) @@ -854,4 +854,28 @@ end assert_equal("", stderr) end + + def test_protected_singleton_method + klass = Class.new + x = klass.new + class << x + protected + + def foo + end + end + assert_raise(NoMethodError) do + x.foo + end + klass.send(:define_method, :bar) do + x.foo + end + assert_nothing_raised do + x.bar + end + y = klass.new + assert_raise(NoMethodError) do + y.bar + end + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/