From 2c87fffec417971fdc7c3fa457dd17ac2be451c6 Mon Sep 17 00:00:00 2001 From: matz Date: Tue, 30 Dec 2003 19:29:56 +0000 Subject: [PATCH] * io.c (rb_f_readline): should raise EOFError at the end of files. [ruby-dev:22458] * io.c (argf_read): should concatenate input files when length argument is nil. [ruby-dev:22450] * io.c (argf_read): should update supplied string buffer (2nd argument) even when IO#read is called multiple times. * io.c: should initialize lineno by zero. [ruby-dev:22460] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5354 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 13 +++++++++++++ io.c | 32 ++++++++++++++++---------------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7403817f50..7ec842eec7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,19 @@ Wed Dec 31 01:33:05 2003 Dave Thomas * array.c, error.c, eval.c, io.c, prec.c, range.c, re.c, string.c, time.c: Add RDoc for Kernel functions, and tidy. +Tue Dec 30 19:39:14 2003 Yukihiro Matsumoto + + * io.c (rb_f_readline): should raise EOFError at the end of + files. [ruby-dev:22458] + + * io.c (argf_read): should concatenate input files when length + argument is nil. [ruby-dev:22450] + + * io.c (argf_read): should update supplied string buffer (2nd + argument) even when IO#read is called multiple times. + + * io.c: should initialize lineno by zero. [ruby-dev:22460] + Tue Dec 30 12:30:30 2003 Dave Thomas * lib/rdoc/code_objects.rb (RDoc::Context::find_symbol): If a diff --git a/io.c b/io.c index 3ccb375876..40d8568bbf 100644 --- a/io.c +++ b/io.c @@ -59,7 +59,7 @@ #include /* EMX has sys/param.h, but.. */ -#if defined(HAVE_SYS_PARAM_H) && !(defined(__EMX__) || defined(__HIUX_MPP__)) +#if defined(HAVE_SYS_PAAM_H) && !(defined(__EMX__) || defined(__HIUX_MPP__)) # include #endif @@ -110,7 +110,7 @@ struct timeval rb_time_interval _((VALUE)); static VALUE filename, current_file; static int gets_lineno; static int init_p = 0, next_p = 0; -static VALUE lineno; +static VALUE lineno = INT2FIX(0); #if defined(__VMS) #define fopen(file_spec, mode) fopen(file_spec, mode, "rfm=stmlf") @@ -4105,7 +4105,8 @@ rb_f_readline(argc, argv) { VALUE line; - NEXT_ARGF_FORWARD(); + if (!next_argv()) rb_eof_error(); + ARGF_FORWARD(); line = rb_f_gets(argc, argv); if (NIL_P(line)) { rb_eof_error(); @@ -4913,23 +4914,22 @@ argf_read(argc, argv) int argc; VALUE *argv; { - VALUE tmp, str; + VALUE tmp, str, length; long len = 0; - if (argc == 1 && !NIL_P(argv[0])) + rb_scan_args(argc, argv, "02", &length, &str); + if (!NIL_P(length)) { len = NUM2LONG(argv[0]); - str = Qnil; + } + if (!NIL_P(str)) { + StringValue(str); + rb_str_resize(str,0); + argv[1] = Qnil; + } retry: if (!next_argv()) { - if (NIL_P(str)) { - VALUE length; - - rb_scan_args(argc, argv, "02", &length, &str); - if (NIL_P(str)) return rb_str_new(0,0); - StringValue(str); - rb_str_resize(str,0); - } + if (NIL_P(str)) return rb_str_new(0,0); return str; } if (TYPE(current_file) != T_FILE) { @@ -4940,14 +4940,14 @@ argf_read(argc, argv) } if (NIL_P(str)) str = tmp; else rb_str_append(str, tmp); - if (NIL_P(tmp) || argc == 0) { + if (NIL_P(tmp) || NIL_P(argv[0])) { if (next_p != -1) { argf_close(current_file); next_p = 1; goto retry; } } - else if (argc == 1) { + else if (argc >= 1) { if (RSTRING(str)->len < len) { len -= RSTRING(str)->len; argv[0] = INT2NUM(len);