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

ruby-changes:4334

From: ko1@a...
Date: Fri, 21 Mar 2008 21:32:51 +0900 (JST)
Subject: [ruby-changes:4334] nobu - Ruby:r15824 (trunk): * io.c (rb_f_gets, rb_f_readline, rb_f_readlines): delegates to ARGF

nobu	2008-03-21 21:32:33 +0900 (Fri, 21 Mar 2008)

  New Revision: 15824

  Modified files:
    trunk/ChangeLog
    trunk/io.c

  Log:
    * io.c (rb_f_gets, rb_f_readline, rb_f_readlines): delegates to ARGF
      as well as puts and putc.  [ruby-dev:34100]


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15824&r2=15823&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/io.c?r1=15824&r2=15823&diff_format=u

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 15823)
+++ ChangeLog	(revision 15824)
@@ -1,3 +1,8 @@
+Fri Mar 21 21:32:25 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* io.c (rb_f_gets, rb_f_readline, rb_f_readlines): delegates to ARGF
+	  as well as puts and putc.  [ruby-dev:34100]
+
 Fri Mar 21 21:26:52 2008  Nobuyoshi Nakada  <nobu@r...>
 
 	* lib/resolv.rb (Resolv::Hosts): should not use win32/resolv on cygwin.
Index: io.c
===================================================================
--- io.c	(revision 15823)
+++ io.c	(revision 15824)
@@ -5227,9 +5227,19 @@
  *  parameter is gradually losing favor in the Ruby community.
  */
 
+static VALUE argf_gets(int, VALUE *, VALUE);
 static VALUE
-rb_f_gets(int argc, VALUE *argv)
+rb_f_gets(int argc, VALUE *argv, VALUE recv)
 {
+    if (recv == argf) {
+	return argf_gets(argc, argv, argf);
+    }
+    return rb_funcall2(argf, rb_intern("gets"), argc, argv);
+}
+
+static VALUE
+argf_gets(int argc, VALUE *argv, VALUE argf)
+{
     VALUE line;
 
     line = argf_getline(argc, argv, argf);
@@ -5243,7 +5253,7 @@
     VALUE line;
 
     if (rb_rs != rb_default_rs) {
-	return rb_f_gets(0, 0);
+	return rb_f_gets(0, 0, argf);
     }
 
   retry:
@@ -5273,14 +5283,24 @@
  *  +readline+ raises +EOFError+ at end of file.
  */
 
+static VALUE argf_readline(int, VALUE *, VALUE);
 static VALUE
-rb_f_readline(int argc, VALUE *argv)
+rb_f_readline(int argc, VALUE *argv, VALUE recv)
 {
+    if (recv == argf) {
+	return argf_readline(argc, argv, argf);
+    }
+    return rb_funcall2(argf, rb_intern("readline"), argc, argv);
+}
+
+static VALUE
+argf_readline(int argc, VALUE *argv, VALUE argf)
+{
     VALUE line;
 
     if (!next_argv()) rb_eof_error();
     ARGF_FORWARD(argc, argv);
-    line = rb_f_gets(argc, argv);
+    line = argf_gets(argc, argv, argf);
     if (NIL_P(line)) {
 	rb_eof_error();
     }
@@ -5298,9 +5318,19 @@
  *  <code>Kernel.gets(<i>sep</i>)</code> until the end of file.
  */
 
+static VALUE argf_readlines(int, VALUE *, VALUE);
 static VALUE
-rb_f_readlines(int argc, VALUE *argv)
+rb_f_readlines(int argc, VALUE *argv, VALUE recv)
 {
+    if (recv == argf) {
+	return argf_readlines(argc, argv, argf);
+    }
+    return rb_funcall2(argf, rb_intern("readlines"), argc, argv);
+}
+
+static VALUE
+argf_readlines(int argc, VALUE *argv, VALUE argf)
+{
     VALUE line, ary;
 
     ary = rb_ary_new();
@@ -6902,10 +6932,10 @@
 
     rb_define_method(rb_cARGF, "read",  argf_read, -1);
     rb_define_method(rb_cARGF, "readpartial",  argf_readpartial, -1);
-    rb_define_method(rb_cARGF, "readlines", rb_f_readlines, -1);
-    rb_define_method(rb_cARGF, "to_a", rb_f_readlines, -1);
-    rb_define_method(rb_cARGF, "gets", rb_f_gets, -1);
-    rb_define_method(rb_cARGF, "readline", rb_f_readline, -1);
+    rb_define_method(rb_cARGF, "readlines", argf_readlines, -1);
+    rb_define_method(rb_cARGF, "to_a", argf_readlines, -1);
+    rb_define_method(rb_cARGF, "gets", argf_gets, -1);
+    rb_define_method(rb_cARGF, "readline", argf_readline, -1);
     rb_define_method(rb_cARGF, "getc", argf_getc, 0);
     rb_define_method(rb_cARGF, "getbyte", argf_getbyte, 0);
     rb_define_method(rb_cARGF, "readchar", argf_readchar, 0);

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

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