diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-07-14 07:18:58 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-07-14 07:18:58 +0000 |
commit | 9144491376799259d3430ad36c0c862b21c053a2 (patch) | |
tree | 94d7468da354e1b2f772d982b8d271289a947e28 | |
parent | ce175376b2a0460d746270831d35240595cac276 (diff) | |
download | ruby-9144491376799259d3430ad36c0c862b21c053a2.tar.gz |
matz
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@833 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | io.c | 72 | ||||
-rw-r--r-- | re.c | 4 |
3 files changed, 46 insertions, 39 deletions
@@ -1,5 +1,14 @@ Fri Jul 14 12:49:50 2000 Yukihiro Matsumoto <matz@netlab.co.jp> + * 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. @@ -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(); } @@ -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 |