ruby-changes:48061
From: nobu <ko1@a...>
Date: Fri, 13 Oct 2017 10:34:57 +0900 (JST)
Subject: [ruby-changes:48061] nobu:r60175 (trunk): error.c: infinite recursion at Warning#warn
nobu 2017-10-13 10:34:52 +0900 (Fri, 13 Oct 2017) New Revision: 60175 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60175 Log: error.c: infinite recursion at Warning#warn * error.c (rb_warn_m): write the message to rb_stderr directly, to get rid of infinite recursion when called on Warning module itself, by super in redefined Warning#warn. [ruby-dev:50293] [Bug #14006] Modified files: trunk/error.c trunk/test/ruby/test_exception.rb Index: error.c =================================================================== --- error.c (revision 60174) +++ error.c (revision 60175) @@ -329,7 +329,13 @@ rb_warn_m(int argc, VALUE *argv, VALUE e https://github.com/ruby/ruby/blob/trunk/error.c#L329 rb_io_puts(argc, argv, str); RBASIC_SET_CLASS(str, rb_cString); } - rb_write_warning_str(str); + if (exc == rb_mWarning) { + rb_must_asciicompat(str); + rb_write_error_str(str); + } + else { + rb_write_warning_str(str); + } } return Qnil; } Index: test/ruby/test_exception.rb =================================================================== --- test/ruby/test_exception.rb (revision 60174) +++ test/ruby/test_exception.rb (revision 60175) @@ -1034,6 +1034,20 @@ $stderr = $stdout; raise "\x82\xa0"') do https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L1034 assert_match(/^\tfrom #{Regexp.escape(path)}:1:/, warning.first) end + def test_warning_warn_super + assert_in_out_err(%[-W0], "#{<<~"{#"}\n#{<<~'};'}", [], /instance variable @a not initialized/) + {# + module Warning + def warn(message) + super + end + end + + $VERBOSE = true + @a + }; + end + def test_undefined_backtrace assert_separately([], "#{<<-"begin;"}\n#{<<-"end;"}") begin; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/