Bug #15440 ยป 0001-Freeze-hash-literals-embedded-in-duphash-instruction.patch
compile.c | ||
---|---|---|
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_freeze(hash);
|
||
iseq_add_mark_object_compile_time(iseq, hash);
|
||
ADD_INSN1(ret, line, duphash, hash);
|
||
}
|
test/ruby/test_literal.rb | ||
---|---|---|
assert_equal "literal", h["string"]
|
||
end
|
||
def frozen_hash_literal_arg(x={0=>1,1=>4,2=>17})
|
||
x
|
||
end
|
||
def test_hash_literal_frozen
|
||
assert_raise(FrozenError){ObjectSpace.each_object(Hash){|a| a[3] = 8 if a.class == Hash && a[0] == 1 && a[1] == 4 && a[2] == 17}}
|
||
assert frozen_hash_literal_arg[3].nil?
|
||
end
|
||
def test_big_array_and_hash_literal
|
||
assert_normal_exit %q{GC.disable=true; x = nil; raise if eval("[#{(1..1_000_000).map{'x'}.join(", ")}]").size != 1_000_000}, "", timeout: 300, child_env: %[--disable-gems]
|
||
assert_normal_exit %q{GC.disable=true; x = nil; raise if eval("[#{(1..1_000_000).to_a.join(", ")}]").size != 1_000_000}, "", timeout: 300, child_env: %[--disable-gems]
|