ruby-changes:50855
From: nobu <ko1@a...>
Date: Mon, 2 Apr 2018 20:39:15 +0900 (JST)
Subject: [ruby-changes:50855] nobu:r63062 (trunk): error.c: prepend "warning: " always
nobu 2018-04-02 20:39:10 +0900 (Mon, 02 Apr 2018) New Revision: 63062 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63062 Log: error.c: prepend "warning: " always * error.c (rb_warn_m): prepend the string "warning: " if uplevel keyword is given, even if caller file and line information are not available. Modified files: trunk/error.c trunk/test/ruby/test_exception.rb Index: test/ruby/test_exception.rb =================================================================== --- test/ruby/test_exception.rb (revision 63061) +++ test/ruby/test_exception.rb (revision 63062) @@ -1121,6 +1121,7 @@ $stderr = $stdout; raise "\x82\xa0"') do https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L1121 warning = capture_warning_warn {obj.w(1)} assert_equal("#{__FILE__}:#{__LINE__-1}: warning: test warning\n", warning[0]) assert_raise(ArgumentError) {warn("test warning", uplevel: -1)} + assert_in_out_err(["-e", "warn 'ok', uplevel: 1"], '', [], /warning:/) end def test_warning_warn_invalid_argument Index: error.c =================================================================== --- error.c (revision 63061) +++ error.c (revision 63062) @@ -348,11 +348,11 @@ warning_write(int argc, VALUE *argv, VAL https://github.com/ruby/ruby/blob/trunk/error.c#L348 static VALUE rb_warn_m(int argc, VALUE *argv, VALUE exc) { - VALUE opts, uplevel = Qnil; + VALUE opts, location = Qnil; if (!NIL_P(ruby_verbose) && argc > 0 && (argc = rb_scan_args(argc, argv, "*:", NULL, &opts)) > 0) { - VALUE str = argv[0]; + VALUE str = argv[0], uplevel = Qnil; if (!NIL_P(opts)) { static ID kwds[1]; if (!kwds[0]) { @@ -370,22 +370,25 @@ rb_warn_m(int argc, VALUE *argv, VALUE e https://github.com/ruby/ruby/blob/trunk/error.c#L370 } args[0] = LONG2NUM(lev + 1); args[1] = INT2FIX(1); - uplevel = rb_vm_thread_backtrace_locations(2, args, GET_THREAD()->self); + location = rb_vm_thread_backtrace_locations(2, args, GET_THREAD()->self); if (!NIL_P(uplevel)) { - uplevel = rb_ary_entry(uplevel, 0); + location = rb_ary_entry(location, 0); } } } if (argc > 1 || !NIL_P(uplevel) || !end_with_asciichar(str, '\n')) { + VALUE path; if (NIL_P(uplevel)) { str = rb_str_tmp_new(0); } + else if (NIL_P(location) || + NIL_P(path = rb_funcall(location, rb_intern("path"), 0))) { + str = rb_str_new_cstr("warning: "); + } else { - VALUE path; - path = rb_funcall(uplevel, rb_intern("path"), 0); str = rb_sprintf("%s:%ld: warning: ", rb_string_value_ptr(&path), - NUM2LONG(rb_funcall(uplevel, rb_intern("lineno"), 0))); + NUM2LONG(rb_funcall(location, rb_intern("lineno"), 0))); } RBASIC_SET_CLASS(str, rb_cWarningBuffer); rb_io_puts(argc, argv, str); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/