summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog32
-rw-r--r--eval.c5
-rw-r--r--io.c43
-rw-r--r--pack.c19
-rw-r--r--test/ruby/ut_eof.rb20
5 files changed, 69 insertions, 50 deletions
diff --git a/ChangeLog b/ChangeLog
index 67faca8380..0e84d6a73d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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]
diff --git a/eval.c b/eval.c
index 8d19602c4f..0e033c2c78 100644
--- a/eval.c
+++ b/eval.c
@@ -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;
diff --git a/io.c b/io.c
index 8ecf0c1426..de3d7230d8 100644
--- a/io.c
+++ b/io.c
@@ -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)) {
@@ -3806,6 +3807,20 @@ argf_to_io()
}
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;
VALUE *argv;
@@ -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);
@@ -3881,20 +3894,6 @@ argf_readchar()
}
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;
VALUE *argv;
diff --git a/pack.c b/pack.c
index 1c9f2f2b2c..e4a301c2e3 100644
--- a/pack.c
+++ b/pack.c
@@ -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)));
}
diff --git a/test/ruby/ut_eof.rb b/test/ruby/ut_eof.rb
index d4b0b6db39..8b3cc8101b 100644
--- a/test/ruby/ut_eof.rb
+++ b/test/ruby/ut_eof.rb
@@ -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