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

49
error.c
View file

@ -357,47 +357,42 @@ warn_vsprintf(rb_encoding *enc, const char *file, int line, const char *fmt, va_
return rb_str_cat2(str, "\n"); 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 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; if (!NIL_P(ruby_verbose)) {
va_list args; with_warn_vsprintf(file, line, fmt) {
rb_write_warning_str(str);
if (NIL_P(ruby_verbose)) return; }
}
va_start(args, fmt);
str = warn_vsprintf(NULL, file, line, fmt, args);
va_end(args);
rb_write_warning_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; if (RTEST(ruby_verbose)) {
va_list args; with_warn_vsprintf(file, line, fmt) {
rb_write_warning_str(str);
if (!RTEST(ruby_verbose)) return; }
}
va_start(args, fmt);
str = warn_vsprintf(NULL, file, line, fmt, args);
va_end(args);
rb_write_warning_str(str);
} }
void void
rb_category_compile_warn(rb_warning_category_t category, const char *file, int line, const char *fmt, ...) rb_category_compile_warn(rb_warning_category_t category, const char *file, int line, const char *fmt, ...)
{ {
VALUE str; if (!NIL_P(ruby_verbose)) {
va_list args; with_warn_vsprintf(file, line, fmt) {
rb_warn_category(str, rb_warning_category_to_name(category));
if (NIL_P(ruby_verbose)) return; }
}
va_start(args, fmt);
str = warn_vsprintf(NULL, file, line, fmt, args);
va_end(args);
rb_warn_category(str, rb_warning_category_to_name(category));
} }
RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 2, 0) RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 2, 0)