mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
hash.c: add warnings
* hash.c (rb_hash_reject): warn attributes in detail more. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44262 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f38a2926e0
commit
cf460c34f7
1 changed files with 31 additions and 12 deletions
43
hash.c
43
hash.c
|
@ -27,9 +27,11 @@
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define HAS_MISC_ATTRIBUTES(hash) \
|
#define HAS_MISC_ATTRIBUTES(hash, klass) ( \
|
||||||
(FL_TEST((hash), FL_EXIVAR|FL_TAINT|HASH_PROC_DEFAULT) || \
|
(klass = rb_obj_class(hash)) != rb_cHash || \
|
||||||
!NIL_P(RHASH_IFNONE(hash)))
|
(klass = 0, \
|
||||||
|
FL_TEST((hash), FL_EXIVAR|FL_TAINT|HASH_PROC_DEFAULT) || \
|
||||||
|
!NIL_P(RHASH_IFNONE(hash))))
|
||||||
#define HASH_REJECT_COPY_MISC_ATTRIBUTES 0
|
#define HASH_REJECT_COPY_MISC_ATTRIBUTES 0
|
||||||
|
|
||||||
static VALUE rb_hash_s_try_convert(VALUE, VALUE);
|
static VALUE rb_hash_s_try_convert(VALUE, VALUE);
|
||||||
|
@ -1129,19 +1131,36 @@ rb_hash_reject(VALUE hash)
|
||||||
VALUE result;
|
VALUE result;
|
||||||
|
|
||||||
RETURN_SIZED_ENUMERATOR(hash, 0, 0, hash_enum_size);
|
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
|
#if HASH_REJECT_COPY_MISC_ATTRIBUTES
|
||||||
# if 0
|
rb_warn("copying unguaranteed attributes: %+"PRIsVALUE, hash);
|
||||||
if (HAS_MISC_ATTRIBUTES(has)) {
|
rb_warn("following atributes will not be copied in the future version:");
|
||||||
rb_warn("copying unguaranteed attributes")
|
if (klass != rb_cHash) {
|
||||||
|
rb_warn(" subclass: %+"PRIsVALUE, klass);
|
||||||
|
}
|
||||||
|
if (FL_TEST(hash, FL_EXIVAR)) {
|
||||||
|
rb_warn(" instance variables: %+"PRIsVALUE,
|
||||||
|
rb_obj_instance_variables(hash));
|
||||||
|
}
|
||||||
|
if (FL_TEST(hash, FL_TAINT)) {
|
||||||
|
rb_warn(" taintedness");
|
||||||
|
}
|
||||||
|
if (FL_TEST(hash, HASH_PROC_DEFAULT)) {
|
||||||
|
rb_warn(" default proc: %+"PRIsVALUE, RHASH_IFNONE(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:");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
# endif
|
#if HASH_REJECT_COPY_MISC_ATTRIBUTES
|
||||||
result = rb_hash_dup_empty(hash);
|
result = rb_hash_dup_empty(hash);
|
||||||
#else
|
#else
|
||||||
# if 0
|
|
||||||
if (HAS_MISC_ATTRIBUTES(has)) {
|
|
||||||
rb_warn("unguaranteed attributes are not copied")
|
|
||||||
}
|
|
||||||
# endif
|
|
||||||
result = rb_hash_new();
|
result = rb_hash_new();
|
||||||
#endif
|
#endif
|
||||||
if (!RHASH_EMPTY_P(hash)) {
|
if (!RHASH_EMPTY_P(hash)) {
|
||||||
|
|
Loading…
Reference in a new issue