ruby-changes:32168
From: nobu <ko1@a...>
Date: Mon, 16 Dec 2013 22:40:14 +0900 (JST)
Subject: [ruby-changes:32168] nobu:r44247 (trunk): hash.c: warnings in rb_hash_reject
nobu 2013-12-16 22:40:04 +0900 (Mon, 16 Dec 2013) New Revision: 44247 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44247 Log: hash.c: warnings in rb_hash_reject * hash.c (rb_hash_dup_empty): split from rb_hash_dup. * hash.c (rb_hash_reject): add warnings (currently suppressed). Modified files: trunk/hash.c Index: hash.c =================================================================== --- hash.c (revision 44246) +++ hash.c (revision 44247) @@ -27,6 +27,11 @@ https://github.com/ruby/ruby/blob/trunk/hash.c#L27 # endif #endif +#define HAS_MISC_ATTRIBUTES(hash) \ + (FL_TEST((hash), FL_EXIVAR|FL_TAINT|HASH_PROC_DEFAULT) || \ + !NIL_P(RHASH_IFNONE(hash))) +#define HASH_REJECT_COPY_MISC_ATTRIBUTES 0 + static VALUE rb_hash_s_try_convert(VALUE, VALUE); /* @@ -272,8 +277,8 @@ rb_hash_new(void) https://github.com/ruby/ruby/blob/trunk/hash.c#L277 return hash_alloc(rb_cHash); } -VALUE -rb_hash_dup(VALUE hash) +static VALUE +rb_hash_dup_empty(VALUE hash) { NEWOBJ_OF(ret, struct RHash, rb_obj_class(hash), @@ -281,8 +286,6 @@ rb_hash_dup(VALUE hash) https://github.com/ruby/ruby/blob/trunk/hash.c#L286 if (FL_TEST((hash), FL_EXIVAR)) rb_copy_generic_ivar((VALUE)(ret),(VALUE)(hash)); - if (!RHASH_EMPTY_P(hash)) - ret->ntbl = st_copy(RHASH(hash)->ntbl); if (FL_TEST(hash, HASH_PROC_DEFAULT)) { FL_SET(ret, HASH_PROC_DEFAULT); } @@ -290,6 +293,15 @@ rb_hash_dup(VALUE hash) https://github.com/ruby/ruby/blob/trunk/hash.c#L293 return (VALUE)ret; } +VALUE +rb_hash_dup(VALUE hash) +{ + VALUE ret = rb_hash_dup_empty(hash); + if (!RHASH_EMPTY_P(hash)) + RHASH(ret)->ntbl = st_copy(RHASH(hash)->ntbl); + return ret; +} + static void rb_hash_modify_check(VALUE hash) { @@ -1117,7 +1129,21 @@ rb_hash_reject(VALUE hash) https://github.com/ruby/ruby/blob/trunk/hash.c#L1129 VALUE result; RETURN_SIZED_ENUMERATOR(hash, 0, 0, hash_enum_size); +#if HASH_REJECT_COPY_TRIVIAL_ATTRIBUTES +# if 0 + if (HAS_MISC_ATTRIBUTES(has)) { + rb_warn("copying unguaranteed attributes") + } +# endif + result = rb_hash_dup_empty(hash); +#else +# if 0 + if (HAS_MISC_ATTRIBUTES(has)) { + rb_warn("unguaranteed attributes are not copied") + } +# endif result = rb_hash_new(); +#endif if (!RHASH_EMPTY_P(hash)) { rb_hash_foreach(hash, reject_i, result); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/