Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use me->def instead of me for opt_table #4493

Merged
merged 2 commits into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion array.c
Original file line number Diff line number Diff line change
Expand Up @@ -8384,7 +8384,7 @@ Init_Array(void)
rb_define_method(rb_cArray, "each_index", rb_ary_each_index, 0);
rb_define_method(rb_cArray, "reverse_each", rb_ary_reverse_each, 0);
rb_define_method(rb_cArray, "length", rb_ary_length, 0);
rb_define_alias(rb_cArray, "size", "length");
rb_define_method(rb_cArray, "size", rb_ary_length, 0);
rb_define_method(rb_cArray, "empty?", rb_ary_empty_p, 0);
rb_define_method(rb_cArray, "find_index", rb_ary_index, -1);
rb_define_method(rb_cArray, "index", rb_ary_index, -1);
Expand Down
15 changes: 15 additions & 0 deletions test/ruby/test_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,21 @@ module M2
end;
end

def test_override_optimized_method_on_class_using_prepend
assert_separately(%w(--disable-gems), <<-'end;', timeout: 30)
# Bug #17725 [ruby-core:102884]
$VERBOSE = nil
String.prepend(Module.new)
class String
def + other
'blah blah'
end
end

assert_equal('blah blah', 'a' + 'b')
end;
end

def test_eqq
assert_operator(0.method(:<), :===, 5)
assert_not_operator(0.method(:<), :===, -5)
Expand Down
11 changes: 5 additions & 6 deletions vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1798,7 +1798,7 @@ rb_iter_break_value(VALUE val)

/* optimization: redefine management */

static st_table *vm_opt_method_table = 0;
static st_table *vm_opt_method_def_table = 0;
static st_table *vm_opt_mid_table = 0;

static int
Expand Down Expand Up @@ -1852,9 +1852,8 @@ rb_vm_check_redefinition_opt_method(const rb_method_entry_t *me, VALUE klass)
klass = RBASIC_CLASS(klass);
}
if (vm_redefinition_check_method_type(me->def)) {
if (st_lookup(vm_opt_method_table, (st_data_t)me, &bop)) {
int flag = vm_redefinition_check_flag(klass);

if (st_lookup(vm_opt_method_def_table, (st_data_t)me->def, &bop)) {
int flag = vm_redefinition_check_flag(klass);
ruby_vm_redefined_flag[bop] |= flag;
}
}
Expand Down Expand Up @@ -1885,7 +1884,7 @@ add_opt_method(VALUE klass, ID mid, VALUE bop)
const rb_method_entry_t *me = rb_method_entry_at(klass, mid);

if (me && vm_redefinition_check_method_type(me->def)) {
st_insert(vm_opt_method_table, (st_data_t)me, (st_data_t)bop);
st_insert(vm_opt_method_def_table, (st_data_t)me->def, (st_data_t)bop);
st_insert(vm_opt_mid_table, (st_data_t)mid, (st_data_t)Qtrue);
}
else {
Expand All @@ -1899,7 +1898,7 @@ vm_init_redefined_flag(void)
ID mid;
VALUE bop;

vm_opt_method_table = st_init_numtable();
vm_opt_method_def_table = st_init_numtable();
vm_opt_mid_table = st_init_numtable();

#define OP(mid_, bop_) (mid = id##mid_, bop = BOP_##bop_, ruby_vm_redefined_flag[bop] = 0)
Expand Down