diff options
author | NAKAMURA Usaku <usa@ruby-lang.org> | 2022-03-19 22:34:37 +0900 |
---|---|---|
committer | NAKAMURA Usaku <usa@ruby-lang.org> | 2022-03-19 22:34:37 +0900 |
commit | 5da2a3e31699570ae1a951c8bbc489040051d19e (patch) | |
tree | 0bd7aebaaf1440313d6a8af3116b2081420236d7 /test | |
parent | 2d886af0a55a99bf3c12ec82c1b7a804bec9d395 (diff) |
merge revision(s) 7ff1bf317887c0d7b21e91ad548d07b9f05c540c,e89d80702bd98a8276243a7fcaa2a158b3bfb659: [Backport #18516]
An alias can suppress method redefinition warning
---
test/ruby/test_alias.rb | 11 +++++++++++
1 file changed, 11 insertions(+)
Fix memory leak at the same named alias [Bug #18516]
When aliasing a method to the same name method, set a separate bit
flag on that method definition, instead of the reference count
increment. Although this kind of alias has no actual effect at
runtime, is used as the hack to suppress the method re-definition
warning.
---
method.h | 1 +
test/ruby/test_alias.rb | 18 ++++++++++++++++++
vm_method.c | 9 ++++++++-
3 files changed, 27 insertions(+), 1 deletion(-)
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_alias.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/ruby/test_alias.rb b/test/ruby/test_alias.rb index 33fb82e1d7..1acf12f7f3 100644 --- a/test/ruby/test_alias.rb +++ b/test/ruby/test_alias.rb @@ -227,4 +227,33 @@ class TestAlias < Test::Unit::TestCase assert_equal(:foo, k.instance_method(:bar).original_name) assert_equal(:foo, name) end + + def test_alias_suppressing_redefinition + assert_in_out_err(%w[-w], "#{<<~"begin;"}\n#{<<~'end;'}") + begin; + class A + def foo; end + alias foo foo + def foo; end + end + end; + end + + def test_alias_memory_leak + assert_no_memory_leak([], "#{<<~"begin;"}", "#{<<~'end;'}", rss: true) + begin; + class A + 500.times do + 1000.times do |i| + define_method(:"foo_#{i}") {} + + alias :"foo_#{i}" :"foo_#{i}" + + remove_method :"foo_#{i}" + end + GC.start + end + end + end; + end end |