Bug #12943 ยป 0001-iseq.c-syntax-error-in-compile_file.patch
ChangeLog | ||
---|---|---|
Tue Sep 27 17:35:28 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||
* iseq.c (iseqw_s_compile_file): deal with syntax error as well as
|
||
compile, and should not abort when rescued.
|
||
Tue Nov 15 03:14:02 2016 NARUSE, Yui <naruse@ruby-lang.org>
|
||
* ext/-test/file/fs.c (get_atime_p): Updating of file access times
|
iseq.c | ||
---|---|---|
iseqw_s_compile_file(int argc, VALUE *argv, VALUE self)
|
||
{
|
||
VALUE file, line = INT2FIX(1), opt = Qnil;
|
||
VALUE parser;
|
||
VALUE f;
|
||
VALUE parser, f, exc = Qnil;
|
||
NODE *node;
|
||
const char *fname;
|
||
rb_compile_option_t option;
|
||
... | ... | |
parser = rb_parser_new();
|
||
node = rb_parser_compile_file(parser, fname, f, NUM2INT(line));
|
||
if (!node) exc = GET_THREAD()->errinfo;
|
||
rb_io_close(f);
|
||
if (!node) rb_exc_raise(exc);
|
||
make_compile_option(&option, opt);
|
||
test/ruby/test_iseq.rb | ||
---|---|---|
require 'test/unit'
|
||
require 'tempfile'
|
||
class TestISeq < Test::Unit::TestCase
|
||
ISeq = RubyVM::InstructionSequence
|
||
... | ... | |
at_exit { assert_equal([:n, :x], Segfault.new.segfault.sort) }
|
||
end;
|
||
end
|
||
def test_compile_file_error
|
||
Tempfile.create(%w"test_iseq .rb") do |f|
|
||
f.puts "end"
|
||
f.close
|
||
path = f.path
|
||
assert_in_out_err(%W[- #{path}], "#{<<-"begin;"}\n#{<<-"end;"}", /compile error/, /keyword_end/)
|
||
begin;
|
||
path = ARGV[0]
|
||
begin
|
||
RubyVM::InstructionSequence.compile_file(path)
|
||
rescue SyntaxError => e
|
||
puts e.message
|
||
end
|
||
end;
|
||
end
|
||
end
|
||
end
|