diff --git a/ChangeLog b/ChangeLog index 23539266be..8c3b973dfc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ Fri Jul 14 12:49:50 2000 Yukihiro Matsumoto + * io.c (argf_eof): need to check stdin, when next_p == -1. + + * io.c (read_all): use io_fread() instead of fread(3). + + * io.c (io_reopen): should clearerr FILE if fd < 3. + + * re.c (rb_reg_match_m): the result is exported, so it should be + declared as busy. + * eval.c (rb_eval): should preserve errinfo even if return, break, etc. is called in rescue clause. diff --git a/io.c b/io.c index d5701dcb8a..f3fd315323 100644 --- a/io.c +++ b/io.c @@ -426,6 +426,36 @@ rb_io_to_io(io) /* reading functions */ +static size_t +io_fread(ptr, len, f) + char *ptr; + size_t len; + FILE *f; +{ + size_t n = len; + int c; + + while (n--) { + if (!READ_DATA_PENDING(f)) { + rb_thread_wait_fd(fileno(f)); + } + TRAP_BEG; + c = getc(f); + TRAP_END; + if (c == EOF) { + if (ferror(f)) { + if (errno == EINTR) continue; + rb_sys_fail(0); + } + *ptr = '\0'; + break; + } + *ptr++ = c; + } + + return len - n - 1; +} + #ifndef S_ISREG # define S_ISREG(m) ((m & S_IFMT) == S_IFREG) #endif @@ -464,12 +494,10 @@ read_all(port) } } } - str = rb_str_new(0, siz); + str = rb_tainted_str_new(0, siz); + READ_CHECK(fptr->f); for (;;) { - READ_CHECK(fptr->f); - TRAP_BEG; - n = fread(RSTRING(str)->ptr+bytes, 1, siz-bytes, fptr->f); - TRAP_END; + n = io_fread(RSTRING(str)->ptr+bytes, siz-bytes, fptr->f); if (n == 0 && bytes == 0) { if (feof(fptr->f)) return Qnil; rb_sys_fail(fptr->path); @@ -481,41 +509,10 @@ read_all(port) } if (bytes == 0) return rb_str_new(0,0); if (bytes != siz) rb_str_resize(str, bytes); - OBJ_TAINT(str); return str; } -static size_t -io_fread(ptr, len, f) - char *ptr; - size_t len; - FILE *f; -{ - size_t n = len; - int c; - - while (n--) { - if (!READ_DATA_PENDING(f)) { - rb_thread_wait_fd(fileno(f)); - } - TRAP_BEG; - c = getc(f); - TRAP_END; - if (c == EOF) { - if (ferror(f)) { - if (errno == EINTR) continue; - rb_sys_fail(0); - } - *ptr = '\0'; - break; - } - *ptr++ = c; - } - - return len - n - 1; -} - static VALUE io_read(argc, argv, io) int argc; @@ -1795,6 +1792,7 @@ io_reopen(io, nfile) mode = rb_io_mode_string(fptr); fd = fileno(fptr->f); if (fd < 3) { + clearerr(fptr->f); /* need to keep stdio */ if (dup2(fileno(orig->f), fd) < 0) rb_sys_fail(orig->path); @@ -3175,8 +3173,6 @@ argf_eof() { if (init_p == 0 && !next_argv()) return Qtrue; - if (next_p == -1) - return Qtrue; if (TYPE(current_file) != T_FILE) { return argf_forward(); } diff --git a/re.c b/re.c index d4e2bade70..a955852d23 100644 --- a/re.c +++ b/re.c @@ -968,7 +968,9 @@ rb_reg_match_m(re, str) VALUE result = rb_reg_match(re, str); if (NIL_P(result)) return Qnil; - return rb_backref_get(); + result = rb_backref_get(); + rb_match_busy(result); + return result; } static VALUE