mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
matz
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@833 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ce175376b2
commit
9144491376
3 changed files with 46 additions and 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.
|
||||
|
||||
|
|
72
io.c
72
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();
|
||||
}
|
||||
|
|
4
re.c
4
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
|
||||
|
|
Loading…
Reference in a new issue