* include/ruby/intern.h (rb_io_ungetbyte): added prototype.

* io.c (rb_io_gets): use rb_io_getline_1 for unget buffer.

* ruby.c (load_file): use rb_io_ungetbyte.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18832 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2008-08-25 08:36:46 +00:00
parent 10906176b4
commit ce60bbc851
4 changed files with 13 additions and 10 deletions

View File

@ -1,4 +1,10 @@
Mon Aug 25 17:35:23 2008 Nobuyoshi Nakada <nobu@ruby-lang.org> Mon Aug 25 17:36:26 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* include/ruby/intern.h (rb_io_ungetbyte): added prototype.
* io.c (rb_io_gets): use rb_io_getline_1 for unget buffer.
* ruby.c (load_file): use rb_io_ungetbyte.
* transcode.c (rb_econv_substr_append): fix for buffer overrun. * transcode.c (rb_econv_substr_append): fix for buffer overrun.

View File

@ -374,6 +374,7 @@ VALUE rb_io_write(VALUE, VALUE);
VALUE rb_io_gets(VALUE); VALUE rb_io_gets(VALUE);
VALUE rb_io_getbyte(VALUE); VALUE rb_io_getbyte(VALUE);
VALUE rb_io_ungetc(VALUE, VALUE); VALUE rb_io_ungetc(VALUE, VALUE);
VALUE rb_io_ungetbyte(VALUE, VALUE);
VALUE rb_io_close(VALUE); VALUE rb_io_close(VALUE);
VALUE rb_io_flush(VALUE); VALUE rb_io_flush(VALUE);
VALUE rb_io_eof(VALUE); VALUE rb_io_eof(VALUE);

6
io.c
View File

@ -2213,11 +2213,7 @@ rb_io_getline(int argc, VALUE *argv, VALUE io)
VALUE VALUE
rb_io_gets(VALUE io) rb_io_gets(VALUE io)
{ {
rb_io_t *fptr; return rb_io_getline_1(rb_default_rs, -1, io);
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
return rb_io_getline_fast(fptr, io_read_encoding(fptr));
} }
/* /*

8
ruby.c
View File

@ -1260,12 +1260,12 @@ load_file(VALUE parser, const char *fname, int script, struct cmdline_options *o
} }
/* push back shebang for pragma may exist in next line */ /* push back shebang for pragma may exist in next line */
rb_io_ungetc(f, rb_str_new2("!\n")); rb_io_ungetbyte(f, rb_str_new2("!\n"));
} }
else if (!NIL_P(c)) { else if (!NIL_P(c)) {
rb_io_ungetc(f, c); rb_io_ungetbyte(f, c);
} }
rb_io_ungetc(f, INT2FIX('#')); rb_io_ungetbyte(f, INT2FIX('#'));
if (no_src_enc && opt->src.enc.name) { if (no_src_enc && opt->src.enc.name) {
opt->src.enc.index = opt_enc_index(opt->src.enc.name); opt->src.enc.index = opt_enc_index(opt->src.enc.name);
src_encoding_index = opt->src.enc.index; src_encoding_index = opt->src.enc.index;
@ -1275,7 +1275,7 @@ load_file(VALUE parser, const char *fname, int script, struct cmdline_options *o
} }
} }
else if (!NIL_P(c)) { else if (!NIL_P(c)) {
rb_io_ungetc(f, c); rb_io_ungetbyte(f, c);
} }
require_libraries(opt); /* Why here? unnatural */ require_libraries(opt); /* Why here? unnatural */
} }