aboutsummaryrefslogtreecommitdiffstats
path: root/error.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-04-26 20:13:07 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-04-26 20:13:07 +0000
commit10c87aa3b5b5a9df59a25f5273345dde57f1b707 (patch)
treed42c11d21ee91d9efc91316b230ed0ea46e9d4cf /error.c
parentfe2959cb300018d3872a0c274aed1e14b5a9be45 (diff)
downloadruby-10c87aa3b5b5a9df59a25f5273345dde57f1b707.tar.gz
error.c: send as a single string
* error.c (rb_warn_m): send the arguments as a single string concatenated with a newline, so it can be filtered easily. [ruby-core:80875] [Feature #12944] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58490 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'error.c')
-rw-r--r--error.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/error.c b/error.c
index 6ec37f6273..709fcf3612 100644
--- a/error.c
+++ b/error.c
@@ -48,6 +48,7 @@ VALUE rb_eEAGAIN;
VALUE rb_eEWOULDBLOCK;
VALUE rb_eEINPROGRESS;
VALUE rb_mWarning;
+VALUE rb_cWarningBuffer;
static ID id_warn;
@@ -279,6 +280,13 @@ rb_enc_warning(rb_encoding *enc, const char *fmt, ...)
}
#endif
+static inline int
+end_with_asciichar(VALUE str, int c)
+{
+ return RB_TYPE_P(str, T_STRING) &&
+ rb_str_end_with_asciichar(str, c);
+}
+
/*
* call-seq:
* warn(msg, ...) -> nil
@@ -301,7 +309,14 @@ static VALUE
rb_warn_m(int argc, VALUE *argv, VALUE exc)
{
if (!NIL_P(ruby_verbose) && argc > 0) {
- rb_io_puts(argc, argv, rb_mWarning);
+ VALUE str = argv[0];
+ if (argc > 1 || !end_with_asciichar(str, '\n')) {
+ str = rb_str_tmp_new(0);
+ RBASIC_SET_CLASS(str, rb_cWarningBuffer);
+ rb_io_puts(argc, argv, str);
+ RBASIC_SET_CLASS(str, rb_cString);
+ }
+ rb_write_warning_str(str);
}
return Qnil;
}
@@ -2175,9 +2190,11 @@ Init_Exception(void)
rb_mWarning = rb_define_module("Warning");
rb_define_method(rb_mWarning, "warn", rb_warning_s_warn, 1);
- rb_define_method(rb_mWarning, "write", rb_warning_s_warn, 1);
rb_extend_object(rb_mWarning, rb_mWarning);
+ rb_cWarningBuffer = rb_define_class_under(rb_mWarning, "buffer", rb_cString);
+ rb_define_method(rb_cWarningBuffer, "write", rb_str_append, 1);
+
rb_define_global_function("warn", rb_warn_m, -1);
id_new = rb_intern_const("new");