ruby-changes:41961
From: nobu <ko1@a...>
Date: Wed, 9 Mar 2016 00:29:52 +0900 (JST)
Subject: [ruby-changes:41961] nobu:r54035 (trunk): vm_method.c: fix aliased original name
nobu 2016-03-09 00:29:48 +0900 (Wed, 09 Mar 2016) New Revision: 54035 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54035 Log: vm_method.c: fix aliased original name * vm_method.c (rb_alias): the original name should be properly available method_added method, set the name before calling the hook. Modified files: trunk/ChangeLog trunk/test/ruby/test_alias.rb trunk/vm_method.c Index: ChangeLog =================================================================== --- ChangeLog (revision 54034) +++ ChangeLog (revision 54035) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Mar 9 00:29:46 2016 Nobuyoshi Nakada <nobu@r...> + + * vm_method.c (rb_alias): the original name should be properly + available method_added method, set the name before calling the + hook. + Wed Mar 9 00:07:03 2016 Nobuyoshi Nakada <nobu@r...> * lib/logger.rb (Logger::LogDevice#initialize): define using Index: vm_method.c =================================================================== --- vm_method.c (revision 54034) +++ vm_method.c (revision 54035) @@ -1552,10 +1552,10 @@ rb_alias(VALUE klass, ID alias_name, ID https://github.com/ruby/ruby/blob/trunk/vm_method.c#L1552 if (visi == METHOD_VISI_UNDEF) visi = METHOD_ENTRY_VISI(orig_me); if (orig_me->defined_class == 0) { - rb_method_entry_t *alias_me; - - alias_me = rb_add_method(target_klass, alias_name, VM_METHOD_TYPE_ALIAS, (void *)rb_method_entry_clone(orig_me), visi); - alias_me->def->original_id = orig_me->called_id; + rb_method_entry_make(target_klass, alias_name, target_klass, visi, + VM_METHOD_TYPE_ALIAS, NULL, orig_me->called_id, + (void *)rb_method_entry_clone(orig_me)); + method_added(target_klass, alias_name); } else { rb_method_entry_t *alias_me; Index: test/ruby/test_alias.rb =================================================================== --- test/ruby/test_alias.rb (revision 54034) +++ test/ruby/test_alias.rb (revision 54035) @@ -203,4 +203,32 @@ class TestAlias < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_alias.rb#L203 assert_equal(obj.method(:bar), obj.method(:foo)) assert_equal(obj.method(:foo), obj.method(:bar)) end + + def test_alias_class_method_added + name = nil + k = Class.new { + def foo;end + def self.method_added(mid) + @name = instance_method(mid).original_name + end + alias bar foo + name = @name + } + assert_equal(:foo, k.instance_method(:bar).original_name) + assert_equal(:foo, name) + end + + def test_alias_module_method_added + name = nil + k = Module.new { + def foo;end + def self.method_added(mid) + @name = instance_method(mid).original_name + end + alias bar foo + name = @name + } + assert_equal(:foo, k.instance_method(:bar).original_name) + assert_equal(:foo, name) + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/