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

ruby-changes:65219

From: Nobuyoshi <ko1@a...>
Date: Wed, 10 Feb 2021 19:45:29 +0900 (JST)
Subject: [ruby-changes:65219] 4b6347ab39 (master): Compile debugging code for time always

https://git.ruby-lang.org/ruby.git/commit/?id=4b6347ab39

From 4b6347ab3907850769aa8e93674a4c0a4a18c668 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Tue, 9 Feb 2021 13:59:31 +0900
Subject: Compile debugging code for time always

---
 time.c | 40 ++++++++++++++++++++++++++--------------
 1 file changed, 26 insertions(+), 14 deletions(-)

diff --git a/time.c b/time.c
index 1c93be1..d75c832 100644
--- a/time.c
+++ b/time.c
@@ -2998,24 +2998,35 @@ timegm_noleapsecond(struct tm *tm) https://github.com/ruby/ruby/blob/trunk/time.c#L2998
 #define DEBUG_GUESSRANGE
 #endif
 
+static const bool debug_guessrange =
 #ifdef DEBUG_GUESSRANGE
-#define DEBUG_REPORT_GUESSRANGE fprintf(stderr, "find time guess range: %ld - %ld : %"PRI_TIMET_PREFIX"u\n", guess_lo, guess_hi, (unsigned_time_t)(guess_hi-guess_lo))
+    true;
 #else
-#define DEBUG_REPORT_GUESSRANGE
+    false;
 #endif
 
+#define DEBUG_REPORT_GUESSRANGE (void)\
+    (debug_guessrange ? \
+     fprintf(stderr, "find time guess range: %ld - %ld : %"PRI_TIMET_PREFIX"u\n", \
+             guess_lo, guess_hi, (unsigned_time_t)(guess_hi-guess_lo)) : 0)
+
+static const bool debug_find_time_numguess =
 #ifdef DEBUG_FIND_TIME_NUMGUESS
-#define DEBUG_FIND_TIME_NUMGUESS_INC find_time_numguess++,
+    true;
+#else
+    false;
+#endif
+
+#define DEBUG_FIND_TIME_NUMGUESS_INC \
+    (void)(debug_find_time_numguess && find_time_numguess++),
 static unsigned long long find_time_numguess;
 
 static VALUE
 find_time_numguess_getter(ID name, VALUE *data)
 {
-    return ULL2NUM(find_time_numguess);
+    unsigned long long *numguess = (void *)data;
+    return ULL2NUM(*numguess);
 }
-#else
-#define DEBUG_FIND_TIME_NUMGUESS_INC
-#endif
 
 static const char *
 find_time_t(struct tm *tptr, int utc_p, time_t *tp)
@@ -3163,10 +3174,10 @@ find_time_t(struct tm *tptr, int utc_p, time_t *tp) https://github.com/ruby/ruby/blob/trunk/time.c#L3174
             }
             if (guess <= guess_lo || guess_hi <= guess) {
                 /* Previous guess is invalid. try binary search. */
-#ifdef DEBUG_GUESSRANGE
-                if (guess <= guess_lo) fprintf(stderr, "too small guess: %ld <= %ld\n", guess, guess_lo);
-                if (guess_hi <= guess) fprintf(stderr, "too big guess: %ld <= %ld\n", guess_hi, guess);
-#endif
+                if (debug_guessrange) {
+                    if (guess <= guess_lo) fprintf(stderr, "too small guess: %ld <= %ld\n", guess, guess_lo);
+                    if (guess_hi <= guess) fprintf(stderr, "too big guess: %ld <= %ld\n", guess_hi, guess);
+                }
                 status = 0;
                 goto binsearch;
             }
@@ -5808,9 +5819,10 @@ Init_Time(void) https://github.com/ruby/ruby/blob/trunk/time.c#L5819
     rb_define_private_method(rb_cTime, "marshal_load", time_mload, 1);
 #endif
 
-#ifdef DEBUG_FIND_TIME_NUMGUESS
-    rb_define_virtual_variable("$find_time_numguess", find_time_numguess_getter, NULL);
-#endif
+    if (debug_find_time_numguess) {
+        rb_define_hooked_variable("$find_time_numguess", (VALUE *)&find_time_numguess,
+                                  find_time_numguess_getter, NULL);
+    }
 
     rb_cTimeTM = Init_tm(rb_cTime, "tm");
 }
-- 
cgit v1.1


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

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