[前][次][番号順一覧][スレッド一覧]

ruby-changes:58137

From: Yusuke <ko1@a...>
Date: Sun, 6 Oct 2019 11:49:27 +0900 (JST)
Subject: [ruby-changes:58137] 2409667aa2 (master): time.c: Fix some bugs about WIDEVALUE

https://git.ruby-lang.org/ruby.git/commit/?id=2409667aa2

From 2409667aa2e03b6008ed7a4ccce48a8b288cc0fd Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Sun, 6 Oct 2019 11:39:01 +0900
Subject: time.c: Fix some bugs about WIDEVALUE

WIDEVALUE differs from VALUE in 32bit platform, but some codes assume
that they are the same.

There is `#define STRUCT_WIDEVAL` mode to check the consistency.
This change allows to build with STRUCT_WIDEVAL.

diff --git a/time.c b/time.c
index 70cac06..a7a95b6 100644
--- a/time.c
+++ b/time.c
@@ -303,7 +303,7 @@ v2w(VALUE v) https://github.com/ruby/ruby/blob/trunk/time.c#L303
 {
     if (RB_TYPE_P(v, T_RATIONAL)) {
         if (RRATIONAL(v)->den != LONG2FIX(1))
-            return v;
+            return WIDEVAL_WRAP(v);
         v = RRATIONAL(v)->num;
     }
 #if WIDEVALUE_IS_WIDER
@@ -2193,7 +2193,7 @@ extract_vtm(VALUE time, struct vtm *vtm, VALUE subsecx) https://github.com/ruby/ruby/blob/trunk/time.c#L2193
         *vtm = tobj->vtm;
         t = rb_time_unmagnify(tobj->timew);
         if (TZMODE_FIXOFF_P(tobj) && vtm->utc_offset != INT2FIX(0))
-            t = wadd(t, vtm->utc_offset);
+            t = wadd(t, v2w(vtm->utc_offset));
     }
     else if (RB_TYPE_P(time, T_STRUCT)) {
 #define AREF(x) rb_struct_aref(time, ID2SYM(id_##x))
@@ -4103,7 +4103,7 @@ time_inspect(VALUE time) https://github.com/ruby/ruby/blob/trunk/time.c#L4103
 
     GetTimeval(time, tobj);
     str = strftimev("%Y-%m-%d %H:%M:%S", time, rb_usascii_encoding());
-    subsec = wmod(tobj->timew, WINT2FIXWV(TIME_SCALE));
+    subsec = w2v(wmod(tobj->timew, WINT2FIXWV(TIME_SCALE)));
     if (FIXNUM_P(subsec) && FIX2LONG(subsec) == 0) {
     }
     else if (FIXNUM_P(subsec) && FIX2LONG(subsec) < TIME_SCALE) {
@@ -4115,7 +4115,7 @@ time_inspect(VALUE time) https://github.com/ruby/ruby/blob/trunk/time.c#L4115
     }
     else {
         rb_str_cat_cstr(str, " ");
-        subsec = quov(w2v(subsec), INT2FIX(TIME_SCALE));
+        subsec = quov(subsec, INT2FIX(TIME_SCALE));
         rb_str_concat(str, rb_obj_as_string(subsec));
     }
     if (TZMODE_UTC_P(tobj)) {
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]