diff options
author | Koichi Sasada <ko1@atdot.net> | 2019-08-01 11:20:37 +0900 |
---|---|---|
committer | Koichi Sasada <ko1@atdot.net> | 2019-08-01 11:22:43 +0900 |
commit | 746386710646f93a5b9e0c408b00408041645091 (patch) | |
tree | 8db40e56ff71858a4d327d96c05abf00759457ce | |
parent | 67f7e5a224bc31e1625023ce1ed5cfbd54ea1d8f (diff) | |
download | ruby-746386710646f93a5b9e0c408b00408041645091.tar.gz |
use internal_id.
"hash_iter_lev" can be exported by Marshal.dump and it will
introduce inconsistency. To avoid this issue, use internal_id
instead of normal ID. This issue is pointed out by Chikanaga-san.
-rw-r--r-- | hash.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -90,6 +90,7 @@ VALUE rb_cHash; static VALUE envtbl; static ID id_hash, id_yield, id_default, id_flatten_bang; +static ID id_hash_iter_lev; VALUE rb_hash_set_ifnone(VALUE hash, VALUE ifnone) @@ -1313,7 +1314,7 @@ hash_foreach_iter(st_data_t key, st_data_t value, st_data_t argp, int error) static int iter_lev_in_ivar(VALUE hash) { - VALUE levval = rb_ivar_get(hash, rb_intern("hash_iter_lev")); + VALUE levval = rb_ivar_get(hash, id_hash_iter_lev); HASH_ASSERT(FIXNUM_P(levval)); return FIX2INT(levval); } @@ -1323,7 +1324,7 @@ void rb_ivar_set_internal(VALUE obj, ID id, VALUE val); static void iter_lev_in_ivar_set(VALUE hash, int lev) { - rb_ivar_set_internal(hash, rb_intern("hash_iter_lev"), INT2FIX(lev)); + rb_ivar_set_internal(hash, id_hash_iter_lev, INT2FIX(lev)); } static int @@ -6048,6 +6049,7 @@ Init_Hash(void) id_yield = rb_intern("yield"); id_default = rb_intern("default"); id_flatten_bang = rb_intern("flatten!"); + id_hash_iter_lev = rb_make_internal_id(); rb_cHash = rb_define_class("Hash", rb_cObject); |