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

ruby-changes:54125

From: akr <ko1@a...>
Date: Wed, 12 Dec 2018 14:07:56 +0900 (JST)
Subject: [ruby-changes:54125] akr:r66346 (trunk): Use File class methods to avoid pipe execution

akr	2018-12-12 14:07:49 +0900 (Wed, 12 Dec 2018)

  New Revision: 66346

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

  Log:
    Use File class methods to avoid pipe execution
    
    
    Following methods use corresponding File class methods
    instead of IO class methods.
    
    - Pathname#each_line
    - Pathname#read
    - Pathname#binread
    - Pathname#write
    - Pathname#binwrite
    - Pathname#readlines
    
    Reported by ooooooo_q.

  Modified files:
    trunk/ext/pathname/pathname.c
Index: ext/pathname/pathname.c
===================================================================
--- ext/pathname/pathname.c	(revision 66345)
+++ ext/pathname/pathname.c	(revision 66346)
@@ -368,10 +368,10 @@ path_each_line(int argc, VALUE *argv, VA https://github.com/ruby/ruby/blob/trunk/ext/pathname/pathname.c#L368
     args[0] = get_strpath(self);
     n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
     if (rb_block_given_p()) {
-        return rb_block_call(rb_cIO, id_foreach, 1+n, args, 0, 0);
+        return rb_block_call(rb_cFile, id_foreach, 1+n, args, 0, 0);
     }
     else {
-        return rb_funcallv(rb_cIO, id_foreach, 1+n, args);
+        return rb_funcallv(rb_cFile, id_foreach, 1+n, args);
     }
 }
 
@@ -382,7 +382,7 @@ path_each_line(int argc, VALUE *argv, VA https://github.com/ruby/ruby/blob/trunk/ext/pathname/pathname.c#L382
  *
  * Returns all data from the file, or the first +N+ bytes if specified.
  *
- * See IO.read.
+ * See File.read.
  *
  */
 static VALUE
@@ -393,7 +393,7 @@ path_read(int argc, VALUE *argv, VALUE s https://github.com/ruby/ruby/blob/trunk/ext/pathname/pathname.c#L393
 
     args[0] = get_strpath(self);
     n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
-    return rb_funcallv(rb_cIO, id_read, 1+n, args);
+    return rb_funcallv(rb_cFile, id_read, 1+n, args);
 }
 
 /*
@@ -402,7 +402,7 @@ path_read(int argc, VALUE *argv, VALUE s https://github.com/ruby/ruby/blob/trunk/ext/pathname/pathname.c#L402
  *
  * Returns all the bytes from the file, or the first +N+ if specified.
  *
- * See IO.binread.
+ * See File.binread.
  *
  */
 static VALUE
@@ -413,7 +413,7 @@ path_binread(int argc, VALUE *argv, VALU https://github.com/ruby/ruby/blob/trunk/ext/pathname/pathname.c#L413
 
     args[0] = get_strpath(self);
     n = rb_scan_args(argc, argv, "02", &args[1], &args[2]);
-    return rb_funcallv(rb_cIO, id_binread, 1+n, args);
+    return rb_funcallv(rb_cFile, id_binread, 1+n, args);
 }
 
 /*
@@ -423,7 +423,7 @@ path_binread(int argc, VALUE *argv, VALU https://github.com/ruby/ruby/blob/trunk/ext/pathname/pathname.c#L423
  *
  * Writes +contents+ to the file.
  *
- * See IO.write.
+ * See File.write.
  *
  */
 static VALUE
@@ -434,7 +434,7 @@ path_write(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/ext/pathname/pathname.c#L434
 
     args[0] = get_strpath(self);
     n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
-    return rb_funcallv(rb_cIO, id_write, 1+n, args);
+    return rb_funcallv(rb_cFile, id_write, 1+n, args);
 }
 
 /*
@@ -444,7 +444,7 @@ path_write(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/ext/pathname/pathname.c#L444
  *
  * Writes +contents+ to the file, opening it in binary mode.
  *
- * See IO.binwrite.
+ * See File.binwrite.
  *
  */
 static VALUE
@@ -455,7 +455,7 @@ path_binwrite(int argc, VALUE *argv, VAL https://github.com/ruby/ruby/blob/trunk/ext/pathname/pathname.c#L455
 
     args[0] = get_strpath(self);
     n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
-    return rb_funcallv(rb_cIO, id_binwrite, 1+n, args);
+    return rb_funcallv(rb_cFile, id_binwrite, 1+n, args);
 }
 
 /*
@@ -466,7 +466,7 @@ path_binwrite(int argc, VALUE *argv, VAL https://github.com/ruby/ruby/blob/trunk/ext/pathname/pathname.c#L466
  *
  * Returns all the lines from the file.
  *
- * See IO.readlines.
+ * See File.readlines.
  *
  */
 static VALUE
@@ -477,7 +477,7 @@ path_readlines(int argc, VALUE *argv, VA https://github.com/ruby/ruby/blob/trunk/ext/pathname/pathname.c#L477
 
     args[0] = get_strpath(self);
     n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
-    return rb_funcallv(rb_cIO, id_readlines, 1+n, args);
+    return rb_funcallv(rb_cFile, id_readlines, 1+n, args);
 }
 
 /*

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

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