[前][次][番号順一覧][スレッド一覧]

ruby-changes:72919

From: S-H-GAMELINKS <ko1@a...>
Date: Fri, 12 Aug 2022 16:59:40 +0900 (JST)
Subject: [ruby-changes:72919] 77fdb3a47d (master): Introduce with_warn_vsprintf macro

https://git.ruby-lang.org/ruby.git/commit/?id=77fdb3a47d

From 77fdb3a47d420eb66761d50db2244a10b1d7272a Mon Sep 17 00:00:00 2001
From: S-H-GAMELINKS <gamelinks007@g...>
Date: Tue, 9 Aug 2022 13:22:21 +0900
Subject: Introduce with_warn_vsprintf macro

---
 error.c | 49 ++++++++++++++++++++++---------------------------
 1 file changed, 22 insertions(+), 27 deletions(-)

diff --git a/error.c b/error.c
index 21a532a8fa..07fa04627e 100644
--- a/error.c
+++ b/error.c
@@ -357,47 +357,42 @@ warn_vsprintf(rb_encoding *enc, const char *file, int line, const char *fmt, va_ https://github.com/ruby/ruby/blob/trunk/error.c#L357
     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);
-    rb_write_warning_str(str);
+    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);
-    rb_write_warning_str(str);
+    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);
-    rb_warn_category(str, rb_warning_category_to_name(category));
+    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)
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]