error.c: warn_vsprintf
* error.c (warn_vsprintf, warning_string): share common code. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54630 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5a0543e87a
commit
ec2f63167e
31
error.c
31
error.c
@ -135,58 +135,53 @@ rb_compile_error_append(const char *fmt, ...)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static VALUE
|
||||||
compile_warn_print(const char *file, int line, const char *fmt, va_list args)
|
warn_vsprintf(rb_encoding *enc, const char *file, int line, const char *fmt, va_list args)
|
||||||
{
|
{
|
||||||
VALUE str;
|
VALUE str;
|
||||||
|
|
||||||
str = compile_vsprintf(NULL, "warning: ", file, line, fmt, args);
|
str = compile_vsprintf(enc, "warning: ", file, line, fmt, args);
|
||||||
rb_str_cat2(str, "\n");
|
return rb_str_cat2(str, "\n");
|
||||||
rb_write_error_str(str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
rb_compile_warn(const char *file, int line, const char *fmt, ...)
|
rb_compile_warn(const char *file, int line, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
|
VALUE str;
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
if (NIL_P(ruby_verbose)) return;
|
if (NIL_P(ruby_verbose)) return;
|
||||||
|
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
compile_warn_print(file, line, fmt, args);
|
str = warn_vsprintf(NULL, file, line, fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
rb_write_error_str(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* rb_compile_warning() reports only in verbose mode */
|
/* rb_compile_warning() reports only in verbose mode */
|
||||||
void
|
void
|
||||||
rb_compile_warning(const char *file, int line, const char *fmt, ...)
|
rb_compile_warning(const char *file, int line, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
|
VALUE str;
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
if (!RTEST(ruby_verbose)) return;
|
if (!RTEST(ruby_verbose)) return;
|
||||||
|
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
compile_warn_print(file, line, fmt, args);
|
str = warn_vsprintf(NULL, file, line, fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
rb_write_error_str(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
warning_string(rb_encoding *enc, const char *fmt, va_list args)
|
warning_string(rb_encoding *enc, const char *fmt, va_list args)
|
||||||
{
|
{
|
||||||
VALUE str = rb_enc_str_new(0, 0, enc);
|
|
||||||
int line;
|
int line;
|
||||||
VALUE file = rb_source_location(&line);
|
VALUE file = rb_source_location(&line);
|
||||||
|
|
||||||
if (!NIL_P(file)) {
|
return warn_vsprintf(enc,
|
||||||
str = rb_str_append(str, file);
|
NIL_P(file) ? NULL : RSTRING_PTR(file), line,
|
||||||
if (line) rb_str_catf(str, ":%d", line);
|
fmt, args);
|
||||||
rb_str_cat2(str, ": ");
|
|
||||||
}
|
|
||||||
|
|
||||||
rb_str_cat2(str, "warning: ");
|
|
||||||
rb_str_vcatf(str, fmt, args);
|
|
||||||
rb_str_cat2(str, "\n");
|
|
||||||
return str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user