Project

General

Profile

Actions

Backport #5586

closed

Time.at(Marshal.load(Marshal.dump(Time.now))).to_s raise TypeError

Added by nagachika (Tomoyuki Chikanaga) over 12 years ago. Updated over 11 years ago.

Status:
Closed
Assignee:
-
[ruby-dev:44827]

Description

以下のコードが TypeError を発生させます。なお 1.9.2-p312 でも発生しました。

Time.at(Marshal.load(Marshal.dump(Time.now))).to_s

=> TypeError: false can't be coerced into Fixnum

Time オブジェクトを Marshal.dump -> load すると TIME_SET_FIXOFF() で
struct time_object の gmt と vtm.utc_offset がセットされるのですが
それを Time.at に渡すと gmt だけコピーされて vtm.utc_offset が (VALUE)0 = Qfalse のままだからのようです。

どこが根本的な原因なのかよくわかりませんが、以下のパッチで例外はおきなくなりました。
るりまの Time.at(time) のページ( http://rurema.clear-code.com/1.9.3/method/Time/s/at.html )を見ると
「生成された Time オブジェクトのタイムゾーンは地方時となります。」とあるので TIME_GMT_COPY() 自体が
不要なのかもしれないと思いますがどうでしょう。

diff --git a/time.c b/time.c
index 3e50c7c..96b717b 100644
--- a/time.c
+++ b/time.c
@@ -1820,7 +1820,10 @@ struct time_object {
(tobj)->vtm.utc_offset = (off),
(tobj)->vtm.zone = NULL)

-#define TIME_COPY_GMT(tobj1, tobj2) ((tobj1)->gmt = (tobj2)->gmt)
+#define TIME_COPY_GMT(tobj1, tobj2) \

  • ((tobj1)->gmt = (tobj2)->gmt, \
  • (tobj1)->vtm.utc_offset = (tobj2)->vtm.utc_offset, \
    
  • (tobj1)->vtm.zone = (tobj2)->vtm.zone)
    

static VALUE time_get_tm(VALUE, struct time_object *);
#define MAKE_TM(time, tobj) \

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0