merge revision(s) r44931: [Backport #9452]

* vm_insnhelper.c (vm_call_method): should check ci->me->flag of
	  a refining method in case the method is private.
	  [ruby-core:60111] [Bug #9452]

	* vm_method.c (make_method_entry_refined): set me->flag of a refined
	  method entry to NOEX_PUBLIC in case the original method is private
	  and it is refined as a public method.  The original flag is stored
	  in me->def->body.orig_me, so it's OK to make a refined method
	  entry public.  [ruby-core:60111] [Bug #9452]

	* test/ruby/test_refinement.rb: related tests.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@44967 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagachika 2014-02-15 06:53:01 +00:00
parent b64a3e4120
commit ab530f056c
5 changed files with 67 additions and 8 deletions

View file

@ -1,3 +1,17 @@
Sat Feb 15 15:32:46 2014 Shugo Maeda <shugo@ruby-lang.org>
* vm_insnhelper.c (vm_call_method): should check ci->me->flag of
a refining method in case the method is private.
[ruby-core:60111] [Bug #9452]
* vm_method.c (make_method_entry_refined): set me->flag of a refined
method entry to NOEX_PUBLIC in case the original method is private
and it is refined as a public method. The original flag is stored
in me->def->body.orig_me, so it's OK to make a refined method
entry public. [ruby-core:60111] [Bug #9452]
* test/ruby/test_refinement.rb: related tests.
Tue Feb 11 23:21:02 2014 CHIKANAGA Tomoyuki <nagachika@ruby-lang.org>
* test/ruby/test_struct.rb (test_struct_question_mark): add a testcase

View file

@ -955,6 +955,53 @@ class TestRefinement < Test::Unit::TestCase
INPUT
end
def test_adding_private_method
bug9452 = '[ruby-core:60111] [Bug #9452]'
assert_in_out_err([], <<-INPUT, ["Success!", "NoMethodError"], [], bug9452)
$VERBOSE = nil #to suppress warning "Refinements are experimental, ..."
module R
refine Object do
def m
puts "Success!"
end
private(:m)
end
end
using R
m
42.m rescue p($!.class)
INPUT
end
def test_making_private_method_public
bug9452 = '[ruby-core:60111] [Bug #9452]'
assert_in_out_err([], <<-INPUT, ["Success!", "Success!"], [], bug9452)
$VERBOSE = nil #to suppress warning "Refinements are experimental, ..."
class Object
private
def m
end
end
module R
refine Object do
def m
puts "Success!"
end
end
end
using R
m
42.m
INPUT
end
private
def eval_using(mod, s)

View file

@ -1,10 +1,10 @@
#define RUBY_VERSION "2.0.0"
#define RUBY_RELEASE_DATE "2014-02-11"
#define RUBY_PATCHLEVEL 402
#define RUBY_RELEASE_DATE "2014-02-15"
#define RUBY_PATCHLEVEL 403
#define RUBY_RELEASE_YEAR 2014
#define RUBY_RELEASE_MONTH 2
#define RUBY_RELEASE_DAY 11
#define RUBY_RELEASE_DAY 15
#include "ruby/version.h"

View file

@ -1839,7 +1839,7 @@ vm_call_method(rb_thread_t *th, rb_control_frame_t *cfp, rb_call_info_t *ci)
ci->me = me;
ci->defined_class = defined_class;
if (me->def->type != VM_METHOD_TYPE_REFINED) {
goto normal_method_dispatch;
goto start_method_dispatch;
}
}
@ -1848,12 +1848,9 @@ vm_call_method(rb_thread_t *th, rb_control_frame_t *cfp, rb_call_info_t *ci)
ci->me = ci->me->def->body.orig_me;
if (UNDEFINED_METHOD_ENTRY_P(ci->me)) {
ci->me = 0;
}
goto start_method_dispatch;
}
else {
goto normal_method_dispatch;
}
}
else {
klass = ci->me->klass;
goto zsuper_method_dispatch;

View file

@ -203,6 +203,7 @@ make_method_entry_refined(rb_method_entry_t *me)
*new_def->body.orig_me = *me;
rb_vm_check_redefinition_opt_method(me, me->klass);
if (me->def) me->def->alias_count++;
me->flag = NOEX_WITH_SAFE(NOEX_PUBLIC);
me->def = new_def;
}