summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-14 02:35:40 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-14 02:35:40 +0000
commit04c7fa0f3b96ce7d94c85f2728a53d3984a66937 (patch)
tree70a78fb5ba0107610816cf7a88737a942b6ba9c7 /hash.c
parentb0af0592fdd9e9d4e4b863fde006d67ccefeac21 (diff)
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43675 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/hash.c b/hash.c
index a37318b..754685e 100644
--- a/hash.c
+++ b/hash.c
@@ -173,6 +173,7 @@ struct hash_foreach_arg {
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_t value, st_data_t argp, int error)
}
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)(ANYARGS), VALUE farg)
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