ruby-changes:31596
From: nobu <ko1@a...>
Date: Thu, 14 Nov 2013 11:35:45 +0900 (JST)
Subject: [ruby-changes:31596] nobu:r43675 (trunk): hash.c: restore iter_lev
nobu 2013-11-14 11:35:40 +0900 (Thu, 14 Nov 2013) New Revision: 43675 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43675 Log: hash.c: restore iter_lev * hash.c (hash_foreach_ensure): restore iter_lev to the previous value, not just decrement. [ruby-dev:47803] [Bug #9105] Modified files: trunk/ChangeLog trunk/hash.c trunk/test/ruby/test_hash.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 43674) +++ ChangeLog (revision 43675) @@ -1,4 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 -Thu Nov 14 11:33:47 2013 Nobuyoshi Nakada <nobu@r...> +Thu Nov 14 11:35:37 2013 Nobuyoshi Nakada <nobu@r...> + + * hash.c (hash_foreach_ensure): restore iter_lev to the previous + value, not just decrement. [ruby-dev:47803] [Bug #9105] * hash.c (foreach_safe_i, hash_foreach_iter): deal with error detected by ST_CHECK. Index: hash.c =================================================================== --- hash.c (revision 43674) +++ hash.c (revision 43675) @@ -173,6 +173,7 @@ struct hash_foreach_arg { https://github.com/ruby/ruby/blob/trunk/hash.c#L173 VALUE hash; rb_foreach_func *func; VALUE arg; + int iter_lev; }; static int @@ -201,9 +202,12 @@ hash_foreach_iter(st_data_t key, st_data https://github.com/ruby/ruby/blob/trunk/hash.c#L202 } static VALUE -hash_foreach_ensure(VALUE hash) +hash_foreach_ensure(VALUE arg) { - if (--RHASH_ITER_LEV(hash) == 0) { + struct hash_foreach_arg *argp = (struct hash_foreach_arg *)arg; + VALUE hash = argp->hash; + + if ((RHASH_ITER_LEV(hash) = argp->iter_lev) == 0) { if (FL_TEST(hash, HASH_DELETED)) { st_cleanup_safe(RHASH(hash)->ntbl, (st_data_t)Qundef); FL_UNSET(hash, HASH_DELETED); @@ -229,11 +233,11 @@ rb_hash_foreach(VALUE hash, int (*func)( https://github.com/ruby/ruby/blob/trunk/hash.c#L233 if (!RHASH(hash)->ntbl) return; - RHASH_ITER_LEV(hash)++; arg.hash = hash; arg.func = (rb_foreach_func *)func; arg.arg = farg; - rb_ensure(hash_foreach_call, (VALUE)&arg, hash_foreach_ensure, hash); + arg.iter_lev = RHASH_ITER_LEV(hash)++; + rb_ensure(hash_foreach_call, (VALUE)&arg, hash_foreach_ensure, (VALUE)&arg); } static VALUE Index: test/ruby/test_hash.rb =================================================================== --- test/ruby/test_hash.rb (revision 43674) +++ test/ruby/test_hash.rb (revision 43675) @@ -930,6 +930,22 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_hash.rb#L930 h.clear c.call end + + bug9105 = '[ruby-dev:47803] [Bug #9105]' + h = @cls[1=>2, 3=>4] + c = nil + f = false + h.each {callcc {|c2| c = c2}} + unless f + f = true + c.call + end + assert_nothing_raised(RuntimeError, bug9105) do + h.each {|i, j| + h.delete(i); + assert_not_equal(false, i, bug9105) + } + end end def test_compare_by_identity -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/