iseq.c: syntax error in compile_file
* iseq.c (iseqw_s_compile_file): deal with syntax error as well as compile, and should not abort when rescued. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56268 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
2ca58e4290
commit
a38b2f84f4
@ -1,3 +1,8 @@
|
|||||||
|
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 Sep 27 12:07:17 2016 NARUSE, Yui <naruse@ruby-lang.org>
|
Tue Sep 27 12:07:17 2016 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
* lib/cgi/cookie.rb (parse): don't allow , as a separator. [Bug #12791]
|
* lib/cgi/cookie.rb (parse): don't allow , as a separator. [Bug #12791]
|
||||||
|
6
iseq.c
6
iseq.c
@ -823,8 +823,7 @@ static VALUE
|
|||||||
iseqw_s_compile_file(int argc, VALUE *argv, VALUE self)
|
iseqw_s_compile_file(int argc, VALUE *argv, VALUE self)
|
||||||
{
|
{
|
||||||
VALUE file, line = INT2FIX(1), opt = Qnil;
|
VALUE file, line = INT2FIX(1), opt = Qnil;
|
||||||
VALUE parser;
|
VALUE parser, f, exc = Qnil;
|
||||||
VALUE f;
|
|
||||||
NODE *node;
|
NODE *node;
|
||||||
rb_compile_option_t option;
|
rb_compile_option_t option;
|
||||||
int i;
|
int i;
|
||||||
@ -841,9 +840,12 @@ iseqw_s_compile_file(int argc, VALUE *argv, VALUE self)
|
|||||||
f = rb_file_open_str(file, "r");
|
f = rb_file_open_str(file, "r");
|
||||||
|
|
||||||
parser = rb_parser_new();
|
parser = rb_parser_new();
|
||||||
|
rb_parser_set_context(parser, NULL, FALSE);
|
||||||
node = rb_parser_compile_file_path(parser, file, f, NUM2INT(line));
|
node = rb_parser_compile_file_path(parser, file, f, NUM2INT(line));
|
||||||
|
if (!node) exc = GET_THREAD()->errinfo;
|
||||||
|
|
||||||
rb_io_close(f);
|
rb_io_close(f);
|
||||||
|
if (!node) rb_exc_raise(exc);
|
||||||
|
|
||||||
make_compile_option(&option, opt);
|
make_compile_option(&option, opt);
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
|
require 'tempfile'
|
||||||
|
|
||||||
class TestISeq < Test::Unit::TestCase
|
class TestISeq < Test::Unit::TestCase
|
||||||
ISeq = RubyVM::InstructionSequence
|
ISeq = RubyVM::InstructionSequence
|
||||||
@ -243,6 +244,23 @@ class TestISeq < Test::Unit::TestCase
|
|||||||
assert_send([e2, :start_with?, __FILE__])
|
assert_send([e2, :start_with?, __FILE__])
|
||||||
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;"}", /keyword_end/, [], success: true)
|
||||||
|
begin;
|
||||||
|
path = ARGV[0]
|
||||||
|
begin
|
||||||
|
RubyVM::InstructionSequence.compile_file(path)
|
||||||
|
rescue SyntaxError => e
|
||||||
|
puts e.message
|
||||||
|
end
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_translate_by_object
|
def test_translate_by_object
|
||||||
assert_separately([], <<-"end;")
|
assert_separately([], <<-"end;")
|
||||||
class Object
|
class Object
|
||||||
|
Loading…
x
Reference in New Issue
Block a user