* io.c (read_all): do not return nil at the end of file.

[ruby-dev:22334]

* io.c (argf_read): do not depend on nil at eof behavior of
  IO#read().

* eval.c (rb_thread_join): dup exception before re-raising it.

* io.c (rb_io_eof): call clearerr() to prevent side effect.  this
  patch is supplied by Masahiro Sakai <sakai@tom.sfc.keio.ac.jp>.
  [ruby-dev:22234]

* pack.c (OFF16): get offset for big endian machines.

* pack.c (pack_pack): use OFF16 instead of OFF16B.
  [ruby-dev:22344]

* pack.c (pack_unpack): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5266 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2003-12-23 19:53:45 +00:00
parent a3ecd5c83d
commit 0a4fc3d71b
5 changed files with 69 additions and 50 deletions

View File

@ -1,3 +1,32 @@
Wed Dec 24 00:56:54 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (read_all): do not return nil at the end of file.
[ruby-dev:22334]
* io.c (argf_read): do not depend on nil at eof behavior of
IO#read().
* eval.c (rb_thread_join): dup exception before re-raising it.
* io.c (rb_io_eof): call clearerr() to prevent side effect. this
patch is supplied by Masahiro Sakai <sakai@tom.sfc.keio.ac.jp>.
[ruby-dev:22234]
* pack.c (OFF16): get offset for big endian machines.
* pack.c (pack_pack): use OFF16 instead of OFF16B.
[ruby-dev:22344]
* pack.c (pack_unpack): ditto.
Tue Dec 23 22:47:14 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (rb_io_check_readable): set FMODE_RBUF always, even if
NEED_IO_SEEK_BETWEEN_RW is not defined. [ruby-dev:22340]
* io.c (rb_io_check_writable): clear FMODE_RBUF before writing
something.
Tue Dec 23 22:25:00 2003 Gavin Sinclair <gsinclair@soyabean.com.au>
* lib/optparse.rb: incomplete RDoc documentation added in place of
@ -22,9 +51,6 @@ Tue Dec 23 18:09:40 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* pack.c (pack_pack): remove unnecessary negative value check.
[ruby-dev:22329]
* io.c (rb_io_ungetc): need fflush before ungetc if write buffer
is filled. [ruby-dev:22330]
Tue Dec 23 17:26:55 2003 KONISHI Hiromasa <konishih@fd6.so-net.ne.jp>
* bcc32/Makefile.sub (config.h): bcc has finite(). [ruby-list:38940]

5
eval.c
View File

@ -9204,12 +9204,13 @@ rb_thread_join(th, limit)
if (!NIL_P(th->errinfo) && (th->flags & THREAD_RAISED)) {
VALUE oldbt = get_backtrace(th->errinfo);
VALUE errat = make_backtrace();
VALUE errinfo = rb_obj_dup(th->errinfo);
if (TYPE(oldbt) == T_ARRAY && RARRAY(oldbt)->len > 0) {
rb_ary_unshift(errat, rb_ary_entry(oldbt, 0));
}
set_backtrace(th->errinfo, errat);
rb_exc_raise(th->errinfo);
set_backtrace(errinfo, errat);
rb_exc_raise(errinfo);
}
return Qtrue;

43
io.c
View File

@ -230,8 +230,8 @@ rb_io_check_readable(fptr)
!fptr->f2) {
io_seek(fptr, 0, SEEK_CUR);
}
fptr->mode |= FMODE_RBUF;
#endif
fptr->mode |= FMODE_RBUF;
}
void
@ -247,6 +247,7 @@ rb_io_check_writable(fptr)
io_seek(fptr, 0, SEEK_CUR);
}
#endif
fptr->mode &= ~FMODE_RBUF;
}
int
@ -568,6 +569,7 @@ rb_io_eof(io)
ungetc(ch, fptr->f);
return Qfalse;
}
clearerr(fptr->f);
return Qtrue;
}
@ -778,7 +780,6 @@ read_all(fptr, siz, str)
long bytes = 0;
long n;
if (feof(fptr->f)) return Qnil;
READ_CHECK(fptr->f);
if (siz == 0) siz = BUFSIZ;
if (NIL_P(str)) {
@ -3805,6 +3806,20 @@ argf_to_io()
return current_file;
}
static VALUE
argf_eof()
{
if (current_file) {
if (init_p == 0) return Qtrue;
ARGF_FORWARD();
if (rb_io_eof(current_file)) {
next_p = 1;
return Qtrue;
}
}
return Qfalse;
}
static VALUE
argf_read(argc, argv)
int argc;
@ -3824,18 +3839,16 @@ argf_read(argc, argv)
else {
tmp = io_read(argc, argv, current_file);
}
if (NIL_P(tmp)) {
if (NIL_P(str)) str = tmp;
else rb_str_append(str, tmp);
if (NIL_P(tmp) || argc == 0) {
if (next_p != -1) {
argf_close(current_file);
next_p = 1;
goto retry;
}
return str;
}
else if (NIL_P(str)) str = tmp;
else rb_str_append(str, tmp);
if (argc == 0) goto retry;
if (argc == 1) {
else if (argc == 1) {
if (RSTRING(str)->len < len) {
len -= RSTRING(str)->len;
argv[0] = INT2NUM(len);
@ -3880,20 +3893,6 @@ argf_readchar()
return c;
}
static VALUE
argf_eof()
{
if (current_file) {
if (init_p == 0) return Qtrue;
ARGF_FORWARD();
if (rb_io_eof(current_file)) {
next_p = 1;
return Qtrue;
}
}
return Qfalse;
}
static VALUE
argf_each_line(argc, argv)
int argc;

19
pack.c
View File

@ -22,14 +22,12 @@
#endif
#ifdef NATINT_PACK
# define OFF16B(p) ((char*)(p) + (natint?0:(sizeof(short) - SIZE16)))
# define OFF32B(p) ((char*)(p) + (natint?0:(sizeof(long) - SIZE32)))
# define NATINT_I32(x) (natint?NUM2LONG(x):(NUM2I32(x)))
# define NATINT_U32(x) (natint?NUM2ULONG(x):(NUM2U32(x)))
# define NATINT_LEN(type,len) (natint?sizeof(type):(len))
# ifdef WORDS_BIGENDIAN
# define OFF16(p) OFF16B(p)
# define OFF32(p) OFF32B(p)
# define OFF16(p) ((char*)(p) + (natint?0:(sizeof(short) - SIZE16)))
# define OFF32(p) ((char*)(p) + (natint?0:(sizeof(long) - SIZE32)))
# endif
# define NATINT_HTOVS(x) (natint?htovs(x):htov16(x))
# define NATINT_HTOVL(x) (natint?htovl(x):htov32(x))
@ -50,11 +48,6 @@
# define OFF32(p) (char*)(p)
#endif
#ifndef OFF16B
# define OFF16B(p) (char*)(p)
# define OFF32B(p) (char*)(p)
#endif
#define define_swapx(x, xtype) \
static xtype \
TOKEN_PASTE(swap,x)(z) \
@ -775,7 +768,7 @@ pack_pack(ary, fmt)
s = NUM2INT(from);
}
s = NATINT_HTONS(s);
rb_str_buf_cat(res, OFF16B(&s), NATINT_LEN(short,2));
rb_str_buf_cat(res, OFF16(&s), NATINT_LEN(short,2));
}
break;
@ -789,7 +782,7 @@ pack_pack(ary, fmt)
l = NATINT_U32(from);
}
l = NATINT_HTONL(l);
rb_str_buf_cat(res, OFF32B(&l), NATINT_LEN(long,4));
rb_str_buf_cat(res, OFF32(&l), NATINT_LEN(long,4));
}
break;
@ -1654,7 +1647,7 @@ pack_unpack(str, fmt)
PACK_LENGTH_ADJUST(unsigned short,2);
while (len-- > 0) {
unsigned short tmp = 0;
memcpy(OFF16B(&tmp), s, NATINT_LEN(unsigned short,2));
memcpy(OFF16(&tmp), s, NATINT_LEN(unsigned short,2));
s += NATINT_LEN(unsigned short,2);
rb_ary_push(ary, UINT2NUM(ntohs(tmp)));
}
@ -1665,7 +1658,7 @@ pack_unpack(str, fmt)
PACK_LENGTH_ADJUST(unsigned long,4);
while (len-- > 0) {
unsigned long tmp = 0;
memcpy(OFF32B(&tmp), s, NATINT_LEN(unsigned long,4));
memcpy(OFF32(&tmp), s, NATINT_LEN(unsigned long,4));
s += NATINT_LEN(unsigned long,4);
rb_ary_push(ary, ULONG2NUM(ntohl(tmp)));
}

View File

@ -11,7 +11,7 @@ module TestEOF
}
open_file("") {|f|
assert_nil(f.read(1))
assert_nil(f.read)
assert_equal("", f.read)
assert_nil(f.read(1))
}
end
@ -20,9 +20,9 @@ module TestEOF
return unless respond_to? :open_file_rw
open_file_rw("") {|f|
assert_equal("", f.read)
assert_nil(f.read)
assert_equal("", f.read)
assert_equal(0, f.syswrite(""))
assert_nil(f.read)
assert_equal("", f.read)
}
end
@ -43,19 +43,19 @@ module TestEOF
open_file("a") {|f|
assert_equal("a", f.read(2))
assert_nil(f.read(1))
assert_nil(f.read)
assert_equal("", f.read)
assert_nil(f.read(1))
}
open_file("a") {|f|
assert_equal("a", f.read)
assert_nil(f.read(1))
assert_nil(f.read)
assert_equal("", f.read)
assert_nil(f.read(1))
}
open_file("a") {|f|
assert_equal("a", f.read(2))
assert_nil(f.read)
assert_nil(f.read)
assert_equal("", f.read)
assert_equal("", f.read)
}
open_file("a") {|f|
assert_equal("a", f.read)
@ -77,18 +77,18 @@ module TestEOF
assert_equal("", f.read(0))
assert_equal("", f.read)
assert_nil(f.read(0))
assert_nil(f.read)
assert_equal("", f.read)
}
end
def test_eof_1_seek
open_file_seek("a", 10) {|f|
assert_equal("", f.read)
assert_nil(f.read)
assert_equal("", f.read)
}
open_file_seek("a", 1) {|f|
assert_equal("", f.read)
assert_nil(f.read)
assert_equal("", f.read)
}
end
end