summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authorglass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-03 04:55:51 +0000
committerglass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-03 04:55:51 +0000
commit95f983f6d0e5f1b2c9c26950cbfaa7cf323d3f1c (patch)
tree24b206ffb4466083cce931b783cc3c4ac61f5e70 /array.c
parent6edaf997e36f9d5b64f0e1349c987432c521f408 (diff)
* array.c (ary_add_hash): set and return values because string keys
will be frozen. [ruby-core:58809] [Bug #9202] * array.c (rb_ary_uniq_bang): ditto. * array.c (rb_ary_or): ditto. * array.c (rb_ary_uniq): ditto. * test/ruby/test_array.rb: tests for above. The patch is from normalperson (Eric Wong). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43969 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/array.c b/array.c
index 1a6af6e70a..8a71e2c8b7 100644
--- a/array.c
+++ b/array.c
@@ -3905,7 +3905,8 @@ ary_add_hash(VALUE hash, VALUE ary)
long i;
for (i=0; i<RARRAY_LEN(ary); i++) {
- rb_hash_aset(hash, RARRAY_AREF(ary, i), Qtrue);
+ VALUE elt = RARRAY_AREF(ary, i);
+ rb_hash_aset(hash, elt, elt);
}
return hash;
}
@@ -4056,15 +4057,15 @@ rb_ary_or(VALUE ary1, VALUE ary2)
ary2 = to_ary(ary2);
hash = ary_add_hash(ary_make_hash(ary1), ary2);
- ary3 = rb_hash_keys(hash);
+ ary3 = rb_hash_values(hash);
ary_recycle_hash(hash);
return ary3;
}
static int
-push_key(st_data_t key, st_data_t val, st_data_t ary)
+push_val(st_data_t key, st_data_t val, st_data_t ary)
{
- rb_ary_push((VALUE)ary, (VALUE)key);
+ rb_ary_push((VALUE)ary, (VALUE)val);
return ST_CONTINUE;
}
@@ -4137,7 +4138,7 @@ rb_ary_uniq_bang(VALUE ary)
FL_SET_EMBED(ary);
}
ary_resize_capa(ary, hash_size);
- st_foreach(rb_hash_tbl_raw(hash), push_key, ary);
+ st_foreach(rb_hash_tbl_raw(hash), push_val, ary);
}
ary_recycle_hash(hash);
@@ -4176,7 +4177,7 @@ rb_ary_uniq(VALUE ary)
}
else {
hash = ary_make_hash(ary);
- uniq = rb_hash_keys(hash);
+ uniq = rb_hash_values(hash);
}
RBASIC_SET_CLASS(uniq, rb_obj_class(ary));
ary_recycle_hash(hash);