Project

General

Profile

Actions

Bug #5152

closed

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

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

Status:
Closed
Target version:
ruby -v:
-
Backport:
[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;
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0