* io.c (argf_close): always close via method.
* io.c (Init_IO): remove obsolete Kernel#getc. * io.c (argf_each_line): should use #each_line, not #each. * io.c (argf_each_line): simplified. * io.c (argf_getline): should handle non T_FILE object in ARGV. * io.c (argf_each_byte): each_byte should yield bytes not one-character strings. [ruby-dev:31374] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12931 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
14c3aa52ae
commit
7e8d337aa4
17
ChangeLog
17
ChangeLog
@ -36,6 +36,12 @@ Mon Aug 13 13:21:58 2007 Tanaka Akira <akr@fsij.org>
|
|||||||
* lib/open-uri.rb: make ftp passive mode to avoid NAT problem.
|
* lib/open-uri.rb: make ftp passive mode to avoid NAT problem.
|
||||||
[ruby-dev:31377]
|
[ruby-dev:31377]
|
||||||
|
|
||||||
|
Mon Aug 13 08:19:43 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* io.c (argf_close): always close via method.
|
||||||
|
|
||||||
|
* io.c (Init_IO): remove obsolete Kernel#getc.
|
||||||
|
|
||||||
Mon Aug 13 05:03:53 2007 Koichi Sasada <ko1@atdot.net>
|
Mon Aug 13 05:03:53 2007 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
* thread.c (rb_thread_raise): check if target thread is
|
* thread.c (rb_thread_raise): check if target thread is
|
||||||
@ -73,6 +79,17 @@ Mon Aug 13 03:57:32 2007 Koichi Sasada <ko1@atdot.net>
|
|||||||
|
|
||||||
* template/yasmdata.rb.tmpl: fix type and name.
|
* template/yasmdata.rb.tmpl: fix type and name.
|
||||||
|
|
||||||
|
Sat Aug 11 23:27:37 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* io.c (argf_each_line): should use #each_line, not #each.
|
||||||
|
|
||||||
|
* io.c (argf_each_line): simplified.
|
||||||
|
|
||||||
|
* io.c (argf_getline): should handle non T_FILE object in ARGV.
|
||||||
|
|
||||||
|
* io.c (argf_each_byte): each_byte should yield bytes not
|
||||||
|
one-character strings. [ruby-dev:31374]
|
||||||
|
|
||||||
Sat Aug 11 07:24:55 2007 Tadayoshi Funaba <tadf@dotrb.org>
|
Sat Aug 11 07:24:55 2007 Tadayoshi Funaba <tadf@dotrb.org>
|
||||||
|
|
||||||
* lib/date/format.rb: reverted some wrongly erased "o" options
|
* lib/date/format.rb: reverted some wrongly erased "o" options
|
||||||
|
58
io.c
58
io.c
@ -4310,7 +4310,7 @@ argf_forward(int argc, VALUE *argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define ARGF_FORWARD(argc, argv) do {\
|
#define ARGF_FORWARD(argc, argv) do {\
|
||||||
if (TYPE(current_file) != T_FILE)\
|
if (current_file == rb_stdout && TYPE(current_file) != T_FILE)\
|
||||||
return argf_forward(argc, argv);\
|
return argf_forward(argc, argv);\
|
||||||
} while (0)
|
} while (0)
|
||||||
#define NEXT_ARGF_FORWARD(argc, argv) do {\
|
#define NEXT_ARGF_FORWARD(argc, argv) do {\
|
||||||
@ -4321,9 +4321,6 @@ argf_forward(int argc, VALUE *argv)
|
|||||||
static void
|
static void
|
||||||
argf_close(VALUE file)
|
argf_close(VALUE file)
|
||||||
{
|
{
|
||||||
if (TYPE(file) == T_FILE)
|
|
||||||
rb_io_close(file);
|
|
||||||
else
|
|
||||||
rb_funcall3(file, rb_intern("close"), 0, 0);
|
rb_funcall3(file, rb_intern("close"), 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4452,6 +4449,10 @@ argf_getline(int argc, VALUE *argv)
|
|||||||
|
|
||||||
retry:
|
retry:
|
||||||
if (!next_argv()) return Qnil;
|
if (!next_argv()) return Qnil;
|
||||||
|
if (current_file == rb_stdout && TYPE(current_file) != T_FILE) {
|
||||||
|
line = rb_funcall3(current_file, rb_intern("gets"), argc, argv);
|
||||||
|
}
|
||||||
|
else {
|
||||||
if (argc == 0 && rb_rs == rb_default_rs) {
|
if (argc == 0 && rb_rs == rb_default_rs) {
|
||||||
line = rb_io_gets(current_file);
|
line = rb_io_gets(current_file);
|
||||||
}
|
}
|
||||||
@ -4463,6 +4464,7 @@ argf_getline(int argc, VALUE *argv)
|
|||||||
next_p = 1;
|
next_p = 1;
|
||||||
goto retry;
|
goto retry;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!NIL_P(line)) {
|
if (!NIL_P(line)) {
|
||||||
gets_lineno++;
|
gets_lineno++;
|
||||||
lineno = INT2FIX(gets_lineno);
|
lineno = INT2FIX(gets_lineno);
|
||||||
@ -4508,13 +4510,7 @@ rb_f_gets(int argc, VALUE *argv)
|
|||||||
{
|
{
|
||||||
VALUE line;
|
VALUE line;
|
||||||
|
|
||||||
if (!next_argv()) return Qnil;
|
|
||||||
if (TYPE(current_file) != T_FILE) {
|
|
||||||
line = rb_funcall3(current_file, rb_intern("gets"), argc, argv);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
line = argf_getline(argc, argv);
|
line = argf_getline(argc, argv);
|
||||||
}
|
|
||||||
rb_lastline_set(line);
|
rb_lastline_set(line);
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
@ -4532,7 +4528,7 @@ rb_gets(void)
|
|||||||
if (!next_argv()) return Qnil;
|
if (!next_argv()) return Qnil;
|
||||||
line = rb_io_gets(current_file);
|
line = rb_io_gets(current_file);
|
||||||
if (NIL_P(line) && next_p != -1) {
|
if (NIL_P(line) && next_p != -1) {
|
||||||
argf_close(current_file);
|
rb_io_close(current_file);
|
||||||
next_p = 1;
|
next_p = 1;
|
||||||
goto retry;
|
goto retry;
|
||||||
}
|
}
|
||||||
@ -4570,19 +4566,6 @@ rb_f_readline(int argc, VALUE *argv)
|
|||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* obsolete
|
|
||||||
*/
|
|
||||||
static VALUE
|
|
||||||
rb_f_getc(void)
|
|
||||||
{
|
|
||||||
rb_warn("getc is obsolete; use STDIN.getc instead");
|
|
||||||
if (TYPE(rb_stdin) != T_FILE) {
|
|
||||||
return rb_funcall3(rb_stdin, rb_intern("getc"), 0, 0);
|
|
||||||
}
|
|
||||||
return rb_io_getc(rb_stdin);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* readlines(sep=$/) => array
|
* readlines(sep=$/) => array
|
||||||
@ -4598,7 +4581,6 @@ rb_f_readlines(int argc, VALUE *argv)
|
|||||||
{
|
{
|
||||||
VALUE line, ary;
|
VALUE line, ary;
|
||||||
|
|
||||||
NEXT_ARGF_FORWARD(argc, argv);
|
|
||||||
ary = rb_ary_new();
|
ary = rb_ary_new();
|
||||||
while (!NIL_P(line = argf_getline(argc, argv))) {
|
while (!NIL_P(line = argf_getline(argc, argv))) {
|
||||||
rb_ary_push(ary, line);
|
rb_ary_push(ary, line);
|
||||||
@ -5379,7 +5361,7 @@ argf_read(int argc, VALUE *argv)
|
|||||||
if (!next_argv()) {
|
if (!next_argv()) {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
if (TYPE(current_file) != T_FILE) {
|
if (current_file == rb_stdout && TYPE(current_file) != T_FILE) {
|
||||||
tmp = argf_forward(argc, argv);
|
tmp = argf_forward(argc, argv);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -5425,7 +5407,7 @@ argf_readpartial(int argc, VALUE *argv)
|
|||||||
rb_str_resize(str, 0);
|
rb_str_resize(str, 0);
|
||||||
rb_eof_error();
|
rb_eof_error();
|
||||||
}
|
}
|
||||||
if (TYPE(current_file) != T_FILE) {
|
if (current_file == rb_stdout && TYPE(current_file) != T_FILE) {
|
||||||
tmp = rb_rescue2(argf_forward, (VALUE)argv,
|
tmp = rb_rescue2(argf_forward, (VALUE)argv,
|
||||||
argf_readpartial_rescue, (VALUE)Qnil,
|
argf_readpartial_rescue, (VALUE)Qnil,
|
||||||
rb_eEOFError, (VALUE)0);
|
rb_eEOFError, (VALUE)0);
|
||||||
@ -5455,7 +5437,7 @@ argf_getc(void)
|
|||||||
|
|
||||||
retry:
|
retry:
|
||||||
if (!next_argv()) return Qnil;
|
if (!next_argv()) return Qnil;
|
||||||
if (TYPE(current_file) != T_FILE) {
|
if (current_file == rb_stdout && TYPE(current_file) != T_FILE) {
|
||||||
ch = rb_funcall3(current_file, rb_intern("getc"), 0, 0);
|
ch = rb_funcall3(current_file, rb_intern("getc"), 0, 0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -5489,18 +5471,12 @@ argf_each_line(int argc, VALUE *argv, VALUE self)
|
|||||||
VALUE str;
|
VALUE str;
|
||||||
|
|
||||||
RETURN_ENUMERATOR(self, argc, argv);
|
RETURN_ENUMERATOR(self, argc, argv);
|
||||||
if (!next_argv()) return Qnil;
|
|
||||||
if (TYPE(current_file) != T_FILE) {
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (!next_argv()) return argf;
|
if (!next_argv()) return Qnil;
|
||||||
rb_block_call(current_file, rb_intern("each"), 0, 0, rb_yield, 0);
|
rb_block_call(current_file, rb_intern("each_line"), 0, 0, rb_yield, 0);
|
||||||
next_p = 1;
|
next_p = 1;
|
||||||
}
|
}
|
||||||
}
|
return self;
|
||||||
while (!NIL_P(str = argf_getline(argc, argv))) {
|
|
||||||
rb_yield(str);
|
|
||||||
}
|
|
||||||
return argf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
@ -5509,10 +5485,11 @@ argf_each_byte(VALUE self)
|
|||||||
VALUE byte;
|
VALUE byte;
|
||||||
|
|
||||||
RETURN_ENUMERATOR(self, 0, 0);
|
RETURN_ENUMERATOR(self, 0, 0);
|
||||||
while (!NIL_P(byte = argf_getc())) {
|
for (;;) {
|
||||||
rb_yield(byte);
|
if (!next_argv()) return Qnil;
|
||||||
|
rb_block_call(current_file, rb_intern("each_byte"), 0, 0, rb_yield, 0);
|
||||||
|
next_p = 1;
|
||||||
}
|
}
|
||||||
return argf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
@ -5705,7 +5682,6 @@ Init_IO(void)
|
|||||||
rb_define_global_function("puts", rb_f_puts, -1);
|
rb_define_global_function("puts", rb_f_puts, -1);
|
||||||
rb_define_global_function("gets", rb_f_gets, -1);
|
rb_define_global_function("gets", rb_f_gets, -1);
|
||||||
rb_define_global_function("readline", rb_f_readline, -1);
|
rb_define_global_function("readline", rb_f_readline, -1);
|
||||||
rb_define_global_function("getc", rb_f_getc, 0);
|
|
||||||
rb_define_global_function("select", rb_f_select, -1);
|
rb_define_global_function("select", rb_f_select, -1);
|
||||||
|
|
||||||
rb_define_global_function("readlines", rb_f_readlines, -1);
|
rb_define_global_function("readlines", rb_f_readlines, -1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user