diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2018-01-30 12:42:49 +0900 |
|---|---|---|
| committer | GitHub <[email protected]> | 2018-01-30 12:42:49 +0900 |
| commit | 3498a787ba4c6425923efafdc04ae6f151bad3dd (patch) | |
| tree | b7bb62aded741b9ab0f6c29b71fccef411d06d01 | |
| parent | 83f2654bac329e9533c893e3759ae045e57b625a (diff) | |
| parent | a1b71b64b37131064b7dbbb04151640a1b16cf5c (diff) | |
| download | mruby-3498a787ba4c6425923efafdc04ae6f151bad3dd.tar.gz mruby-3498a787ba4c6425923efafdc04ae6f151bad3dd.zip | |
Merge pull request #3936 from ken-mu/uint
mruby-time: support time_t is uint
| -rw-r--r-- | mrbgems/mruby-time/src/time.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/mrbgems/mruby-time/src/time.c b/mrbgems/mruby-time/src/time.c index 98198083b..cfd51ac63 100644 --- a/mrbgems/mruby-time/src/time.c +++ b/mrbgems/mruby-time/src/time.c @@ -67,6 +67,11 @@ 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 @@ -240,13 +245,21 @@ time_alloc(mrb_state *mrb, double sec, double usec, enum mrb_timezone timezone) mrb_check_num_exact(mrb, (mrb_float)sec); mrb_check_num_exact(mrb, (mrb_float)usec); - +#ifndef MRB_TIME_T_UINT if (sizeof(time_t) == 4 && (sec > (double)INT32_MAX || (double)INT32_MIN > sec)) { goto out_of_range; } if (sizeof(time_t) == 8 && (sec > (double)INT64_MAX || (double)INT64_MIN > sec)) { goto out_of_range; } +#else + if (sizeof(time_t) == 4 && (sec > (double)UINT32_MAX || (double)0 > sec)) { + goto out_of_range; + } + if (sizeof(time_t) == 8 && (sec > (double)UINT64_MAX || (double)0 > sec)) { + goto out_of_range; + } +#endif tsec = (time_t)sec; if ((sec > 0 && tsec < 0) || (sec < 0 && (double)tsec > sec)) { out_of_range: |
