[前][次][番号順一覧][スレッド一覧]

ruby-changes:49196

From: nobu <ko1@a...>
Date: Mon, 18 Dec 2017 12:38:26 +0900 (JST)
Subject: [ruby-changes:49196] nobu:r61314 (trunk): io.c: open_key_args by rb_io_open

nobu	2017-12-18 12:38:20 +0900 (Mon, 18 Dec 2017)

  New Revision: 61314

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61314

  Log:
    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@r...>

  Modified files:
    trunk/io.c
Index: io.c
===================================================================
--- io.c	(revision 61313)
+++ io.c	(revision 61314)
@@ -7098,16 +7098,6 @@ rb_io_open_generic(VALUE filename, int o https://github.com/ruby/ruby/blob/trunk/io.c#L7098
 }
 
 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
 io_reopen(VALUE io, VALUE nfile)
 {
     rb_io_t *fptr, *orig;
@@ -10168,6 +10158,7 @@ static void https://github.com/ruby/ruby/blob/trunk/io.c#L10158
 open_key_args(int argc, VALUE *argv, VALUE opt, struct foreach_arg *arg)
 {
     VALUE path, v;
+    VALUE vmode = Qnil, vperm = Qnil;
 
     path = *argv++;
     argc--;
@@ -10176,29 +10167,18 @@ open_key_args(int argc, VALUE *argv, VAL https://github.com/ruby/ruby/blob/trunk/io.c#L10167
     arg->argc = argc;
     arg->argv = argv;
     if (NIL_P(opt)) {
-	arg->io = rb_io_open(path, INT2NUM(O_RDONLY), INT2FIX(0666), Qnil);
-	return;
+	vmode = INT2NUM(O_RDONLY);
+	vperm = INT2FIX(0666);
     }
-    v = rb_hash_aref(opt, sym_open_args);
-    if (!NIL_P(v)) {
-	VALUE args;
-	long n;
+    else if (!NIL_P(v = rb_hash_aref(opt, sym_open_args))) {
+	int n;
 
 	v = rb_to_array_type(v);
-	n = RARRAY_LEN(v) + 1;
-#if SIZEOF_LONG > SIZEOF_INT
-	if (n > INT_MAX) {
-	    rb_raise(rb_eArgError, "too many arguments");
-	}
-#endif
-	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;
+	n = RARRAY_LENINT(v);
+	rb_check_arity(n, 0, 3); /* rb_io_open */
+	rb_scan_args(n, RARRAY_CONST_PTR(v), "02:", &vmode, &vperm, &opt);
     }
-    arg->io = rb_io_open(path, Qnil, Qnil, opt);
+    arg->io = rb_io_open(path, vmode, vperm, opt);
 }
 
 static VALUE

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]