ruby-changes:37418
From: marcandre <ko1@a...>
Date: Thu, 5 Feb 2015 04:03:18 +0900 (JST)
Subject: [ruby-changes:37418] marcandRe: r49499 (trunk): * vm_insnhelper.c: Fix one type of symbol leak with +send+
marcandre 2015-02-05 04:03:04 +0900 (Thu, 05 Feb 2015) New Revision: 49499 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49499 Log: * vm_insnhelper.c: Fix one type of symbol leak with +send+ Modified files: trunk/test/ruby/test_symbol.rb trunk/vm_insnhelper.c Index: vm_insnhelper.c =================================================================== --- vm_insnhelper.c (revision 49498) +++ vm_insnhelper.c (revision 49499) @@ -1526,10 +1526,7 @@ vm_call_opt_send(rb_thread_t *th, rb_con https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1526 sym = TOPN(i); - if (SYMBOL_P(sym)) { - ci->mid = SYM2ID(sym); - } - else if (!(ci->mid = rb_check_id(&sym))) { + if (!(ci->mid = rb_check_id(&sym))) { if (rb_method_basic_definition_p(CLASS_OF(ci->recv), idMethodMissing)) { VALUE exc = make_no_method_exception(rb_eNoMethodError, NULL, ci->recv, rb_long2int(ci->argc), &TOPN(i)); rb_exc_raise(exc); Index: test/ruby/test_symbol.rb =================================================================== --- test/ruby/test_symbol.rb (revision 49498) +++ test/ruby/test_symbol.rb (revision 49499) @@ -238,4 +238,24 @@ class TestSymbol < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_symbol.rb#L238 200_000.times { |i| i.to_s.to_sym } end; end + + def assert_no_immortal_symbol_created + delta = -Symbol.all_symbols.size + yield + GC.start + delta += Symbol.all_symbols.size + assert_equal 0, delta, "#{delta} immortal symbols were created" + end + + def test_symbol_send_leak_string + assert_no_immortal_symbol_created do + 10.times { 42.send "send should not leak #{i} - str" rescue nil } + end + end + + def test_symbol_send_leak_symbol + assert_no_immortal_symbol_created do + 10.times { 42.send "send should not leak #{i} - sym".to_sym rescue nil } + end + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/