Commit e6033e00 authored by KOBAYASHI Shuji's avatar KOBAYASHI Shuji

Auto detect `MRB_TIME_T_UINT`

parent 52318b33
...@@ -76,11 +76,6 @@ double round(double x) { ...@@ -76,11 +76,6 @@ double round(double x) {
/* define following macro to use probably faster timegm() on the platform */ /* define following macro to use probably faster timegm() on the platform */
/* #define USE_SYSTEM_TIMEGM */ /* #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 */ /** end of Time class configuration */
#ifndef NO_GETTIMEOFDAY #ifndef NO_GETTIMEOFDAY
...@@ -214,15 +209,15 @@ typedef mrb_int mrb_sec; ...@@ -214,15 +209,15 @@ typedef mrb_int mrb_sec;
#define mrb_sec_value(mrb, sec) mrb_fixnum_value(sec) #define mrb_sec_value(mrb, sec) mrb_fixnum_value(sec)
#endif #endif
#ifdef MRB_TIME_T_UINT #define MRB_TIME_T_UINT (~(time_t)0 > 0)
typedef uint64_t mrb_time_int; #define MRB_TIME_MIN ( \
# define MRB_TIME_MIN 0 MRB_TIME_T_UINT ? 0 : \
# define MRB_TIME_MAX (sizeof(time_t) <= 4 ? UINT32_MAX : UINT64_MAX) (sizeof(time_t) <= 4 ? INT32_MIN : INT64_MIN) \
#else )
typedef int64_t mrb_time_int; #define MRB_TIME_MAX ( \
# define MRB_TIME_MIN (sizeof(time_t) <= 4 ? INT32_MIN : INT64_MIN) MRB_TIME_T_UINT ? (sizeof(time_t) <= 4 ? UINT32_MAX : UINT64_MAX) : \
# define MRB_TIME_MAX (sizeof(time_t) <= 4 ? INT32_MAX : INT64_MAX) (sizeof(time_t) <= 4 ? INT32_MAX : INT64_MAX) \
#endif )
static mrb_bool static mrb_bool
fixable_time_t_p(time_t v) fixable_time_t_p(time_t v)
...@@ -262,7 +257,7 @@ mrb_to_time_t(mrb_state *mrb, mrb_value obj, time_t *usec) ...@@ -262,7 +257,7 @@ mrb_to_time_t(mrb_state *mrb, mrb_value obj, time_t *usec)
{ {
mrb_int i = mrb_int(mrb, obj); 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)) { (MRB_TIME_MIN > MRB_INT_MIN && MRB_TIME_MIN > i)) {
goto out_of_range; goto out_of_range;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment