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

ruby-changes:42113

From: naruse <ko1@a...>
Date: Sat, 19 Mar 2016 04:06:40 +0900 (JST)
Subject: [ruby-changes:42113] naruse:r54187 (trunk): * time.c (LOCALTIME): organize #ifdefs.

naruse	2016-03-19 04:06:33 +0900 (Sat, 19 Mar 2016)

  New Revision: 54187

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54187

  Log:
    * time.c (LOCALTIME): organize #ifdefs.
    
    * time.c (GMTIME): define only ifndef HAVE_STRUCT_TM_TM_GMTOFF.

  Modified files:
    trunk/ChangeLog
    trunk/time.c
Index: time.c
===================================================================
--- time.c	(revision 54186)
+++ time.c	(revision 54187)
@@ -783,45 +783,29 @@ static struct vtm *localtimew(wideval_t https://github.com/ruby/ruby/blob/trunk/time.c#L783
 static int leap_year_p(long y);
 #define leap_year_v_p(y) leap_year_p(NUM2LONG(mod((y), INT2FIX(400))))
 
-#ifdef HAVE_GMTIME_R
-#define rb_gmtime_r(t, tm) gmtime_r((t), (tm))
-#define rb_localtime_r(t, tm) localtime_r((t), (tm))
-#else
-static inline struct tm *
-rb_gmtime_r(const time_t *tp, struct tm *result)
-{
-    struct tm *t = gmtime(tp);
-    if (t) *result = *t;
-    return t;
-}
-
-static inline struct tm *
-rb_localtime_r(const time_t *tp, struct tm *result)
-{
-    struct tm *t = localtime(tp);
-    if (t) *result = *t;
-    return t;
-}
-#endif
-
 static struct tm *
-rb_localtime_r2(const time_t *t, struct tm *result)
+rb_localtime_r(const time_t *t, struct tm *result)
 {
 #if defined __APPLE__ && defined __LP64__
     if (*t != (time_t)(int)*t) return NULL;
 #endif
-    result = rb_localtime_r(t, result);
+#ifdef HAVE_GMTIME_R
+    result = localtime_r(t, result);
+#else
+    {
+	struct tm *tmp = localtime(t);
+	if (tmp) *result = *tmp;
+    }
+#endif
 #if defined(HAVE_MKTIME) && defined(LOCALTIME_OVERFLOW_PROBLEM)
     if (result) {
         long gmtoff1 = 0;
         long gmtoff2 = 0;
         struct tm tmp = *result;
         time_t t2;
-#  if defined(HAVE_STRUCT_TM_TM_GMTOFF)
-        gmtoff1 = result->tm_gmtoff;
-#  endif
         t2 = mktime(&tmp);
 #  if defined(HAVE_STRUCT_TM_TM_GMTOFF)
+        gmtoff1 = result->tm_gmtoff;
         gmtoff2 = tmp.tm_gmtoff;
 #  endif
         if (*t + gmtoff1 != t2 + gmtoff2)
@@ -830,24 +814,26 @@ rb_localtime_r2(const time_t *t, struct https://github.com/ruby/ruby/blob/trunk/time.c#L814
 #endif
     return result;
 }
-#define LOCALTIME(tm, result) (tzset(),rb_localtime_r2((tm), &(result)))
+#define LOCALTIME(tm, result) (tzset(),rb_localtime_r((tm), &(result)))
 
-#if !defined(HAVE_STRUCT_TM_TM_GMTOFF)
+#ifndef HAVE_STRUCT_TM_TM_GMTOFF
 static struct tm *
-rb_gmtime_r2(const time_t *t, struct tm *result)
+rb_gmtime_r(const time_t *t, struct tm *result)
 {
-    result = rb_gmtime_r(t, result);
+#ifdef HAVE_GMTIME_R
+    result = gmtime_r(t, result);
+#else
+    struct tm *tmp = gmtime(t);
+    if (tmp) *result = *tmp;
+#endif
 #if defined(HAVE_TIMEGM) && defined(LOCALTIME_OVERFLOW_PROBLEM)
-    if (result) {
-	struct tm tmp = *result;
-	time_t t2 = timegm(&tmp);
-	if (*t != t2)
-	    result = NULL;
+    if (result && *t != timegm(result)) {
+	return NULL;
     }
 #endif
     return result;
 }
-#   define GMTIME(tm, result) rb_gmtime_r2((tm), &(result))
+#   define GMTIME(tm, result) rb_gmtime_r((tm), &(result))
 #endif
 
 static const int common_year_yday_offset[] = {
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54186)
+++ ChangeLog	(revision 54187)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Mar 19 03:57:13 2016  NARUSE, Yui  <naruse@r...>
+
+	* time.c (LOCALTIME): organize #ifdefs.
+
+	* time.c (GMTIME): define only ifndef HAVE_STRUCT_TM_TM_GMTOFF.
+
 Sat Mar 19 03:53:31 2016  NARUSE, Yui  <naruse@r...>
 
 	* configure.in (rb_cv_member_struct_tm_tm_gmtoff): For Linux (glibc)

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

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