Project

General

Profile

Bug #5152

TestDateNew#test_civil が GC.stress = true 下で Failure

Added by nagachika (Tomoyuki Chikanaga) about 7 years ago. Updated about 7 years ago.

Status:
Closed
Priority:
Normal
Target version:
[ruby-dev:44337]

Description

make test-all TESTS="-vq --gc-stress date/test_date_new.rb -n test_civil"
のように GC.stress = true 下で DateTime のテストが Failure します。

1) Failure:
test_civil(TestDateNew) [/home/chikanaga/opt/ruby-trunk/src/ruby/test/date/test_date_new.rb:100]:
<[-4712, 1, 1, 0, 0, 0, (3/8)]> expected but was
<[-4712, 1, 1, 0, 0, 0, (0/1)]>.

以下のようなスクリプトでも再現します。また ruby_1_9_3 でも再現しました。

$ cat datetime.rb
require "date"
GC.stress = true
dt = DateTime.civil(-4712,1,1, 0,0,0, '+0900')
p dt.offset # => (3/8) になるはずが (0/1) になる

date_parse.c の date_zone_to_diff での str の GC 保護されていないためだと思います。
以下のような変更で期待した offset を得られるようになりました。

diff --git a/ext/date/date_parse.c b/ext/date/date_parse.c
index 3605ff7..e41606b 100644
--- a/ext/date/date_parse.c
+++ b/ext/date/date_parse.c
@@ -374,6 +374,7 @@ date_zone_to_diff(VALUE str)
sp = 0;
}
}

  • RB_GC_GUARD(str); if (d > dest) { if (*(d - 1) == ' ') --d;

Associated revisions

Revision 0bd01d00
Added by nagachika (Tomoyuki Chikanaga) about 7 years ago

  • ext/date/date_parse.c (date_zone_to_diff): add RB_GC_GUARD.
    [Bug #5152]

  • ext/date/data_parse.c (parse_ddd_cb): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32896 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 32896
Added by nagachika (Tomoyuki Chikanaga) about 7 years ago

  • ext/date/date_parse.c (date_zone_to_diff): add RB_GC_GUARD.
    [Bug #5152]

  • ext/date/data_parse.c (parse_ddd_cb): ditto.

Revision 32896
Added by nagachika (Tomoyuki Chikanaga) about 7 years ago

  • ext/date/date_parse.c (date_zone_to_diff): add RB_GC_GUARD.
    [Bug #5152]

  • ext/date/data_parse.c (parse_ddd_cb): ditto.

Revision 32896
Added by nagachika (Tomoyuki Chikanaga) about 7 years ago

  • ext/date/date_parse.c (date_zone_to_diff): add RB_GC_GUARD.
    [Bug #5152]

  • ext/date/data_parse.c (parse_ddd_cb): ditto.

Revision 32896
Added by nagachika (Tomoyuki Chikanaga) about 7 years ago

  • ext/date/date_parse.c (date_zone_to_diff): add RB_GC_GUARD.
    [Bug #5152]

  • ext/date/data_parse.c (parse_ddd_cb): ditto.

Revision 32896
Added by nagachika (Tomoyuki Chikanaga) about 7 years ago

  • ext/date/date_parse.c (date_zone_to_diff): add RB_GC_GUARD.
    [Bug #5152]

  • ext/date/data_parse.c (parse_ddd_cb): ditto.

Revision 5da4785a
Added by nagachika (Tomoyuki Chikanaga) about 7 years ago

merge revision(s) 32859:

   * ext/date/date_parse.c (date_zone_to_diff): add RB_GC_GUARD.
      [Bug #5152]

   * ext/date/data_parse.c (parse_ddd_cb): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@32897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 14b57772
Added by nagachika (Tomoyuki Chikanaga) about 7 years ago

  • ext/date/date_parse.c parse_ddd_cb): fix r32896. RB_GC_GUARD insertion position was mistaken. [Bug #5152]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32962 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 32962
Added by nagachika (Tomoyuki Chikanaga) about 7 years ago

  • ext/date/date_parse.c parse_ddd_cb): fix r32896. RB_GC_GUARD insertion position was mistaken. [Bug #5152]

Revision 32962
Added by nagachika (Tomoyuki Chikanaga) about 7 years ago

  • ext/date/date_parse.c parse_ddd_cb): fix r32896. RB_GC_GUARD insertion position was mistaken. [Bug #5152]

Revision 32962
Added by nagachika (Tomoyuki Chikanaga) about 7 years ago

  • ext/date/date_parse.c parse_ddd_cb): fix r32896. RB_GC_GUARD insertion position was mistaken. [Bug #5152]

Revision 32962
Added by nagachika (Tomoyuki Chikanaga) about 7 years ago

  • ext/date/date_parse.c parse_ddd_cb): fix r32896. RB_GC_GUARD insertion position was mistaken. [Bug #5152]

Revision 32962
Added by nagachika (Tomoyuki Chikanaga) about 7 years ago

  • ext/date/date_parse.c parse_ddd_cb): fix r32896. RB_GC_GUARD insertion position was mistaken. [Bug #5152]

Revision 7956346a
Added by nagachika (Tomoyuki Chikanaga) about 7 years ago

  • backport r32962+r32965 from trunk.

  • ext/date/date_parse.c (parse_ddd_cb): fix r32896. RB_GC_GUARD
    insertion position was mistaken. [Bug #5152]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@32966 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

History

#1 [ruby-dev:44340] Updated by nagachika (Tomoyuki Chikanaga) about 7 years ago

すみません、ソースコードを良く読むと RB_GC_GUARD() を挿入しないといけないのはさっきのところじゃなくて関数の最後のほうに挿入する必要がありそうでした。

また parse_ddd_cb() にも GC 保護が必要な変数がありそうでした。

@@ -1323,6 +1324,7 @@ parse_ddd_cb(VALUE m, VALUE hash)
}
break;
}

  • RB_GC_GUARD(s2); if (!NIL_P(s3)) { cs3 = RSTRING_PTR(s3); l3 = RSTRING_LEN(s3); @@ -1354,6 +1356,7 @@ parse_ddd_cb(VALUE m, VALUE hash) } } }
  • RB_GC_GUARD(s3); if (!NIL_P(s4)) { l4 = RSTRING_LEN(s4);

@@ -1392,6 +1395,7 @@ parse_ddd_cb(VALUE m, VALUE hash)
set_hash("offset", date_zone_to_diff(rb_str_new2(s1)));
}
}

  • RB_GC_GUARD(s5);

    return 1;
    }

#2 [ruby-dev:44357] Updated by tadf (tadayoshi funaba) about 7 years ago

  • ruby -v changed from ruby 1.9.4dev (2011-08-03 trunk 32823) [x86_64-linux] to -

とりあえずコミットしておいて下さい。

#3 [ruby-dev:44367] Updated by nagachika (Tomoyuki Chikanaga) about 7 years ago

了解しました。
今週は追加の確認ができそうにないので、とりあえず現在わかっているところを入れてしまいます。

#4 Updated by nagachika (Tomoyuki Chikanaga) about 7 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r32896.
Tomoyuki, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • ext/date/date_parse.c (date_zone_to_diff): add RB_GC_GUARD.
    [Bug #5152]

  • ext/date/data_parse.c (parse_ddd_cb): ditto.

Also available in: Atom PDF