mark created frozen strings.
* hash.c (rb_hash_new_from_values_with_klass): before this fix, only a st table are filled with passed values. However, newly created frozen strings are not marked correctly only reference from st table. This patch marks such created frozen strings by Hash object which refers to the st table. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58434 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
34f1488895
commit
a7db632088
9
hash.c
9
hash.c
@ -639,8 +639,8 @@ hash_insert_raw(st_table *tbl, VALUE key, VALUE val)
|
|||||||
{
|
{
|
||||||
st_data_t v = (st_data_t)val;
|
st_data_t v = (st_data_t)val;
|
||||||
st_data_t k = (rb_obj_class(key) == rb_cString) ?
|
st_data_t k = (rb_obj_class(key) == rb_cString) ?
|
||||||
(st_data_t)rb_str_new_frozen(key) :
|
(st_data_t)rb_str_new_frozen(key) :
|
||||||
(st_data_t)key;
|
(st_data_t)key;
|
||||||
|
|
||||||
return st_insert(tbl, k, v);
|
return st_insert(tbl, k, v);
|
||||||
}
|
}
|
||||||
@ -650,19 +650,22 @@ rb_hash_new_from_values_with_klass(long argc, const VALUE *argv, VALUE klass)
|
|||||||
{
|
{
|
||||||
long i;
|
long i;
|
||||||
st_table *t;
|
st_table *t;
|
||||||
|
VALUE v;
|
||||||
|
|
||||||
if (argc % 2) {
|
if (argc % 2) {
|
||||||
rb_raise(rb_eArgError, "odd number of arguments for Hash");
|
rb_raise(rb_eArgError, "odd number of arguments for Hash");
|
||||||
}
|
}
|
||||||
|
|
||||||
t = st_init_table_with_size(&objhash, argc / 2);
|
t = st_init_table_with_size(&objhash, argc / 2);
|
||||||
|
v = hash_alloc_from_st(klass, t);
|
||||||
|
|
||||||
for (i = 0; i < argc; /* */) {
|
for (i = 0; i < argc; /* */) {
|
||||||
VALUE key = argv[i++];
|
VALUE key = argv[i++];
|
||||||
VALUE val = argv[i++];
|
VALUE val = argv[i++];
|
||||||
|
|
||||||
hash_insert_raw(t, key, val);
|
hash_insert_raw(t, key, val);
|
||||||
}
|
}
|
||||||
return hash_alloc_from_st(klass, t);
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user