Feature #12944 » 0001-Change-Kernel-warn-to-call-Warning.warn.patch
| error.c | ||
|---|---|---|
|
VALUE rb_iseqw_local_variables(VALUE iseqval);
|
||
|
VALUE rb_iseqw_new(const rb_iseq_t *);
|
||
|
int str_end_with_asciichar(VALUE str, int c);
|
||
|
VALUE rb_eEAGAIN;
|
||
|
VALUE rb_eEWOULDBLOCK;
|
||
|
VALUE rb_eEINPROGRESS;
|
||
|
VALUE rb_mWarning;
|
||
|
static ID id_warn;
|
||
|
static ID id_warn, id_flatten_b;
|
||
|
extern const char ruby_description[];
|
||
| ... | ... | |
|
* 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,
|
||
|
* flattens the array of arguments and converts the
|
||
|
* entries to strings, makes sure all strings end with
|
||
|
* a newline, joins all strings into a single string,
|
||
|
* and calls <code>Warning.warn</code> with the
|
||
|
* resulting string.
|
||
|
*
|
||
|
* warn("warning 1", "warning 2")
|
||
|
* warn(["warning 1\n", "warning 2"])
|
||
|
* warn("warning 1", "warning 2\n")
|
||
|
*
|
||
|
* <em>produces:</em>
|
||
|
* <em>all call <code>Warning.warn</code> with:</em>
|
||
|
*
|
||
|
* warning 1
|
||
|
* warning 2
|
||
|
* "warning 1\nwarning 2\n"
|
||
|
*/
|
||
|
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;
|
||
|
VALUE ary = rb_ary_new_from_values(argc, argv);
|
||
|
rb_funcall(ary, id_flatten_b, 0);
|
||
|
Check_Type(ary, T_ARRAY);
|
||
|
argc = RARRAY_LEN(ary);
|
||
|
argv = RARRAY_PTR(ary);
|
||
|
for(i = 0; i < argc; i++) {
|
||
|
str = rb_obj_as_string(argv[i]);
|
||
|
if (RSTRING_LEN(str) == 0 || !str_end_with_asciichar(str, '\n')) {
|
||
|
str = rb_str_cat(rb_str_dup(str), "\n", 1);
|
||
|
}
|
||
|
rb_ary_store(ary, i, str);
|
||
|
}
|
||
|
rb_write_warning_str(rb_ary_join(ary, rb_str_new("", 0)));
|
||
|
}
|
||
|
return Qnil;
|
||
|
}
|
||
| ... | ... | |
|
id_errno = rb_intern_const("errno");
|
||
|
id_i_path = rb_intern_const("@path");
|
||
|
id_warn = rb_intern_const("warn");
|
||
|
id_flatten_b = rb_intern_const("flatten!");
|
||
|
id_iseq = rb_make_internal_id();
|
||
|
}
|
||
| io.c | ||
|---|---|---|
|
}
|
||
|
static int
|
||
|
int
|
||
|
str_end_with_asciichar(VALUE str, int c)
|
||
|
{
|
||
|
long len = RSTRING_LEN(str);
|
||