ruby-changes:51608
From: nagachika <ko1@a...>
Date: Mon, 2 Jul 2018 09:31:33 +0900 (JST)
Subject: [ruby-changes:51608] nagachika:r63819 (ruby_2_5): merge revision(s) 61525, 61527, 63062, 63650: [Backport #14846]
nagachika 2018-07-02 09:31:27 +0900 (Mon, 02 Jul 2018) New Revision: 63819 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63819 Log: merge revision(s) 61525,61527,63062,63650: [Backport #14846] error.c: negative uplevel * error.c (rb_warn_m): negative uplevel is not allowed. [ruby-core:84568] [Bug #14262] error.c: limit depth * error.c (rb_warn_m): limit backtrace depth to reduce objects to be created but not used. 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. Fix condition in Kernel#warn when using uplevel * It causes SEGV on `warn("foo", uplevel: 100)`. * Found in a ruby/spec added by @andrykonchin in https://github.com/ruby/spec/pull/605 Modified directories: branches/ruby_2_5/ Modified files: branches/ruby_2_5/error.c branches/ruby_2_5/test/ruby/test_exception.rb branches/ruby_2_5/version.h Index: ruby_2_5/test/ruby/test_exception.rb =================================================================== --- ruby_2_5/test/ruby/test_exception.rb (revision 63818) +++ ruby_2_5/test/ruby/test_exception.rb (revision 63819) @@ -1007,6 +1007,8 @@ $stderr = $stdout; raise "\x82\xa0"') do https://github.com/ruby/ruby/blob/trunk/ruby_2_5/test/ruby/test_exception.rb#L1007 def test_kernel_warn_uplevel warning = capture_warning_warn {warn("test warning", uplevel: 0)} 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: ruby_2_5/version.h =================================================================== --- ruby_2_5/version.h (revision 63818) +++ ruby_2_5/version.h (revision 63819) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_5/version.h#L1 #define RUBY_VERSION "2.5.2" #define RUBY_RELEASE_DATE "2018-07-02" -#define RUBY_PATCHLEVEL 61 +#define RUBY_PATCHLEVEL 62 #define RUBY_RELEASE_YEAR 2018 #define RUBY_RELEASE_MONTH 7 Index: ruby_2_5/error.c =================================================================== --- ruby_2_5/error.c (revision 63818) +++ ruby_2_5/error.c (revision 63819) @@ -327,11 +327,11 @@ warning_write(int argc, VALUE *argv, VAL https://github.com/ruby/ruby/blob/trunk/ruby_2_5/error.c#L327 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]) { @@ -342,23 +342,32 @@ rb_warn_m(int argc, VALUE *argv, VALUE e https://github.com/ruby/ruby/blob/trunk/ruby_2_5/error.c#L342 uplevel = Qnil; } else if (!NIL_P(uplevel)) { - uplevel = LONG2NUM((long)NUM2ULONG(uplevel) + 1); - uplevel = rb_vm_thread_backtrace_locations(1, &uplevel, GET_THREAD()->self); - if (!NIL_P(uplevel)) { - uplevel = rb_ary_entry(uplevel, 0); + VALUE args[2]; + long lev = NUM2LONG(uplevel); + if (lev < 0) { + rb_raise(rb_eArgError, "negative level (%ld)", lev); + } + args[0] = LONG2NUM(lev + 1); + args[1] = INT2FIX(1); + location = rb_vm_thread_backtrace_locations(2, args, GET_THREAD()->self); + if (!NIL_P(location)) { + 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:%li: warning: ", + 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); Index: ruby_2_5 =================================================================== --- ruby_2_5 (revision 63818) +++ ruby_2_5 (revision 63819) Property changes on: ruby_2_5 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /trunk:r61525,61527,63062,63650 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/