From: matz@... (Yukihiro Matsumoto) Date: 1998-07-21T13:31:04+09:00 Subject: [ruby-list:8791] Re: ruby 1.1c0 released まつもと ゆきひろです In message "[ruby-list:8775] Re: ruby 1.1c0 released" on 98/07/17, TANAKA Shin-ichi writes: |東芝の田中です。 |が、/usr/share/dict/web2 (英単語のリスト、とっても長いです) を |読み込む |というスクリプトを実行させると | |aho.rb:6: [BUG] Segmentation fault |zsh: 5598 abort ruby aho.rb | |といってお亡くなりになってしまいます。 gdbの結果のおかげで原因がわかりました. # 助かるなあ. これはrehashでハッシュのサイズを拡大している最中にGCが発生す ると落っこちるというものです.以下のパッチで直ると思います. --- st.c 1998/05/13 07:26:34 1.1.1.1.4.1 +++ st.c 1998/07/21 04:28:34 @@ -51,2 +51,3 @@ #define do_hash(key, table) (*(table)->type->hash)((key), (table)->num_bins) +#define do_hash2(key, table, bins) (*(table)->type->hash)((key), bins) @@ -224,13 +225,14 @@ register st_table_entry *ptr, *next, **old_bins = table->bins; - int i, old_num_bins = table->num_bins, hash_val; + int i, old_num_bins = table->num_bins, new_num_bins, hash_val; - table->num_bins = 1.79*old_num_bins; + new_num_bins = 1.79*old_num_bins; - if (table->num_bins%2 == 0) { - table->num_bins += 1; + if (new_num_bins%2 == 0) { + new_num_bins += 1; } + table->num_bins = 0; table->num_entries = 0; table->bins = (st_table_entry **) - Calloc((unsigned)table->num_bins, sizeof(st_table_entry*)); + Calloc((unsigned)new_num_bins, sizeof(st_table_entry*)); @@ -240,3 +242,3 @@ next = ptr->next; - hash_val = do_hash(ptr->key, table); + hash_val = do_hash2(ptr->key, table, new_num_bins); ptr->next = table->bins[hash_val]; @@ -247,2 +249,3 @@ } + table->num_bins = new_num_bins; free((char*)old_bins);