aboutsummaryrefslogtreecommitdiffstats
path: root/error.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-04-02 11:39:10 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-04-02 11:39:10 +0000
commit26fc2525a40495eb432cf8eedb2e812d8b2639e1 (patch)
treed46c7c2cfbd697cf804ab9eaed0f3436c4deb1fb /error.c
parent544605f0a361a2867c1aa23fea3e14a512cede4d (diff)
downloadruby-26fc2525a40495eb432cf8eedb2e812d8b2639e1.tar.gz
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63062 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'error.c')
-rw-r--r--error.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/error.c b/error.c
index 058446d60b..ba6f1ea689 100644
--- a/error.c
+++ b/error.c
@@ -348,11 +348,11 @@ warning_write(int argc, VALUE *argv, VALUE buf)
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 exc)
}
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);