aboutsummaryrefslogtreecommitdiffstats
path: root/error.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-01-19 06:25:06 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-01-19 06:25:06 +0000
commit98cf54a4b55b65dbd8af2a86a572f02afb1701b8 (patch)
tree5d2b13d84e3681be40d9fbd47a5b31cdb2055587 /error.c
parent11aea79b64ed1b78c12b554cab5a4480d161fe9c (diff)
downloadruby-98cf54a4b55b65dbd8af2a86a572f02afb1701b8.tar.gz
Change Kernel#warn to call Warning.warn
This allows Warning.warn to filter/process warning messages generated by Kernel#warn. Currently, Warning.warn can only handle messages generated by the rb_warn/rb_warning C functions. The Kernel#warn API is different than the Warning.warn API, this tries to get similar behavior, but there are probably corner cases where the behavior is different. This makes str_end_with_asciichar in io.c no longer static so it can be called from error.c. [Feature #12944] Author: Jeremy Evans <code@jeremyevans.net> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57370 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'error.c')
-rw-r--r--error.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/error.c b/error.c
index ae0f79180c..d4c38f8cbb 100644
--- a/error.c
+++ b/error.c
@@ -42,6 +42,7 @@
VALUE rb_iseqw_local_variables(VALUE iseqval);
VALUE rb_iseqw_new(const rb_iseq_t *);
+int rb_str_end_with_asciichar(VALUE str, int c);
VALUE rb_eEAGAIN;
VALUE rb_eEWOULDBLOCK;
@@ -280,9 +281,11 @@ rb_enc_warning(rb_encoding *enc, const char *fmt, ...)
* call-seq:
* warn(msg, ...) -> nil
*
- * Displays each of the given messages followed by a record separator on
- * STDERR unless warnings have been disabled (for example with the
- * <code>-W0</code> flag).
+ * If warnings have been disabled (for example with the
+ * <code>-W0</code> flag), does nothing. Otherwise,
+ * converts each of the messages to strings, appends a newline
+ * character to the string if the string does not end in a newline,
+ * and calls <code>Warning.warn</code> with the string.
*
* warn("warning 1", "warning 2")
*
@@ -296,7 +299,15 @@ static VALUE
rb_warn_m(int argc, VALUE *argv, VALUE exc)
{
if (!NIL_P(ruby_verbose) && argc > 0) {
- rb_io_puts(argc, argv, rb_stderr);
+ int i;
+ VALUE str;
+ for (i = 0; i < argc; i++) {
+ str = rb_obj_as_string(argv[i]);
+ if (RSTRING_LEN(str) == 0 || !rb_str_end_with_asciichar(str, '\n')) {
+ str = rb_str_cat(rb_str_dup(str), "\n", 1);
+ }
+ rb_write_warning_str(str);
+ }
}
return Qnil;
}