Commit 543ac88e authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #2947 from kazuho/kazuho/freeze-hash-key

freeze the hash keys (fixes #2945)
parents 1cbbb7e1 8256d77c
......@@ -104,10 +104,11 @@ static void mrb_hash_modify(mrb_state *mrb, mrb_value hash);
static inline mrb_value
mrb_hash_ht_key(mrb_state *mrb, mrb_value key)
{
if (mrb_string_p(key))
return mrb_str_dup(mrb, key);
else
return key;
if (mrb_string_p(key) && !RSTR_FROZEN_P(mrb_str_ptr(key))) {
key = mrb_str_dup(mrb, key);
RSTR_SET_FROZEN_FLAG(mrb_str_ptr(key));
}
return key;
}
#define KEY(key) mrb_hash_ht_key(mrb, key)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment