io.c: open_key_args by rb_io_open

* io.c (open_key_args): open by rb_io_open always also when
  open_args: option is given.

From: Nobuyoshi Nakada <nobu@ruby-lang.org>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61314 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-12-18 03:38:20 +00:00
parent 2e24a66b88
commit 7d24c27d21

38
io.c
View File

@ -7097,16 +7097,6 @@ rb_io_open_generic(VALUE filename, int oflags, int fmode,
} }
} }
static VALUE
rb_io_open_with_args(int argc, const VALUE *argv)
{
VALUE io;
io = io_alloc(rb_cFile);
rb_open_file(argc, argv, io);
return io;
}
static VALUE static VALUE
io_reopen(VALUE io, VALUE nfile) io_reopen(VALUE io, VALUE nfile)
{ {
@ -10168,6 +10158,7 @@ static void
open_key_args(int argc, VALUE *argv, VALUE opt, struct foreach_arg *arg) open_key_args(int argc, VALUE *argv, VALUE opt, struct foreach_arg *arg)
{ {
VALUE path, v; VALUE path, v;
VALUE vmode = Qnil, vperm = Qnil;
path = *argv++; path = *argv++;
argc--; argc--;
@ -10176,29 +10167,18 @@ open_key_args(int argc, VALUE *argv, VALUE opt, struct foreach_arg *arg)
arg->argc = argc; arg->argc = argc;
arg->argv = argv; arg->argv = argv;
if (NIL_P(opt)) { if (NIL_P(opt)) {
arg->io = rb_io_open(path, INT2NUM(O_RDONLY), INT2FIX(0666), Qnil); vmode = INT2NUM(O_RDONLY);
return; vperm = INT2FIX(0666);
} }
v = rb_hash_aref(opt, sym_open_args); else if (!NIL_P(v = rb_hash_aref(opt, sym_open_args))) {
if (!NIL_P(v)) { int n;
VALUE args;
long n;
v = rb_to_array_type(v); v = rb_to_array_type(v);
n = RARRAY_LEN(v) + 1; n = RARRAY_LENINT(v);
#if SIZEOF_LONG > SIZEOF_INT rb_check_arity(n, 0, 3); /* rb_io_open */
if (n > INT_MAX) { rb_scan_args(n, RARRAY_CONST_PTR(v), "02:", &vmode, &vperm, &opt);
rb_raise(rb_eArgError, "too many arguments");
} }
#endif arg->io = rb_io_open(path, vmode, vperm, opt);
args = rb_ary_tmp_new(n);
rb_ary_push(args, path);
rb_ary_concat(args, v);
arg->io = rb_io_open_with_args((int)n, RARRAY_CONST_PTR(args));
rb_ary_clear(args); /* prevent from GC */
return;
}
arg->io = rb_io_open(path, Qnil, Qnil, opt);
} }
static VALUE static VALUE