e$B1sF#$H?=$7$^$9!#e(B
ARGF.dup e$B$re(B rewind e$B$9$k$He(B lineno e$B$,$*$+$7$/$J$j$^$9!#e(B
$ cat foobarbaz.txt
foo
bar
baz
$ ./ruby -ve ’
a = ARGF.dup
p [a.gets, a.lineno]
p [a.gets, a.lineno]
a.rewind
p [a.gets, a.lineno]
p [a.gets, a.lineno]
’ foobarbaz.txt
ruby 1.9.0 (2008-04-17 revision 16058) [i686-linux]
[“foo\n”, 1]
[“bar\n”, 2]
[“foo\n”, 1]
[“bar\n”, 2]
rb_io_t e$B$Ke(B argf e$B$r<($9%U%#!<%k%I$rDI2C$7$FBP1~$7$F$_$^$7$?!#e(B
Index: include/ruby/io.h
— include/ruby/io.h (revision 16062)
+++ include/ruby/io.h (working copy)
@@ -47,6 +47,7 @@
VALUE tied_io_for_writing;
rb_encoding *enc;
rb_encoding *enc2;
- VALUE argf;
} rb_io_t;
#define HAVE_RB_IO_T 1
@@ -92,6 +93,7 @@
fp->tied_io_for_writing = 0;
fp->enc = 0;
fp->enc2 = 0;\
- fp->argf = 0;
} while (0)
FILE *rb_io_stdio_file(rb_io_t *fptr);
Index: io.c
— io.c (revision 16062)
+++ io.c (working copy)
@@ -994,10 +994,12 @@
rb_io_rewind(VALUE io)
{
rb_io_t *fptr;
-
VALUE argf;
GetOpenFile(io, fptr);
-
argf = fptr->argf;
if (io_seek(fptr, 0L, 0) < 0) rb_sys_fail(fptr->path);
- if (io == ARGF.current_file) {
-
if (argf && io == ARGF.current_file) {
ARGF.gets_lineno -= fptr->lineno;
}
fptr->lineno = 0;
@@ -5209,6 +5211,8 @@
if (stdout_binmode) rb_io_binmode(rb_stdout);
}
current_file = prep_io(fr, FMODE_READABLE, rb_cFile, fn); -
GetOpenFile(current_file, fptr);
-
fptr->argf = argf;
}
if (argf_binmode) rb_io_binmode(current_file);
if (argf_enc) {
Index: gc.c
===================================================================
— gc.c (revision 16062)
+++ gc.c (working copy)
@@ -1113,8 +1113,10 @@
break;case T_FILE:
-
if (obj->as.file.fptr)
-
if (obj->as.file.fptr) { gc_mark(obj->as.file.fptr->tied_io_for_writing, lev);
-
gc_mark(obj->as.file.fptr->argf, lev);
-
}
break;case T_REGEXP: