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

ruby-changes:72838

From: Nobuyoshi <ko1@a...>
Date: Sat, 6 Aug 2022 11:46:54 +0900 (JST)
Subject: [ruby-changes:72838] 27173e3735 (master): Allow `RUBY_DEBUG_LOG` format to be empty

https://git.ruby-lang.org/ruby.git/commit/?id=27173e3735

From 27173e3735ff509dc8d9cc9b410baff84adf57dc Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Thu, 28 Jul 2022 16:50:26 +0900
Subject: Allow `RUBY_DEBUG_LOG` format to be empty

GCC warns of empty format strings, perhaps because they have no
effects in printf() and there are better ways than sprintf().
However, ruby_debug_log() adds informations other than the format,
this warning is not the case.
---
 thread.c       | 10 +++++-----
 thread_win32.c |  4 ++--
 vm_debug.h     |  9 +++++++++
 3 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/thread.c b/thread.c
index feb89d4352..b271128193 100644
--- a/thread.c
+++ b/thread.c
@@ -1353,14 +1353,14 @@ sleep_hrtime_until(rb_thread_t *th, rb_hrtime_t end, unsigned int fl) https://github.com/ruby/ruby/blob/trunk/thread.c#L1353
 void
 rb_thread_sleep_forever(void)
 {
-    RUBY_DEBUG_LOG("%s", "");
+    RUBY_DEBUG_LOG("");
     sleep_forever(GET_THREAD(), SLEEP_SPURIOUS_CHECK);
 }
 
 void
 rb_thread_sleep_deadly(void)
 {
-    RUBY_DEBUG_LOG("%s", "");
+    RUBY_DEBUG_LOG("");
     sleep_forever(GET_THREAD(), SLEEP_DEADLOCKABLE|SLEEP_SPURIOUS_CHECK);
 }
 
@@ -1384,7 +1384,7 @@ rb_thread_sleep_deadly_allow_spurious_wakeup(VALUE blocker, VALUE timeout, rb_hr https://github.com/ruby/ruby/blob/trunk/thread.c#L1384
         rb_fiber_scheduler_block(scheduler, blocker, timeout);
     }
     else {
-        RUBY_DEBUG_LOG("%s", "");
+        RUBY_DEBUG_LOG("");
         if (end) {
             sleep_hrtime_until(GET_THREAD(), end, SLEEP_SPURIOUS_CHECK);
         }
@@ -1481,7 +1481,7 @@ blocking_region_begin(rb_thread_t *th, struct rb_blocking_region_buffer *region, https://github.com/ruby/ruby/blob/trunk/thread.c#L1481
         th->status = THREAD_STOPPED;
         rb_ractor_blocking_threads_inc(th->ractor, __FILE__, __LINE__);
 
-        RUBY_DEBUG_LOG("%s", "");
+        RUBY_DEBUG_LOG("");
 
         RB_GC_SAVE_MACHINE_CONTEXT(th);
         thread_sched_to_waiting(TH_SCHED(th));
@@ -1509,7 +1509,7 @@ blocking_region_end(rb_thread_t *th, struct rb_blocking_region_buffer *region) https://github.com/ruby/ruby/blob/trunk/thread.c#L1509
         th->status = region->prev_status;
     }
 
-    RUBY_DEBUG_LOG("%s", "");
+    RUBY_DEBUG_LOG("");
     VM_ASSERT(th == GET_THREAD());
 }
 
diff --git a/thread_win32.c b/thread_win32.c
index cbb01d5d84..e9deff23cc 100644
--- a/thread_win32.c
+++ b/thread_win32.c
@@ -746,7 +746,7 @@ static unsigned long __stdcall https://github.com/ruby/ruby/blob/trunk/thread_win32.c#L746
 timer_thread_func(void *dummy)
 {
     rb_vm_t *vm = GET_VM();
-    RUBY_DEBUG_LOG("%s", "start");
+    RUBY_DEBUG_LOG("start");
     rb_w32_set_thread_description(GetCurrentThread(), L"ruby-timer-thread");
     while (WaitForSingleObject(timer_thread.lock,
                                TIME_QUANTUM_USEC/1000) == WAIT_TIMEOUT) {
@@ -754,7 +754,7 @@ timer_thread_func(void *dummy) https://github.com/ruby/ruby/blob/trunk/thread_win32.c#L754
         ruby_sigchld_handler(vm); /* probably no-op */
         rb_threadptr_check_signal(vm->ractor.main_thread);
     }
-    RUBY_DEBUG_LOG("%s", "end");
+    RUBY_DEBUG_LOG("end");
     return 0;
 }
 
diff --git a/vm_debug.h b/vm_debug.h
index 5956105648..9c7fc65f7c 100644
--- a/vm_debug.h
+++ b/vm_debug.h
@@ -86,6 +86,15 @@ void ruby_debug_log(const char *file, int line, const char *func_name, const cha https://github.com/ruby/ruby/blob/trunk/vm_debug.h#L86
 void ruby_debug_log_print(unsigned int n);
 bool ruby_debug_log_filter(const char *func_name, const char *file_name);
 
+#if RBIMPL_COMPILER_IS(GCC) && defined(__OPTIMIZE__)
+# define ruby_debug_log(...) \
+    RB_GNUC_EXTENSION_BLOCK( \
+        RBIMPL_WARNING_PUSH(); \
+        RBIMPL_WARNING_IGNORED(-Wformat-zero-length); \
+        ruby_debug_log(__VA_ARGS__); \
+        RBIMPL_WARNING_POP())
+#endif
+
 // convenient macro to log even if the USE_RUBY_DEBUG_LOG macro is not specified.
 // You can use this macro for temporary usage (you should not commit it).
 #define _RUBY_DEBUG_LOG(...) ruby_debug_log(__FILE__, __LINE__, RUBY_FUNCTION_NAME_STRING, "" __VA_ARGS__)
-- 
cgit v1.2.1


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

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