Skip to content

Commit cf3896b

Browse files
committed
merge revision(s) 44931: [Backport ruby#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 ruby#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 ruby#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
1 parent 276b6b8 commit cf3896b

File tree

5 files changed

+63
-6
lines changed

5 files changed

+63
-6
lines changed

ChangeLog

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
Sat Feb 22 13:49:30 2014 Shugo Maeda <[email protected]>
2+
3+
* vm_insnhelper.c (vm_call_method): should check ci->me->flag of
4+
a refining method in case the method is private.
5+
[ruby-core:60111] [Bug #9452]
6+
7+
* vm_method.c (make_method_entry_refined): set me->flag of a refined
8+
method entry to NOEX_PUBLIC in case the original method is private
9+
and it is refined as a public method. The original flag is stored
10+
in me->def->body.orig_me, so it's OK to make a refined method
11+
entry public. [ruby-core:60111] [Bug #9452]
12+
13+
* test/ruby/test_refinement.rb: related tests.
14+
115
Sat Feb 22 13:26:57 2014 Nobuyoshi Nakada <[email protected]>
216

317
* iseq.c (iseq_load): keep type_map to get rid of memory leak.

test/ruby/test_refinement.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,51 @@ def foo
11071107
INPUT
11081108
end
11091109

1110+
def test_adding_private_method
1111+
bug9452 = '[ruby-core:60111] [Bug #9452]'
1112+
1113+
assert_in_out_err([], <<-INPUT, ["Success!", "NoMethodError"], [], bug9452)
1114+
module R
1115+
refine Object do
1116+
def m
1117+
puts "Success!"
1118+
end
1119+
1120+
private(:m)
1121+
end
1122+
end
1123+
1124+
using R
1125+
1126+
m
1127+
42.m rescue p($!.class)
1128+
INPUT
1129+
end
1130+
1131+
def test_making_private_method_public
1132+
bug9452 = '[ruby-core:60111] [Bug #9452]'
1133+
1134+
assert_in_out_err([], <<-INPUT, ["Success!", "Success!"], [], bug9452)
1135+
class Object
1136+
private
1137+
def m
1138+
end
1139+
end
1140+
1141+
module R
1142+
refine Object do
1143+
def m
1144+
puts "Success!"
1145+
end
1146+
end
1147+
end
1148+
1149+
using R
1150+
m
1151+
42.m
1152+
INPUT
1153+
end
1154+
11101155
private
11111156

11121157
def eval_using(mod, s)

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#define RUBY_VERSION "2.1.1"
22
#define RUBY_RELEASE_DATE "2014-02-22"
3-
#define RUBY_PATCHLEVEL 52
3+
#define RUBY_PATCHLEVEL 53
44

55
#define RUBY_RELEASE_YEAR 2014
66
#define RUBY_RELEASE_MONTH 2

vm_insnhelper.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,7 +1829,7 @@ vm_call_method(rb_thread_t *th, rb_control_frame_t *cfp, rb_call_info_t *ci)
18291829
ci->me = me;
18301830
ci->defined_class = defined_class;
18311831
if (me->def->type != VM_METHOD_TYPE_REFINED) {
1832-
goto normal_method_dispatch;
1832+
goto start_method_dispatch;
18331833
}
18341834
}
18351835

@@ -1838,11 +1838,8 @@ vm_call_method(rb_thread_t *th, rb_control_frame_t *cfp, rb_call_info_t *ci)
18381838
ci->me = ci->me->def->body.orig_me;
18391839
if (UNDEFINED_METHOD_ENTRY_P(ci->me)) {
18401840
ci->me = 0;
1841-
goto start_method_dispatch;
1842-
}
1843-
else {
1844-
goto normal_method_dispatch;
18451841
}
1842+
goto start_method_dispatch;
18461843
}
18471844
else {
18481845
klass = ci->me->klass;

vm_method.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ make_method_entry_refined(rb_method_entry_t *me)
212212
*new_def->body.orig_me = *me;
213213
rb_vm_check_redefinition_opt_method(me, me->klass);
214214
if (me->def) me->def->alias_count++;
215+
me->flag = NOEX_WITH_SAFE(NOEX_PUBLIC);
215216
me->def = new_def;
216217
}
217218

0 commit comments

Comments
 (0)