From e3dbe84e12b3ebe95187edc3a5e9fe2f373a0388 Mon Sep 17 00:00:00 2001 From: ko1 Date: Wed, 9 Jan 2019 19:11:32 +0000 Subject: [PATCH] add setter of iter_lev. * hash.c: add special setter function (inc and dec). * internal.h: constify RHash::iter_leve. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66765 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- hash.c | 18 +++++++++++++++--- internal.h | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/hash.c b/hash.c index 7395eb5914..dd94ffd4a5 100644 --- a/hash.c +++ b/hash.c @@ -1206,17 +1206,29 @@ hash_foreach_iter(st_data_t key, st_data_t value, st_data_t argp, int error) return ST_CHECK; } +static void +hash_iter_lev_inc(VALUE hash) +{ + *((int *)&RHASH(hash)->iter_lev) = RHASH_ITER_LEV(hash) + 1; +} + +static void +hash_iter_lev_dec(VALUE hash) +{ + *((int *)&RHASH(hash)->iter_lev) = RHASH_ITER_LEV(hash) - 1; +} + static VALUE hash_foreach_ensure_rollback(VALUE hash) { - RHASH_ITER_LEV(hash)++; + hash_iter_lev_inc(hash); return 0; } static VALUE hash_foreach_ensure(VALUE hash) { - RHASH_ITER_LEV(hash)--; + hash_iter_lev_dec(hash); return 0; } @@ -1257,7 +1269,7 @@ rb_hash_foreach(VALUE hash, int (*func)(ANYARGS), VALUE farg) if (RHASH_TABLE_EMPTY_P(hash)) return; - RHASH_ITER_LEV(hash)++; + hash_iter_lev_inc(hash); arg.hash = hash; arg.func = (rb_foreach_func *)func; arg.arg = farg; diff --git a/internal.h b/internal.h index 3205050ec2..867beceb02 100644 --- a/internal.h +++ b/internal.h @@ -806,7 +806,7 @@ struct RHash { st_table *st; struct ar_table_struct *ar; /* possibly 0 */ } as; - int iter_lev; + const int iter_lev; const VALUE ifnone; };