Project

General

Profile

Feature #14258 ยป 0001-hash-literal-deduplicates-like-Hash.patch

normalperson (Eric Wong), 12/29/2017 08:51 AM

View differences:

hash.c
}
}
VALUE
rb_hash_key_str(VALUE key)
{
VALUE k;
if (!RB_OBJ_TAINTED(key) &&
(k = fstring_existing_str(key)) != Qnil) {
return k;
}
else {
return rb_str_new_frozen(key);
}
}
static int
hash_aset_str(st_data_t *key, st_data_t *val, struct update_arg *arg, int existing)
{
if (!existing && !RB_OBJ_FROZEN(*key)) {
VALUE k;
if (!RB_OBJ_TAINTED(*key) &&
(k = fstring_existing_str(*key)) != Qnil) {
*key = k;
}
else {
*key = rb_str_new_frozen(*key);
}
*key = rb_hash_key_str(*key);
}
return hash_aset(key, val, arg, existing);
}
internal.h
st_table *rb_init_identtable_with_size(st_index_t size);
VALUE rb_hash_compare_by_id_p(VALUE hash);
VALUE rb_to_hash_type(VALUE obj);
VALUE rb_hash_key_str(VALUE);
#define RHASH_TBL_RAW(h) rb_hash_tbl_raw(h)
VALUE rb_hash_keys(VALUE hash);
st.c
static st_data_t
st_stringify(VALUE key)
{
return (rb_obj_class(key) == rb_cString) ?
rb_str_new_frozen(key) : key;
return (rb_obj_class(key) == rb_cString && !RB_OBJ_FROZEN(key)) ?
rb_hash_key_str(key) : key;
}
static void
test/ruby/test_hash.rb
b = {"ABC" => :t}
assert_same a.keys[0], b.keys[0]
assert_same "ABC".freeze, a.keys[0]
var = +'ABC'
c = { var => :t }
assert_same "ABC".freeze, c.keys[0]
end
def test_tainted_string_key
-
    (1-1/1)