From 7096d277da60df6b5e9077a63fc38913143f7280 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Tue, 7 Mar 2023 22:17:02 +0900 Subject: [PATCH] mruby-time/time.c: support bigint to time_t if necessary --- mrbgems/mruby-time/src/time.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/mrbgems/mruby-time/src/time.c b/mrbgems/mruby-time/src/time.c index c48e1ab86..5b1f65b1e 100644 --- a/mrbgems/mruby-time/src/time.c +++ b/mrbgems/mruby-time/src/time.c @@ -217,7 +217,7 @@ typedef mrb_int mrb_sec; (sizeof(time_t) <= 4 ? INT32_MAX : INT64_MAX) \ ) -#ifndef MRB_NO_FLOAT +#if defined(MRB_NO_FLOAT) || defined(MRB_USE_BIGINT) /* return true if time_t is fit in mrb_int */ static mrb_bool fixable_time_t_p(time_t v) @@ -948,11 +948,18 @@ mrb_time_to_i(mrb_state *mrb, mrb_value self) struct mrb_time *tm; tm = time_get_ptr(mrb, self); -#ifndef MRB_NO_FLOAT if (!fixable_time_t_p(tm->sec)) { +#if defined(MRB_USE_BIGINT) + if (MRB_TIME_T_UINT) { + return mrb_bint_new_uint64(mrb, (uint64_t)tm->sec); + } + else { + return mrb_bint_new_int64(mrb, (int64_t)tm->sec); + } +#elif !defined(MRB_NO_FLOAT) return mrb_float_value(mrb, (mrb_float)tm->sec); - } #endif + } return mrb_int_value(mrb, (mrb_int)tm->sec); }