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

ruby-changes:13475

From: akr <ko1@a...>
Date: Wed, 7 Oct 2009 08:14:47 +0900 (JST)
Subject: [ruby-changes:13475] Ruby:r25250 (ruby_1_8): * time.c (NUM2TIMET): defined because some platforms, such as

akr	2009-10-07 08:14:32 +0900 (Wed, 07 Oct 2009)

  New Revision: 25250

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=25250

  Log:
    * time.c (NUM2TIMET): defined because some platforms, such as
      NetBSD5/amd64 and NetBSD6/i386, has time_t which size is different
      from long.  (NetBSD 5 uses 32bit time_t for all, including 64bit,
      platforms.  NetBSD 6 uses 64bit time_t for all, including 32bit,
      platforms.)
      (TIMET2NUM): defined.
      (time_timeval): use NUM2TIMET.
      (time_s_at): ditto.
      (time_to_i): use TIMET2NUM.

  Modified files:
    branches/ruby_1_8/ChangeLog
    branches/ruby_1_8/time.c

Index: ruby_1_8/time.c
===================================================================
--- ruby_1_8/time.c	(revision 25249)
+++ ruby_1_8/time.c	(revision 25250)
@@ -21,6 +21,22 @@
 
 #include <math.h>
 
+#if SIZEOF_TIME_T == SIZEOF_LONG
+typedef unsigned long unsigned_time_t;
+#define NUM2TIMET(v) NUM2LONG(v)
+#define TIMET2NUM(v) LONG2NUM(v)
+#elif SIZEOF_TIME_T == SIZEOF_INT
+typedef unsigned int unsigned_time_t;
+#define NUM2TIMET(v) NUM2INT(v)
+#define TIMET2NUM(v) INT2NUM(v)
+#elif SIZEOF_TIME_T == SIZEOF_LONG_LONG
+typedef unsigned LONG_LONG unsigned_time_t;
+#define NUM2TIMET(v) NUM2LL(v)
+#define TIMET2NUM(v) LL2NUM(v)
+#else
+# error cannot find integer type which size is same as time_t.
+#endif
+
 VALUE rb_cTime;
 
 struct time_object {
@@ -179,7 +195,7 @@
 
     switch (TYPE(time)) {
       case T_FIXNUM:
-	t.tv_sec = FIX2LONG(time);
+	t.tv_sec = NUM2TIMET(time);
 	if (interval && t.tv_sec < 0)
 	    rb_raise(rb_eArgError, "%s must be positive", tstr);
 	t.tv_usec = 0;
@@ -207,7 +223,7 @@
 	break;
 
       case T_BIGNUM:
-	t.tv_sec = NUM2LONG(time);
+	t.tv_sec = NUM2TIMET(time);
 	if (interval && t.tv_sec < 0)
 	    rb_raise(rb_eArgError, "%s must be positive", tstr);
 	t.tv_usec = 0;
@@ -268,7 +284,7 @@
     VALUE time, t;
 
     if (rb_scan_args(argc, argv, "11", &time, &t) == 2) {
-	tv.tv_sec = NUM2LONG(time);
+	tv.tv_sec = NUM2TIMET(time);
 	tv.tv_usec = NUM2LONG(t);
     }
     else {
@@ -495,16 +511,6 @@
         return 0;
 }
 
-#if SIZEOF_TIME_T == SIZEOF_LONG
-typedef unsigned long unsigned_time_t;
-#elif SIZEOF_TIME_T == SIZEOF_INT
-typedef unsigned int unsigned_time_t;
-#elif SIZEOF_TIME_T == SIZEOF_LONG_LONG
-typedef unsigned LONG_LONG unsigned_time_t;
-#else
-# error cannot find integer type which size is same as time_t.
-#endif
-
 static time_t
 search_time_t(tptr, utc_p)
     struct tm *tptr;
@@ -895,7 +901,7 @@
     struct time_object *tobj;
 
     GetTimeval(time, tobj);
-    return LONG2NUM(tobj->tv.tv_sec);
+    return TIMET2NUM(tobj->tv.tv_sec);
 }
 
 /*
Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog	(revision 25249)
+++ ruby_1_8/ChangeLog	(revision 25250)
@@ -1,3 +1,15 @@
+Wed Oct  7 08:07:45 2009  Tanaka Akira  <akr@f...>
+
+	* time.c (NUM2TIMET): defined because some platforms, such as
+	  NetBSD5/amd64 and NetBSD6/i386, has time_t which size is different
+	  from long.  (NetBSD 5 uses 32bit time_t for all, including 64bit,
+	  platforms.  NetBSD 6 uses 64bit time_t for all, including 32bit,
+	  platforms.)
+	  (TIMET2NUM): defined.
+	  (time_timeval): use NUM2TIMET.
+	  (time_s_at): ditto.
+	  (time_to_i): use TIMET2NUM.
+
 Wed Oct  7 00:27:01 2009  Tanaka Akira  <akr@f...>
 
 	* lib/resolv.rb (Resolv::DNS.bind_random_port): bind to "::" for IPv6.

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

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