ruby-changes:46379
From: eregon <ko1@a...>
Date: Thu, 27 Apr 2017 21:07:52 +0900 (JST)
Subject: [ruby-changes:46379] eregon:r58493 (trunk): Send the backtrace of the circular require warning as a single String to Warning.warn
eregon 2017-04-27 21:07:43 +0900 (Thu, 27 Apr 2017) New Revision: 58493 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58493 Log: Send the backtrace of the circular require warning as a single String to Warning.warn * load.c: send as a single string. * error.c: expose the string formatted by rb_warning as rb_warning_string(). * test/ruby/test_exception.rb: update tests. [ruby-core:80850] [Bug #13505] Modified files: trunk/error.c trunk/internal.h trunk/load.c trunk/test/ruby/test_exception.rb Index: load.c =================================================================== --- load.c (revision 58492) +++ load.c (revision 58493) @@ -743,8 +743,9 @@ load_lock(const char *ftptr) https://github.com/ruby/ruby/blob/trunk/load.c#L743 return (char *)""; } if (RTEST(ruby_verbose)) { - rb_warning("loading in progress, circular require considered harmful - %s", ftptr); - rb_backtrace_each(rb_warning_warn, rb_mWarning); + VALUE warning = rb_warning_string("loading in progress, circular require considered harmful - %s", ftptr); + rb_backtrace_each(rb_str_append, warning); + rb_warning_warn(rb_mWarning, warning); } switch (rb_thread_shield_wait((VALUE)data)) { case Qfalse: Index: error.c =================================================================== --- error.c (revision 58492) +++ error.c (revision 58493) @@ -268,6 +268,14 @@ rb_warning(const char *fmt, ...) https://github.com/ruby/ruby/blob/trunk/error.c#L268 } } +VALUE +rb_warning_string(const char *fmt, ...) +{ + with_warning_string(mesg, 0, fmt) { + } + return mesg; +} + #if 0 void rb_enc_warning(rb_encoding *enc, const char *fmt, ...) Index: internal.h =================================================================== --- internal.h (revision 58492) +++ internal.h (revision 58493) @@ -1140,6 +1140,7 @@ NORETURN(void ruby_deprecated_internal_f https://github.com/ruby/ruby/blob/trunk/internal.h#L1140 #define DEPRECATED_INTERNAL_FEATURE(func) \ (ruby_deprecated_internal_feature(func), UNREACHABLE) VALUE rb_warning_warn(VALUE mod, VALUE str); +VALUE rb_warning_string(const char *fmt, ...); /* eval.c */ VALUE rb_refinement_module_get_refined_class(VALUE module); Index: test/ruby/test_exception.rb =================================================================== --- test/ruby/test_exception.rb (revision 58492) +++ test/ruby/test_exception.rb (revision 58493) @@ -1005,9 +1005,9 @@ $stderr = $stdout; raise "\x82\xa0"') do https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L1005 $LOAD_PATH.pop $LOADED_FEATURES.delete(t) end + assert_equal(1, warning.size) assert_match(/circular require/, warning.first) - warning.pop while %r[lib/rubygems/core_ext/kernel_require.rb:] =~ warning.last - assert_operator(warning.last, :start_with?, "\tfrom #{path}:1:") + assert_match(/^\tfrom #{Regexp.escape(path)}:1:/, warning.first) end def test_undefined_backtrace -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/