ruby-changes:54258
From: ko1 <ko1@a...>
Date: Thu, 20 Dec 2018 16:18:04 +0900 (JST)
Subject: [ruby-changes:54258] ko1:r66466 (trunk): hide iseq operand object for duphash. [Bug #15440]
ko1 2018-12-20 16:17:55 +0900 (Thu, 20 Dec 2018) New Revision: 66466 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66466 Log: 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. Modified files: trunk/compile.c trunk/hash.c trunk/insns.def trunk/internal.h trunk/test/ruby/test_literal.rb Index: insns.def =================================================================== --- insns.def (revision 66465) +++ insns.def (revision 66466) @@ -461,7 +461,7 @@ duphash https://github.com/ruby/ruby/blob/trunk/insns.def#L461 () (VALUE val) { - val = rb_hash_dup(hash); + val = rb_hash_resurrect(hash); } /* if TOS is an array expand, expand it to num objects. Index: internal.h =================================================================== --- internal.h (revision 66465) +++ internal.h (revision 66466) @@ -1573,6 +1573,7 @@ VALUE rb_hash_key_str(VALUE); https://github.com/ruby/ruby/blob/trunk/internal.h#L1573 VALUE rb_hash_keys(VALUE hash); VALUE rb_hash_values(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); VALUE rb_hash_set_pair(VALUE hash, VALUE pair); void rb_hash_bulk_insert(long, const VALUE *, VALUE); Index: compile.c =================================================================== --- compile.c (revision 66465) +++ compile.c (revision 66466) @@ -4026,8 +4026,7 @@ compile_array(rb_iseq_t *iseq, LINK_ANCH https://github.com/ruby/ruby/blob/trunk/compile.c#L4026 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); + iseq_add_mark_object_compile_time(iseq, rb_obj_hide(hash)); ADD_INSN1(ret, line, duphash, hash); } } Index: hash.c =================================================================== --- hash.c (revision 66465) +++ hash.c (revision 66466) @@ -1310,6 +1310,13 @@ rb_hash_dup(VALUE hash) https://github.com/ruby/ruby/blob/trunk/hash.c#L1310 return ret; } +MJIT_FUNC_EXPORTED VALUE +rb_hash_resurrect(VALUE hash) +{ + VALUE ret = hash_dup(hash, rb_cHash, 0); + return ret; +} + static void rb_hash_modify_check(VALUE hash) { Index: test/ruby/test_literal.rb =================================================================== --- test/ruby/test_literal.rb (revision 66465) +++ test/ruby/test_literal.rb (revision 66466) @@ -290,12 +290,10 @@ class TestRubyLiteral < Test::Unit::Test https://github.com/ruby/ruby/blob/trunk/test/ruby/test_literal.rb#L290 {0=>1,1=>4,2=>17} end - assert_not_include frozen_hash_literal_arg, 3 - assert_raise(FrozenError) do - ObjectSpace.each_object(Hash) do |a| - 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 - end + ObjectSpace.each_object(Hash) do |a| + if a.class == Hash and !a.default_proc and a.size == 3 + # should not be found. + raise end end assert_not_include frozen_hash_literal_arg, 3 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/