summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-03-10 19:47:46 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-03-10 19:47:46 +0000
commit8231655dea0c216d9a3bd08796a43ddb3399d699 (patch)
tree70dd561928dcda22029cc20d0ea511743ac9e9c6
parent0032476a243f28684f14fcdb8cf59e38798cb6a5 (diff)
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22880 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog10
-rw-r--r--time.c27
-rw-r--r--win32/Makefile.sub5
3 files changed, 34 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 3dd971fddf..005cdfacf9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Wed Mar 11 04:47:47 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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@ruby-lang.org>
* win32/win32.c: suppress warnings. based on a patch from Charlie
diff --git a/time.c b/time.c
index 5542c79c9b..4bed1be810 100644
--- a/time.c
+++ b/time.c
@@ -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 @@ time_timeval(VALUE num, int interval)
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 @@ rb_time_timeval(VALUE time)
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 @@ obj2nsec(VALUE obj, long *nsec)
ts = time_timespec(obj, 1);
*nsec = ts.tv_nsec;
- return ts.tv_sec;
+ return (long)ts.tv_sec;
}
static long
@@ -992,7 +996,7 @@ time_to_i(VALUE time)
struct time_object *tobj;
GetTimeval(time, tobj);
- return LONG2NUM(tobj->ts.tv_sec);
+ return TIMET2NUM(tobj->ts.tv_sec);
}
/*
@@ -1183,7 +1187,13 @@ time_hash(VALUE time)
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 @@ time_strftime(VALUE time, VALUE format)
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 @@ time_mdump(VALUE time)
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 @@ time_mload(VALUE time, VALUE str)
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);
diff --git a/win32/Makefile.sub b/win32/Makefile.sub
index de4eb7c802..f6b757d50f 100644
--- a/win32/Makefile.sub
+++ b/win32/Makefile.sub
@@ -393,8 +393,12 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/win32/Makefile.sub $(win_srcdir)/Makefile.sub
#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 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/win32/Makefile.sub $(win_srcdir)/Makefile.sub
!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