mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
hide iseq operand object for duphash. [Bug #15440]
* compile.c (compile_array): hide source Hash object. * hash.c (rb_hash_resurrect): introduced to dup Hash object using rb_cHash. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66466 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
fe8475d7df
commit
2a70f68c05
5 changed files with 14 additions and 9 deletions
|
@ -4026,8 +4026,7 @@ compile_array(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node_ro
|
||||||
|
|
||||||
hash = rb_hash_new_with_size(RARRAY_LEN(ary) / 2);
|
hash = rb_hash_new_with_size(RARRAY_LEN(ary) / 2);
|
||||||
rb_hash_bulk_insert(RARRAY_LEN(ary), RARRAY_CONST_PTR_TRANSIENT(ary), hash);
|
rb_hash_bulk_insert(RARRAY_LEN(ary), RARRAY_CONST_PTR_TRANSIENT(ary), hash);
|
||||||
rb_hash_freeze(hash);
|
iseq_add_mark_object_compile_time(iseq, rb_obj_hide(hash));
|
||||||
iseq_add_mark_object_compile_time(iseq, hash);
|
|
||||||
ADD_INSN1(ret, line, duphash, hash);
|
ADD_INSN1(ret, line, duphash, hash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
7
hash.c
7
hash.c
|
@ -1310,6 +1310,13 @@ rb_hash_dup(VALUE hash)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MJIT_FUNC_EXPORTED VALUE
|
||||||
|
rb_hash_resurrect(VALUE hash)
|
||||||
|
{
|
||||||
|
VALUE ret = hash_dup(hash, rb_cHash, 0);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
rb_hash_modify_check(VALUE hash)
|
rb_hash_modify_check(VALUE hash)
|
||||||
{
|
{
|
||||||
|
|
|
@ -461,7 +461,7 @@ duphash
|
||||||
()
|
()
|
||||||
(VALUE val)
|
(VALUE val)
|
||||||
{
|
{
|
||||||
val = rb_hash_dup(hash);
|
val = rb_hash_resurrect(hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if TOS is an array expand, expand it to num objects.
|
/* if TOS is an array expand, expand it to num objects.
|
||||||
|
|
|
@ -1573,6 +1573,7 @@ VALUE rb_hash_key_str(VALUE);
|
||||||
VALUE rb_hash_keys(VALUE hash);
|
VALUE rb_hash_keys(VALUE hash);
|
||||||
VALUE rb_hash_values(VALUE hash);
|
VALUE rb_hash_values(VALUE hash);
|
||||||
VALUE rb_hash_rehash(VALUE hash);
|
VALUE rb_hash_rehash(VALUE hash);
|
||||||
|
VALUE rb_hash_resurrect(VALUE hash);
|
||||||
int rb_hash_add_new_element(VALUE hash, VALUE key, VALUE val);
|
int rb_hash_add_new_element(VALUE hash, VALUE key, VALUE val);
|
||||||
VALUE rb_hash_set_pair(VALUE hash, VALUE pair);
|
VALUE rb_hash_set_pair(VALUE hash, VALUE pair);
|
||||||
void rb_hash_bulk_insert(long, const VALUE *, VALUE);
|
void rb_hash_bulk_insert(long, const VALUE *, VALUE);
|
||||||
|
|
|
@ -290,12 +290,10 @@ class TestRubyLiteral < Test::Unit::TestCase
|
||||||
{0=>1,1=>4,2=>17}
|
{0=>1,1=>4,2=>17}
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_not_include frozen_hash_literal_arg, 3
|
|
||||||
assert_raise(FrozenError) do
|
|
||||||
ObjectSpace.each_object(Hash) do |a|
|
ObjectSpace.each_object(Hash) do |a|
|
||||||
if a.class == Hash and !a.default_proc and a.size == 3
|
if a.class == Hash and !a.default_proc and a.size == 3
|
||||||
a[3] = 8 if a[0] == 1 and a[1] == 4 and a[2] == 17
|
# should not be found.
|
||||||
end
|
raise
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
assert_not_include frozen_hash_literal_arg, 3
|
assert_not_include frozen_hash_literal_arg, 3
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue