mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
+ * ruby.c (load_file_internal2): Extracted from load_file_internal.
+ (load_file_internal): Invoke load_file_internal2 using rb_protect. + Close an opened FD if load_file_internal2 raises an exception. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46341 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7ad125d7d2
commit
fc3c52eb37
2 changed files with 71 additions and 39 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
Tue Jun 3 23:32:34 2014 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* ruby.c (load_file_internal2): Extracted from load_file_internal.
|
||||||
|
(load_file_internal): Invoke load_file_internal2 using rb_protect.
|
||||||
|
Close an opened FD if load_file_internal2 raises an exception.
|
||||||
|
|
||||||
Tue Jun 3 19:11:45 2014 Koichi Sasada <ko1@atdot.net>
|
Tue Jun 3 19:11:45 2014 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
* gc.c (rb_objspace_free): should not rest_sweep() here.
|
* gc.c (rb_objspace_free): should not rest_sweep() here.
|
||||||
|
|
104
ruby.c
104
ruby.c
|
@ -1515,57 +1515,24 @@ struct load_file_arg {
|
||||||
VALUE fname;
|
VALUE fname;
|
||||||
int script;
|
int script;
|
||||||
struct cmdline_options *opt;
|
struct cmdline_options *opt;
|
||||||
|
VALUE f;
|
||||||
|
int xflag;
|
||||||
};
|
};
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
load_file_internal(VALUE arg)
|
load_file_internal2(VALUE argp_v)
|
||||||
{
|
{
|
||||||
extern VALUE rb_stdin;
|
struct load_file_arg *argp = (struct load_file_arg *)argp_v;
|
||||||
struct load_file_arg *argp = (struct load_file_arg *)arg;
|
|
||||||
VALUE parser = argp->parser;
|
VALUE parser = argp->parser;
|
||||||
VALUE orig_fname = argp->fname;
|
VALUE orig_fname = argp->fname;
|
||||||
VALUE fname_v = rb_str_encode_ospath(orig_fname);
|
|
||||||
const char *fname = StringValueCStr(fname_v);
|
|
||||||
int script = argp->script;
|
int script = argp->script;
|
||||||
struct cmdline_options *opt = argp->opt;
|
struct cmdline_options *opt = argp->opt;
|
||||||
VALUE f;
|
VALUE f = argp->f;
|
||||||
int line_start = 1;
|
int line_start = 1;
|
||||||
NODE *tree = 0;
|
NODE *tree = 0;
|
||||||
rb_encoding *enc;
|
rb_encoding *enc;
|
||||||
ID set_encoding;
|
ID set_encoding;
|
||||||
int xflag = 0;
|
int xflag = argp->xflag;
|
||||||
|
|
||||||
if (strcmp(fname, "-") == 0) {
|
|
||||||
f = rb_stdin;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
int fd, mode = O_RDONLY;
|
|
||||||
#if defined DOSISH || defined __CYGWIN__
|
|
||||||
{
|
|
||||||
const char *ext = strrchr(fname, '.');
|
|
||||||
if (ext && STRCASECMP(ext, ".exe") == 0) {
|
|
||||||
mode |= O_BINARY;
|
|
||||||
xflag = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if ((fd = rb_cloexec_open(fname, mode, 0)) < 0) {
|
|
||||||
rb_load_fail(fname_v, strerror(errno));
|
|
||||||
}
|
|
||||||
rb_update_max_fd(fd);
|
|
||||||
#if !defined DOSISH && !defined __CYGWIN__
|
|
||||||
{
|
|
||||||
struct stat st;
|
|
||||||
if (fstat(fd, &st) != 0)
|
|
||||||
rb_load_fail(fname_v, strerror(errno));
|
|
||||||
if (S_ISDIR(st.st_mode)) {
|
|
||||||
errno = EISDIR;
|
|
||||||
rb_load_fail(fname_v, strerror(EISDIR));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
f = rb_io_fdopen(fd, mode, fname);
|
|
||||||
}
|
|
||||||
|
|
||||||
CONST_ID(set_encoding, "set_encoding");
|
CONST_ID(set_encoding, "set_encoding");
|
||||||
if (script) {
|
if (script) {
|
||||||
|
@ -1664,6 +1631,65 @@ load_file_internal(VALUE arg)
|
||||||
rb_funcall(f, set_encoding, 2, rb_enc_from_encoding(enc), rb_str_new_cstr("-"));
|
rb_funcall(f, set_encoding, 2, rb_enc_from_encoding(enc), rb_str_new_cstr("-"));
|
||||||
tree = rb_parser_compile_file_path(parser, orig_fname, f, line_start);
|
tree = rb_parser_compile_file_path(parser, orig_fname, f, line_start);
|
||||||
rb_funcall(f, set_encoding, 1, rb_parser_encoding(parser));
|
rb_funcall(f, set_encoding, 1, rb_parser_encoding(parser));
|
||||||
|
return (VALUE)tree;
|
||||||
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
load_file_internal(VALUE arg)
|
||||||
|
{
|
||||||
|
extern VALUE rb_stdin;
|
||||||
|
struct load_file_arg *argp = (struct load_file_arg *)arg;
|
||||||
|
VALUE parser = argp->parser;
|
||||||
|
VALUE orig_fname = argp->fname;
|
||||||
|
VALUE fname_v = rb_str_encode_ospath(orig_fname);
|
||||||
|
const char *fname = StringValueCStr(fname_v);
|
||||||
|
int script = argp->script;
|
||||||
|
VALUE f;
|
||||||
|
NODE *tree;
|
||||||
|
int xflag = 0;
|
||||||
|
int state;
|
||||||
|
|
||||||
|
if (strcmp(fname, "-") == 0) {
|
||||||
|
f = rb_stdin;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int fd, mode = O_RDONLY;
|
||||||
|
#if defined DOSISH || defined __CYGWIN__
|
||||||
|
{
|
||||||
|
const char *ext = strrchr(fname, '.');
|
||||||
|
if (ext && STRCASECMP(ext, ".exe") == 0) {
|
||||||
|
mode |= O_BINARY;
|
||||||
|
xflag = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if ((fd = rb_cloexec_open(fname, mode, 0)) < 0) {
|
||||||
|
rb_load_fail(fname_v, strerror(errno));
|
||||||
|
}
|
||||||
|
rb_update_max_fd(fd);
|
||||||
|
#if !defined DOSISH && !defined __CYGWIN__
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
if (fstat(fd, &st) != 0)
|
||||||
|
rb_load_fail(fname_v, strerror(errno));
|
||||||
|
if (S_ISDIR(st.st_mode)) {
|
||||||
|
errno = EISDIR;
|
||||||
|
rb_load_fail(fname_v, strerror(EISDIR));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
f = rb_io_fdopen(fd, mode, fname);
|
||||||
|
}
|
||||||
|
|
||||||
|
argp->f = f;
|
||||||
|
argp->xflag = xflag;
|
||||||
|
tree = (NODE *)rb_protect(load_file_internal2, (VALUE)argp, &state);
|
||||||
|
if (state) {
|
||||||
|
if (f != rb_stdin)
|
||||||
|
rb_io_close(f);
|
||||||
|
rb_jump_tag(state);
|
||||||
|
}
|
||||||
|
|
||||||
if (script && tree && rb_parser_end_seen_p(parser)) {
|
if (script && tree && rb_parser_end_seen_p(parser)) {
|
||||||
/*
|
/*
|
||||||
* DATA is a File that contains the data section of the executed file.
|
* DATA is a File that contains the data section of the executed file.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue