* io.c (argf_rewind): need to rewind $. and ARGF.lineno.

[ruby-core:24046]

* io.c (struct argf): refactoring on $. and ARGF.lineno behavior.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23862 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2009-06-26 18:10:12 +00:00
Родитель c86115e996
Коммит 917286208c
2 изменённых файлов: 25 добавлений и 19 удалений

Просмотреть файл

@ -1,3 +1,10 @@
Sat Jun 27 03:09:04 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (argf_rewind): need to rewind $. and ARGF.lineno.
[ruby-core:24046]
* io.c (struct argf): refactoring on $. and ARGF.lineno behavior.
Fri Jun 26 21:48:30 2009 Tanaka Akira <akr@fsij.org>
* ext/pty/pty.c (pty_getpty): check dup failure.

37
io.c
Просмотреть файл

@ -134,9 +134,9 @@ struct timeval rb_time_interval(VALUE);
struct argf {
VALUE filename, current_file;
int gets_lineno;
int last_lineno; /* $. */
int lineno;
int init_p, next_p;
VALUE lineno;
VALUE argv;
char *inplace;
int binmode;
@ -1142,7 +1142,7 @@ rb_io_rewind(VALUE io)
GetOpenFile(io, fptr);
if (io_seek(fptr, 0L, 0) < 0) rb_sys_fail_path(fptr->pathv);
if (io == ARGF.current_file) {
ARGF.gets_lineno -= fptr->lineno;
ARGF.lineno -= fptr->lineno;
}
fptr->lineno = 0;
if (fptr->readconv) {
@ -2273,7 +2273,8 @@ rb_io_getline_fast(rb_io_t *fptr, rb_encoding *enc)
str = io_enc_str(str, fptr);
ENC_CODERANGE_SET(str, cr);
fptr->lineno++;
ARGF.lineno = INT2FIX(fptr->lineno);
ARGF.last_lineno = fptr->lineno;
return str;
}
@ -2410,7 +2411,7 @@ rb_io_getline_1(VALUE rs, long limit, VALUE io)
if (!NIL_P(str)) {
if (!nolimit) {
fptr->lineno++;
ARGF.lineno = INT2FIX(fptr->lineno);
ARGF.last_lineno = fptr->lineno;
}
}
@ -6334,7 +6335,6 @@ argf_mark(void *ptr)
struct argf *p = ptr;
rb_gc_mark(p->filename);
rb_gc_mark(p->current_file);
rb_gc_mark(p->lineno);
rb_gc_mark(p->argv);
rb_gc_mark(p->encs.ecopts);
}
@ -6351,7 +6351,7 @@ argf_init(struct argf *p, VALUE v)
{
p->filename = Qnil;
p->current_file = Qnil;
p->lineno = INT2FIX(0);
p->lineno = 0;
p->argv = v;
}
@ -6392,15 +6392,15 @@ argf_initialize_copy(VALUE argf, VALUE orig)
static VALUE
argf_set_lineno(VALUE argf, VALUE val)
{
ARGF.gets_lineno = NUM2INT(val);
ARGF.lineno = INT2FIX(ARGF.gets_lineno);
ARGF.lineno = NUM2INT(val);
ARGF.last_lineno = ARGF.lineno;
return Qnil;
}
static VALUE
argf_lineno(VALUE argf)
{
return ARGF.lineno;
return INT2FIX(ARGF.lineno);
}
static VALUE
@ -6448,7 +6448,6 @@ argf_next_argv(VALUE argf)
ARGF.next_p = -1;
}
ARGF.init_p = 1;
ARGF.gets_lineno = 0;
}
if (ARGF.next_p == 1) {
@ -6582,8 +6581,8 @@ argf_getline(int argc, VALUE *argv, VALUE argf)
}
}
if (!NIL_P(line)) {
ARGF.gets_lineno++;
ARGF.lineno = INT2FIX(ARGF.gets_lineno);
ARGF.lineno++;
ARGF.last_lineno = ARGF.lineno;
}
return line;
}
@ -6592,7 +6591,7 @@ static VALUE
argf_lineno_getter(ID id, VALUE *var)
{
VALUE argf = *var;
return ARGF.lineno;
return INT2FIX(ARGF.last_lineno);
}
static void
@ -6600,8 +6599,7 @@ argf_lineno_setter(VALUE val, ID id, VALUE *var)
{
VALUE argf = *var;
int n = NUM2INT(val);
ARGF.gets_lineno = n;
ARGF.lineno = INT2FIX(n);
ARGF.last_lineno = ARGF.lineno = n;
}
static VALUE argf_gets(int, VALUE *, VALUE);
@ -6655,6 +6653,7 @@ argf_gets(int argc, VALUE *argv, VALUE argf)
line = argf_getline(argc, argv, argf);
rb_lastline_set(line);
return line;
}
@ -6677,8 +6676,8 @@ rb_gets(void)
}
rb_lastline_set(line);
if (!NIL_P(line)) {
ARGF.gets_lineno++;
ARGF.lineno = INT2FIX(ARGF.gets_lineno);
ARGF.lineno++;
ARGF.last_lineno = ARGF.lineno;
}
return line;
@ -8633,7 +8632,7 @@ argf_close_m(VALUE argf)
if (ARGF.next_p != -1) {
ARGF.next_p = 1;
}
ARGF.gets_lineno = 0;
ARGF.lineno = 0;
return argf;
}