Project

General

Profile

Feature #12026 » 0001-Add-WARNING_PROCESSOR-for-processing-warnings.patch

jeremyevans0 (Jeremy Evans), 04/09/2016 10:26 PM

View differences:

error.c
VALUE rb_eEWOULDBLOCK;
VALUE rb_eEINPROGRESS;
static ID id_call;
extern const char ruby_description[];
static const char REPORTBUG_MSG[] =
......
}
static void
rb_write_warning_str(VALUE str)
{
VALUE filter = rb_gv_get("$WARNING_PROCESSOR");
if (NIL_P(filter)) {
rb_write_error_str(str);
} else {
rb_funcall(filter, id_call, 1, str);
}
}
static void
compile_warn_print(const char *file, int line, const char *fmt, va_list args)
{
VALUE str;
str = compile_snprintf(NULL, "warning: ", file, line, fmt, args);
rb_str_cat2(str, "\n");
rb_write_error_str(str);
rb_write_warning_str(str);
}
void
......
va_start(args, fmt);
mesg = warning_string(0, fmt, args);
va_end(args);
rb_write_error_str(mesg);
rb_write_warning_str(mesg);
}
void
......
va_start(args, fmt);
mesg = warning_string(enc, fmt, args);
va_end(args);
rb_write_error_str(mesg);
rb_write_warning_str(mesg);
}
/* rb_warning() reports only in verbose mode */
......
va_start(args, fmt);
mesg = warning_string(0, fmt, args);
va_end(args);
rb_write_error_str(mesg);
rb_write_warning_str(mesg);
}
#if 0
......
va_start(args, fmt);
mesg = warning_string(enc, fmt, args);
va_end(args);
rb_write_error_str(mesg);
rb_write_warning_str(mesg);
}
#endif
......
rb_define_singleton_method(rb_eSystemCallError, "===", syserr_eqq, 1);
rb_mErrno = rb_define_module("Errno");
rb_gv_set("$WARNING_PROCESSOR", Qnil);
rb_define_global_function("warn", rb_warn_m, -1);
......
id_Errno = rb_intern_const("Errno");
id_errno = rb_intern_const("errno");
id_i_path = rb_intern_const("@path");
id_call = rb_intern_const("call");
id_iseq = rb_make_internal_id();
}
......
va_end(args);
rb_str_set_len(mesg, RSTRING_LEN(mesg)-1);
rb_str_catf(mesg, ": %s\n", strerror(errno_save));
rb_write_error_str(mesg);
rb_write_warning_str(mesg);
errno = errno_save;
}
......
va_end(args);
rb_str_set_len(mesg, RSTRING_LEN(mesg)-1);
rb_str_catf(mesg, ": %s\n", strerror(errno_save));
rb_write_error_str(mesg);
rb_write_warning_str(mesg);
errno = errno_save;
}
test/ruby/test_module.rb
end
end
def test_uninitialized_instance_variable_warning_processor
a = AttrTest.new
$WARNING_PROCESSOR = lambda do |str|
unless str =~ /instance variable @ivar not initialized/
$stderr << str
end
end
assert_warning '' do
assert_nil(a.ivar)
end
assert_warning /instance variable @ivar2 not initialized/ do
assert_nil(a.instance_variable_get(:@ivar2))
end
ensure
$WARNING_PROCESSOR = nil
end
def test_uninitialized_attr
a = AttrTest.new
assert_warning '' do
(2-2/2)