ruby-changes:50616
From: nobu <ko1@a...>
Date: Fri, 16 Mar 2018 11:27:55 +0900 (JST)
Subject: [ruby-changes:50616] nobu:r62772 (trunk): compile.c: fix load_from_binary
nobu 2018-03-16 11:27:50 +0900 (Fri, 16 Mar 2018) New Revision: 62772 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62772 Log: compile.c: fix load_from_binary * compile.c (ibf_load_iseq_each): realpath may be nil. follow up r59709. [fix https://github.com/Shopify/bootsnap/issues/132] From: nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> Modified files: trunk/compile.c trunk/test/ruby/test_iseq.rb Index: compile.c =================================================================== --- compile.c (revision 62771) +++ compile.c (revision 62772) @@ -8773,7 +8773,15 @@ ibf_load_iseq_each(const struct ibf_load https://github.com/ruby/ruby/blob/trunk/compile.c#L8773 rb_raise(rb_eRuntimeError, "path object size mismatch"); } path = rb_fstring(RARRAY_AREF(pathobj, 0)); - realpath = rb_fstring(RARRAY_AREF(pathobj, 1)); + realpath = RARRAY_AREF(pathobj, 1); + if (!NIL_P(realpath)) { + if (!RB_TYPE_P(realpath, T_STRING)) { + rb_raise(rb_eArgError, "unexpected realpath %"PRIxVALUE + "(%x), path=%+"PRIsVALUE, + realpath, TYPE(realpath), path); + } + realpath = rb_fstring(realpath); + } } else { rb_raise(rb_eRuntimeError, "unexpected path object"); Index: test/ruby/test_iseq.rb =================================================================== --- test/ruby/test_iseq.rb (revision 62771) +++ test/ruby/test_iseq.rb (revision 62772) @@ -398,10 +398,9 @@ class TestISeq < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_iseq.rb#L398 def test_to_binary_with_objects code = "[]"+100.times.map{|i|"<</#{i}/"}.join - bin = assert_nothing_raised { - RubyVM::InstructionSequence.compile(code).to_binary - } - # load_from_binary doesn't work now - assert_instance_of(String, bin) + iseq = RubyVM::InstructionSequence.compile(code) + bin = assert_nothing_raised {iseq.to_binary} + iseq2 = RubyVM::InstructionSequence.load_from_binary(bin) + assert_equal(iseq2.to_a, iseq.to_a) end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/