1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Introduce with_warn_vsprintf macro

This commit is contained in:
S-H-GAMELINKS 2022-08-09 13:22:21 +09:00 committed by Nobuyoshi Nakada
parent b2205cd45c
commit 77fdb3a47d
Notes: git 2022-08-12 16:59:51 +09:00

43
error.c
View file

@ -357,48 +357,43 @@ warn_vsprintf(rb_encoding *enc, const char *file, int line, const char *fmt, va_
return rb_str_cat2(str, "\n");
}
#define with_warn_vsprintf(file, line, fmt) \
VALUE str; \
va_list args; \
va_start(args, fmt); \
str = warn_vsprintf(NULL, file, line, fmt, args); \
va_end(args);
void
rb_compile_warn(const char *file, int line, const char *fmt, ...)
{
VALUE str;
va_list args;
if (NIL_P(ruby_verbose)) return;
va_start(args, fmt);
str = warn_vsprintf(NULL, file, line, fmt, args);
va_end(args);
if (!NIL_P(ruby_verbose)) {
with_warn_vsprintf(file, line, fmt) {
rb_write_warning_str(str);
}
}
}
/* rb_compile_warning() reports only in verbose mode */
void
rb_compile_warning(const char *file, int line, const char *fmt, ...)
{
VALUE str;
va_list args;
if (!RTEST(ruby_verbose)) return;
va_start(args, fmt);
str = warn_vsprintf(NULL, file, line, fmt, args);
va_end(args);
if (RTEST(ruby_verbose)) {
with_warn_vsprintf(file, line, fmt) {
rb_write_warning_str(str);
}
}
}
void
rb_category_compile_warn(rb_warning_category_t category, const char *file, int line, const char *fmt, ...)
{
VALUE str;
va_list args;
if (NIL_P(ruby_verbose)) return;
va_start(args, fmt);
str = warn_vsprintf(NULL, file, line, fmt, args);
va_end(args);
if (!NIL_P(ruby_verbose)) {
with_warn_vsprintf(file, line, fmt) {
rb_warn_category(str, rb_warning_category_to_name(category));
}
}
}
RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 2, 0)
static VALUE