diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-02-22 05:05:22 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-02-22 05:05:22 +0000 |
commit | 669e9ac5ff2593b175bd6b0b30d482d3e2fbced3 (patch) | |
tree | 47b951148ab01012acec3e61406ffdb9310e9a51 | |
parent | d382c46a723cb191369707fd18b4bfa5f6709d1b (diff) |
merge revision(s) 44931: [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_1@45107 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | test/ruby/test_refinement.rb | 45 | ||||
-rw-r--r-- | version.h | 2 | ||||
-rw-r--r-- | vm_insnhelper.c | 7 | ||||
-rw-r--r-- | vm_method.c | 1 |
5 files changed, 63 insertions, 6 deletions
@@ -1,3 +1,17 @@ +Sat Feb 22 13:49:30 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. + Sat Feb 22 13:26:57 2014 Nobuyoshi Nakada <nobu@ruby-lang.org> * iseq.c (iseq_load): keep type_map to get rid of memory leak. diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb index 07a325c1b8..d535c47424 100644 --- a/test/ruby/test_refinement.rb +++ b/test/ruby/test_refinement.rb @@ -1107,6 +1107,51 @@ 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) + 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) + 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) @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.1.1" #define RUBY_RELEASE_DATE "2014-02-22" -#define RUBY_PATCHLEVEL 52 +#define RUBY_PATCHLEVEL 53 #define RUBY_RELEASE_YEAR 2014 #define RUBY_RELEASE_MONTH 2 diff --git a/vm_insnhelper.c b/vm_insnhelper.c index edf4e46652..1228b3f4df 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -1829,7 +1829,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; } } @@ -1838,11 +1838,8 @@ 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; } + goto start_method_dispatch; } else { klass = ci->me->klass; diff --git a/vm_method.c b/vm_method.c index fce8add6ef..ecded4aa2f 100644 --- a/vm_method.c +++ b/vm_method.c @@ -212,6 +212,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; } |