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;

Updated by nagachika (Tomoyuki Chikanaga) over 12 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;
    }

Updated by tadf (tadayoshi funaba) over 12 years ago

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

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

Updated by nagachika (Tomoyuki Chikanaga) over 12 years ago

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

Actions #4

Updated by nagachika (Tomoyuki Chikanaga) over 12 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.
    [ruby-dev:44337] [Bug #5152]

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

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0