ruby-changes:63798
From: Nobuyoshi <ko1@a...>
Date: Mon, 30 Nov 2020 15:20:08 +0900 (JST)
Subject: [ruby-changes:63798] 555bd83a8e (master): Raise when loading unprovided builtin function [Bug #17192]
https://git.ruby-lang.org/ruby.git/commit/?id=555bd83a8e From 555bd83a8e8b1e859f698089cbbd9ad938159a0e Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Mon, 30 Nov 2020 15:19:49 +0900 Subject: Raise when loading unprovided builtin function [Bug #17192] diff --git a/compile.c b/compile.c index f6f5a1d..0525c3e 100644 --- a/compile.c +++ b/compile.c @@ -10296,14 +10296,13 @@ ibf_load_builtin(const struct ibf_load *load, ibf_offset_t *offset) https://github.com/ruby/ruby/blob/trunk/compile.c#L10296 const char *name = (char *)ibf_load_ptr(load, offset, len); if (0) { - for (int i=0; i<len; i++) fprintf(stderr, "%c", name[i]); - fprintf(stderr, "!!\n"); + fprintf(stderr, "%.*s!!\n", len, name); } const struct rb_builtin_function *table = GET_VM()->builtin_function_table; - if (table == NULL) rb_bug("%s: table is not provided.", RUBY_FUNCTION_NAME_STRING); + if (table == NULL) rb_raise(rb_eArgError, "builtin function table is not provided"); if (strncmp(table[i].name, name, len) != 0) { - rb_bug("%s: index (%d) mismatch (expect %s but %s).", RUBY_FUNCTION_NAME_STRING, i, name, table[i].name); + rb_raise(rb_eArgError, "builtin function index (%d) mismatch (expect %s but %s)", i, name, table[i].name); } // fprintf(stderr, "load-builtin: name:%s(%d)\n", table[i].name, table[i].argc); diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb index 78be07d..e3ca1ba 100644 --- a/test/ruby/test_iseq.rb +++ b/test/ruby/test_iseq.rb @@ -590,6 +590,21 @@ class TestISeq < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_iseq.rb#L590 assert_equal([:func_ptr, :argc, :index, :name], invokebuiltin[1].keys) end + def test_iseq_builtin_load + Tempfile.create(["builtin", ".iseq"]) do |f| + f.binmode + f.write(RubyVM::InstructionSequence.of(1.method(:abs)).to_binary) + f.close + assert_separately(["-", f.path], "#{<<~"begin;"}\n#{<<~'end;'}") + begin; + bin = File.binread(ARGV[0]) + assert_raise(ArgumentError) do + RubyVM::InstructionSequence.load_from_binary(bin) + end + end; + end + end + def test_iseq_option_debug_level assert_raise(TypeError) {ISeq.compile("", debug_level: "")} assert_ruby_status([], "#{<<~"begin;"}\n#{<<~'end;'}") -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/