diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-01-23 02:17:40 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-01-23 02:17:40 +0000 |
commit | ba97a56685bda66d60978d8e27f44e995a68a6ed (patch) | |
tree | 25907a05db8988707156131ae4b26f1da0fb8c8f /hash.c | |
parent | 111cbcb3d9a8307707cbbbbc8585f6a61e088895 (diff) |
merge revision(s) 44358,44359,44360,44363: [Backport #9275]
hash.c: reword
* hash.c (HAS_EXTRA_STATES, rb_hash_reject): use words "extra states".
* hash.c (HAS_EXTRA_STATES): warn extra states only when something
differ. [ruby-core:59254] [Bug #9275]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@44683 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r-- | hash.c | 37 |
1 files changed, 24 insertions, 13 deletions
@@ -27,12 +27,24 @@ # endif #endif -#define HAS_MISC_ATTRIBUTES(hash, klass) ( \ - (klass = rb_obj_class(hash)) != rb_cHash || \ - (klass = 0, \ - FL_TEST((hash), FL_EXIVAR|FL_TAINT|HASH_PROC_DEFAULT) || \ - !NIL_P(RHASH_IFNONE(hash)))) -#define HASH_REJECT_COPY_MISC_ATTRIBUTES 1 +#define HAS_EXTRA_STATES(hash, klass) ( \ + ((klass = has_extra_methods(rb_obj_class(hash))) != 0) || \ + FL_TEST((hash), FL_EXIVAR|FL_TAINT|HASH_PROC_DEFAULT) || \ + !NIL_P(RHASH_IFNONE(hash))) +#define HASH_REJECT_COPY_EXTRA_STATES 1 + +static VALUE +has_extra_methods(VALUE klass) +{ + const VALUE base = rb_cHash; + VALUE c = klass; + while (c != base) { + st_table *mtbl = RCLASS_M_TBL(c); + if (mtbl && mtbl->num_entries) return klass; + c = RCLASS_SUPER(c); + } + return 0; +} static VALUE rb_hash_s_try_convert(VALUE, VALUE); @@ -1133,11 +1145,11 @@ rb_hash_reject(VALUE hash) RETURN_SIZED_ENUMERATOR(hash, 0, 0, hash_enum_size); if (RTEST(ruby_verbose)) { VALUE klass; - if (HAS_MISC_ATTRIBUTES(hash, klass)) { -#if HASH_REJECT_COPY_MISC_ATTRIBUTES - rb_warn("copying unguaranteed attributes: %+"PRIsVALUE, hash); - rb_warn("following atributes will not be copied in the future version:"); - if (klass != rb_cHash) { + if (HAS_EXTRA_STATES(hash, klass)) { +#if HASH_REJECT_COPY_EXTRA_STATES + rb_warn("copying extra states: %+"PRIsVALUE, hash); + rb_warn("following states will not be copied in the future version:"); + if (klass) { rb_warn(" subclass: %+"PRIsVALUE, klass); } if (FL_TEST(hash, FL_EXIVAR)) { @@ -1153,8 +1165,7 @@ rb_hash_reject(VALUE hash) else if (!NIL_P(RHASH_IFNONE(hash))) rb_warn(" default value: %+"PRIsVALUE, RHASH_IFNONE(hash)); #else - rb_warn("unguaranteed attributes are not copied: %+"PRIsVALUE, hash); - rb_warn("following atributes are ignored now:"); + rb_warn("extra states are no longer copied: %+"PRIsVALUE, hash); #endif } } |