diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-02-14 05:45:19 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-02-14 05:45:19 +0000 |
commit | 90d94de3b00f506dfb769501a5f11dbf2186d434 (patch) | |
tree | 7ab10f6d5d87988cd1208c597b9737c73e1ac073 /hash.c | |
parent | 1bb654d307ea0b536123514ddc459f37e369076e (diff) |
merge revision(s) 43942,43957,43975: [Backport #9187]
* hash.c (rb_hash_rehash): fix to free new st_table when exception
is raised in do_hash(). [Bug #9187]
* hash.c (rb_hash_rehash): make temporary st_table under the control
of GC. [Bug #9187]
* test/ruby/test_hash.rb: add a test for above.
* array.c (rb_hash_rehash): use hash_alloc() instead of rb_hash_new().
[Bug #9187]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@44938 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r-- | hash.c | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -442,6 +442,11 @@ rb_hash_s_try_convert(VALUE dummy, VALUE hash) return rb_check_hash_type(hash); } +struct rehash_arg { + VALUE hash; + st_table *tbl; +}; + static int rb_hash_rehash_i(VALUE key, VALUE value, VALUE arg) { @@ -474,6 +479,7 @@ rb_hash_rehash_i(VALUE key, VALUE value, VALUE arg) static VALUE rb_hash_rehash(VALUE hash) { + VALUE tmp; st_table *tbl; if (RHASH(hash)->iter_lev > 0) { @@ -482,10 +488,14 @@ rb_hash_rehash(VALUE hash) rb_hash_modify_check(hash); if (!RHASH(hash)->ntbl) return hash; + tmp = hash_alloc(0); tbl = st_init_table_with_size(RHASH(hash)->ntbl->type, RHASH(hash)->ntbl->num_entries); + RHASH(tmp)->ntbl = tbl; + rb_hash_foreach(hash, rb_hash_rehash_i, (VALUE)tbl); st_free_table(RHASH(hash)->ntbl); RHASH(hash)->ntbl = tbl; + RHASH(tmp)->ntbl = 0; return hash; } |