ruby-changes:11269
From: nobu <ko1@a...>
Date: Wed, 11 Mar 2009 04:47:58 +0900 (JST)
Subject: [ruby-changes:11269] Ruby:r22880 (trunk): * time.c (time_to_i, time_hash): time_t may be bigger than long
nobu 2009-03-11 04:47:46 +0900 (Wed, 11 Mar 2009) New Revision: 22880 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=22880 Log: * time.c (time_to_i, time_hash): time_t may be bigger than long and int. * time.c (time_timeval, rb_time_timeval, obj2nsec, time_strftime), (time_mdump, time_mload): suppress warnings. * win32/Makefile.sub (config.h): added TIMET2NUM and NUM2TIMET. Modified files: trunk/ChangeLog trunk/time.c trunk/win32/Makefile.sub Index: time.c =================================================================== --- time.c (revision 22879) +++ time.c (revision 22880) @@ -21,6 +21,10 @@ #include <math.h> +#ifndef TYPEOF_TIMEVAL_TV_SEC +# define TYPEOF_TIMEVAL_TV_SEC time_t +#endif + VALUE rb_cTime; static VALUE time_utc_offset _((VALUE)); @@ -251,7 +255,7 @@ struct timeval tv; ts = time_timespec(num, interval); - tv.tv_sec = ts.tv_sec; + tv.tv_sec = (TYPEOF_TIMEVAL_TV_SEC)ts.tv_sec; tv.tv_usec = ts.tv_nsec / 1000; return tv; @@ -271,7 +275,7 @@ if (TYPE(time) == T_DATA && RDATA(time)->dfree == time_free) { GetTimeval(time, tobj); - t.tv_sec = tobj->ts.tv_sec; + t.tv_sec = (TYPEOF_TIMEVAL_TV_SEC)tobj->ts.tv_sec; t.tv_usec = tobj->ts.tv_nsec / 1000; return t; } @@ -365,7 +369,7 @@ ts = time_timespec(obj, 1); *nsec = ts.tv_nsec; - return ts.tv_sec; + return (long)ts.tv_sec; } static long @@ -992,7 +996,7 @@ struct time_object *tobj; GetTimeval(time, tobj); - return LONG2NUM(tobj->ts.tv_sec); + return TIMET2NUM(tobj->ts.tv_sec); } /* @@ -1183,7 +1187,13 @@ long hash; GetTimeval(time, tobj); - hash = rb_hash_end(rb_hash_uint(rb_hash_start(tobj->ts.tv_sec), tobj->ts.tv_nsec)); +#if SIZEOF_TIME_T > SIZEOF_INT + hash = rb_hash_start((unsigned int)(tobj->ts.tv_sec >> (SIZEOF_INT * CHAR_BIT))); + hash = rb_hash_uint(hash, (unsigned int)tobj->ts.tv_sec); +#else + hash = rb_hash_start((unsigned int)tobj->ts.tv_sec); +#endif + hash = rb_hash_end(rb_hash_uint(hash, tobj->ts.tv_nsec)); return LONG2FIX(hash); } @@ -2137,7 +2147,7 @@ if (len == 0) { rb_warning("strftime called with empty format string"); } - else if (strlen(fmt) < len) { + else if (memchr(fmt, '\0', len)) { /* Ruby string may contain \0's. */ const char *p = fmt, *pe = fmt + len; @@ -2202,11 +2212,11 @@ nsec = tobj->ts.tv_nsec % 1000; for (i=0; i<4; i++) { - buf[i] = p & 0xff; + buf[i] = (unsigned char)p; p = RSHIFT(p, 8); } for (i=4; i<8; i++) { - buf[i] = s & 0xff; + buf[i] = (unsigned char)s; s = RSHIFT(s, 8); } @@ -2306,6 +2316,7 @@ tm.tm_hour = p & 0x1f; tm.tm_min = (s >> 26) & 0x3f; tm.tm_sec = (s >> 20) & 0x3f; + tm.tm_yday = tm.tm_mday = tm.tm_wday = 0; tm.tm_isdst = 0; sec = make_time_t(&tm, Qtrue); Index: ChangeLog =================================================================== --- ChangeLog (revision 22879) +++ ChangeLog (revision 22880) @@ -1,3 +1,13 @@ +Wed Mar 11 04:47:47 2009 Nobuyoshi Nakada <nobu@r...> + + * time.c (time_to_i, time_hash): time_t may be bigger than long + and int. + + * time.c (time_timeval, rb_time_timeval, obj2nsec, time_strftime), + (time_mdump, time_mload): suppress warnings. + + * win32/Makefile.sub (config.h): added TIMET2NUM and NUM2TIMET. + Wed Mar 11 04:29:52 2009 Nobuyoshi Nakada <nobu@r...> * win32/win32.c: suppress warnings. based on a patch from Charlie Index: win32/Makefile.sub =================================================================== --- win32/Makefile.sub (revision 22879) +++ win32/Makefile.sub (revision 22880) @@ -393,8 +393,12 @@ #define SIZEOF_DOUBLE 8 !if $(MSC_VER) >= 1400 #define SIZEOF_TIME_T 8 +#define TIMET2NUM(v) LL2NUM(v) +#define NUM2TIMET(v) NUM2LL(v) !else #define SIZEOF_TIME_T 4 +#define TIMET2NUM(v) LONG2NUM(v) +#define NUM2TIMET(v) NUM2LONG(v) !endif #define SIZEOF_RLIM_T 0 !if "$(ARCH)" == "x64" || "$(ARCH)" == "ia64" @@ -460,6 +464,7 @@ !endif #define GETGROUPS_T int #define RETSIGTYPE void +#define TYPEOF_TIMEVAL_TV_SEC long #define HAVE_ALLOCA 1 #define HAVE_DUP2 1 #define HAVE_MEMCMP 1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/