summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-time
diff options
context:
space:
mode:
authorKOBAYASHI Shuji <[email protected]>2019-12-05 21:40:15 +0900
committerKOBAYASHI Shuji <[email protected]>2019-12-05 21:40:15 +0900
commite6033e00fec973d3efa811fc46805c733ece8438 (patch)
tree7b7f22096487de530f36aa1109a5ce1e17f35156 /mrbgems/mruby-time
parent52318b3359683a3127728d4b0299f0f63703c346 (diff)
downloadmruby-e6033e00fec973d3efa811fc46805c733ece8438.tar.gz
mruby-e6033e00fec973d3efa811fc46805c733ece8438.zip
Auto detect `MRB_TIME_T_UINT`
Diffstat (limited to 'mrbgems/mruby-time')
-rw-r--r--mrbgems/mruby-time/src/time.c25
1 files changed, 10 insertions, 15 deletions
diff --git a/mrbgems/mruby-time/src/time.c b/mrbgems/mruby-time/src/time.c
index 46e32839a..62de406ab 100644
--- a/mrbgems/mruby-time/src/time.c
+++ b/mrbgems/mruby-time/src/time.c
@@ -76,11 +76,6 @@ double round(double x) {
/* define following macro to use probably faster timegm() on the platform */
/* #define USE_SYSTEM_TIMEGM */
-/* time_t */
-/* If your platform supports time_t as uint (e.g. uint32_t, uint64_t), */
-/* uncomment following macro. */
-/* #define MRB_TIME_T_UINT */
-
/** end of Time class configuration */
#ifndef NO_GETTIMEOFDAY
@@ -214,15 +209,15 @@ typedef mrb_int mrb_sec;
#define mrb_sec_value(mrb, sec) mrb_fixnum_value(sec)
#endif
-#ifdef MRB_TIME_T_UINT
-typedef uint64_t mrb_time_int;
-# define MRB_TIME_MIN 0
-# define MRB_TIME_MAX (sizeof(time_t) <= 4 ? UINT32_MAX : UINT64_MAX)
-#else
-typedef int64_t mrb_time_int;
-# define MRB_TIME_MIN (sizeof(time_t) <= 4 ? INT32_MIN : INT64_MIN)
-# define MRB_TIME_MAX (sizeof(time_t) <= 4 ? INT32_MAX : INT64_MAX)
-#endif
+#define MRB_TIME_T_UINT (~(time_t)0 > 0)
+#define MRB_TIME_MIN ( \
+ MRB_TIME_T_UINT ? 0 : \
+ (sizeof(time_t) <= 4 ? INT32_MIN : INT64_MIN) \
+)
+#define MRB_TIME_MAX ( \
+ MRB_TIME_T_UINT ? (sizeof(time_t) <= 4 ? UINT32_MAX : UINT64_MAX) : \
+ (sizeof(time_t) <= 4 ? INT32_MAX : INT64_MAX) \
+)
static mrb_bool
fixable_time_t_p(time_t v)
@@ -262,7 +257,7 @@ mrb_to_time_t(mrb_state *mrb, mrb_value obj, time_t *usec)
{
mrb_int i = mrb_int(mrb, obj);
- if ((MRB_INT_MAX > MRB_TIME_MAX && (mrb_time_int)i > MRB_TIME_MAX) ||
+ if ((MRB_INT_MAX > MRB_TIME_MAX && i > 0 && i > MRB_TIME_MAX) ||
(MRB_TIME_MIN > MRB_INT_MIN && MRB_TIME_MIN > i)) {
goto out_of_range;
}