summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorNARUSE, Yui <naruse@airemix.jp>2022-02-03 08:04:57 +0900
committerNARUSE, Yui <naruse@airemix.jp>2022-02-03 08:04:57 +0900
commit42c9ef769f210d88241a114395dd5ffc27b2fb87 (patch)
treef264115c882c59b101cb8740358b5870f5ca1744 /test/ruby
parent7bef8ed183a336b040f051d7c2133b93364920c6 (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/ruby')
-rw-r--r--test/ruby/test_alias.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/ruby/test_alias.rb b/test/ruby/test_alias.rb
index 271d552bf5..99f2223b49 100644
--- a/test/ruby/test_alias.rb
+++ b/test/ruby/test_alias.rb
@@ -253,4 +253,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
ef='/ruby.git/commit/symbol.c?h=v3_3_0_preview3&id=65075dfe3adbb834d9282c01ba9b0630e2752450'>symbol.c: ids arraynobu 2014-10-14symbol.c: immortal IDsnobu 2014-10-14symbol.c: rename rb_str_dynamic_internnobu 2014-10-06symbol.c: junk-base attrsetnobu 2014-09-19symbol.c: fix dynamic attrset IDnobu 2014-09-08symbol.c (rb_intern_cstr_without_pindown): check dsymbol on returnnormal 2014-08-30internal.h: WARN_UNUSED_RESULTnobu 2014-08-30symbol.c (rb_sym2id): do not return garbage objectnormal 2014-08-16string.c: rb_setup_fake_strnobu 2014-08-15* string.c (setup_fake_str): fake strings should not set class byko1 2014-08-04symbol.c: move macrosnobu 2014-07-27symbol.c: wrap global_symbols tablesnobu 2014-07-27symbol.c: return the results directlynobu 2014-07-25symbol.c (dsymbol_check): remove unneeded semi-colonnormal 2014-07-11symbol.c: remove dependency on parse.hnobu 2014-07-09* symbol.c: remove rb_gc_mark_symbols().ko1 2014-07-09symbol.c, symbol.h: split from parse.ynobu