* io.c (READ_DATA_BUFFERED): new macro to detect whether stdio

buffer filled.

* io.c (rb_io_fptr_cleanup): move path deallocation to
  rb_io_fptr_finalize (finalizer called by GC).


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4865 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2003-10-30 09:36:41 +00:00
parent cf22db8d69
commit 1a8ccefafc
6 changed files with 132 additions and 72 deletions

View File

@ -1,11 +1,17 @@
Thu Oct 30 14:25:31 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (READ_DATA_BUFFERED): new macro to detect whether stdio
buffer filled.
* io.c (rb_io_fptr_cleanup): move path deallocation to
rb_io_fptr_finalize (finalizer called by GC).
Thu Oct 30 13:23:39 2003 Yukihiro Matsumoto <matz@ruby-lang.org> Thu Oct 30 13:23:39 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* parse.y (logop): left may be NULL. [ruby-talk:84539] * parse.y (logop): left may be NULL. [ruby-talk:84539]
* eval.c (rb_eval): NODE_CASE nd_head may be NULL. * eval.c (rb_eval): NODE_CASE nd_head may be NULL.
* eval.c (rb_eval): remove never occurred NODE_WHEN branch.
Thu Oct 30 10:14:51 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org> Thu Oct 30 10:14:51 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* lib/test/unit/autorunner.rb: make fox runners work. * lib/test/unit/autorunner.rb: make fox runners work.

36
eval.c
View File

@ -2585,6 +2585,42 @@ rb_eval(self, n)
} }
goto again; goto again;
case NODE_WHEN:
while (node) {
NODE *tag;
if (nd_type(node) != NODE_WHEN) goto again;
tag = node->nd_head;
while (tag) {
if (trace_func) {
call_trace_func("line", tag, self,
ruby_frame->last_func,
ruby_frame->last_class);
}
if (tag->nd_head && nd_type(tag->nd_head) == NODE_WHEN) {
VALUE v = rb_eval(self, tag->nd_head->nd_head);
long i;
if (TYPE(v) != T_ARRAY) v = rb_ary_to_ary(v);
for (i=0; i<RARRAY(v)->len; i++) {
if (RTEST(RARRAY(v)->ptr[i])) {
node = node->nd_body;
goto again;
}
}
tag = tag->nd_next;
continue;
}
if (RTEST(rb_eval(self, tag->nd_head))) {
node = node->nd_body;
goto again;
}
tag = tag->nd_next;
}
node = node->nd_next;
}
RETURN(Qnil);
case NODE_CASE: case NODE_CASE:
{ {
VALUE val; VALUE val;

16
io.c
View File

@ -140,6 +140,10 @@ static VALUE lineno;
/* requires systems own version of the ReadDataPending() */ /* requires systems own version of the ReadDataPending() */
extern int ReadDataPending(); extern int ReadDataPending();
# define READ_DATA_PENDING(fp) (!feof(fp)) # define READ_DATA_PENDING(fp) (!feof(fp))
# define READ_DATA_BUFFERED(fp) 0
#endif
#ifndef READ_DATA_BUFFERED
# define READ_DATA_BUFFERED(fp) READ_DATA_PENDING(fp)
#endif #endif
#ifndef READ_DATA_PENDING_PTR #ifndef READ_DATA_PENDING_PTR
@ -1366,11 +1370,6 @@ rb_io_fptr_cleanup(fptr, noraise)
else { else {
fptr_finalize(fptr, noraise); fptr_finalize(fptr, noraise);
} }
if (fptr->path) {
free(fptr->path);
fptr->path = 0;
}
} }
void void
@ -1378,6 +1377,9 @@ rb_io_fptr_finalize(fptr)
OpenFile *fptr; OpenFile *fptr;
{ {
if (!fptr) return; if (!fptr) return;
if (fptr->path) {
free(fptr->path);
}
if (!fptr->f && !fptr->f2) return; if (!fptr->f && !fptr->f2) return;
if (fileno(fptr->f) < 3) return; if (fileno(fptr->f) < 3) return;
@ -1510,7 +1512,7 @@ rb_io_sysseek(argc, argv, io)
} }
GetOpenFile(io, fptr); GetOpenFile(io, fptr);
if ((fptr->mode & FMODE_READABLE) && READ_DATA_PENDING(fptr->f)) { if ((fptr->mode & FMODE_READABLE) && READ_DATA_BUFFERED(fptr->f)) {
rb_raise(rb_eIOError, "sysseek for buffered IO"); rb_raise(rb_eIOError, "sysseek for buffered IO");
} }
if ((fptr->mode & FMODE_WRITABLE) && (fptr->mode & FMODE_WBUF)) { if ((fptr->mode & FMODE_WRITABLE) && (fptr->mode & FMODE_WBUF)) {
@ -1567,7 +1569,7 @@ rb_io_sysread(argc, argv, io)
GetOpenFile(io, fptr); GetOpenFile(io, fptr);
rb_io_check_readable(fptr); rb_io_check_readable(fptr);
if (READ_DATA_PENDING(fptr->f)) { if (READ_DATA_BUFFERED(fptr->f)) {
rb_raise(rb_eIOError, "sysread for buffered IO"); rb_raise(rb_eIOError, "sysread for buffered IO");
} }
if (NIL_P(str)) { if (NIL_P(str)) {

View File

@ -401,7 +401,8 @@ module FileUtils
File.open(src, 'rb') {|r| File.open(src, 'rb') {|r|
File.open(dest, 'wb') {|w| File.open(dest, 'wb') {|w|
copy_stream r, w copy_stream r, w
} } }
}
end end
# #

View File

@ -16,87 +16,93 @@ class TestDRbYield < Test::Unit::TestCase
end end
def test_01_one def test_01_one
one = nil @there.echo_yield_1([]) {|one|
@there.echo_yield_1([]) {|one|}
assert_equal([], one) assert_equal([], one)
}
one = nil @there.echo_yield_1(1) {|one|
@there.echo_yield_1(1) {|one|}
assert_equal(1, one) assert_equal(1, one)
}
one = nil @there.echo_yield_1(nil) {|one|
@there.echo_yield_1(nil) {|one|}
assert_equal(nil, one) assert_equal(nil, one)
}
end end
def test_02_two def test_02_two
one = two = nil @there.echo_yield_2([], []) {|one, two|
@there.echo_yield_2([], []) {|one, two|}
assert_equal([], one) assert_equal([], one)
assert_equal([], two) assert_equal([], two)
}
one = two = nil @there.echo_yield_2(1, 2) {|one, two|
@there.echo_yield_2(1, 2) {|one, two|}
assert_equal(1, one) assert_equal(1, one)
assert_equal(2, two) assert_equal(2, two)
}
one = two = nil @there.echo_yield_2(3, nil) {|one, two|
@there.echo_yield_2(3, nil) {|one, two|}
assert_equal(3, one) assert_equal(3, one)
assert_equal(nil, two) assert_equal(nil, two)
}
one = two = nil @there.echo_yield_1([:key, :value]) {|one, two|
@there.echo_yield_1([:key, :value]) {|one, two|} assert_equal(:key, one)
assert_equal([:key, :value], one) assert_equal(:value, two)
assert_equal(nil, two) }
end end
def test_03_many def test_03_many
s = nil @there.echo_yield_0 {|*s|
@there.echo_yield_0 {|*s|}
assert_equal([], s) assert_equal([], s)
@there.echo_yield(nil) {|*s|} }
@there.echo_yield(nil) {|*s|
assert_equal([nil], s) assert_equal([nil], s)
@there.echo_yield(1) {|*s|} }
@there.echo_yield(1) {|*s|
assert_equal([1], s) assert_equal([1], s)
@there.echo_yield(1, 2) {|*s|} }
@there.echo_yield(1, 2) {|*s|
assert_equal([1, 2], s) assert_equal([1, 2], s)
@there.echo_yield(1, 2, 3) {|*s|} }
@there.echo_yield(1, 2, 3) {|*s|
assert_equal([1, 2, 3], s) assert_equal([1, 2, 3], s)
@there.echo_yield([], []) {|*s|} }
@there.echo_yield([], []) {|*s|
assert_equal([[], []], s) assert_equal([[], []], s)
@there.echo_yield([]) {|*s|} }
if RUBY_VERSION >= '1.8' @there.echo_yield([]) {|*s|
assert_equal([[]], s) # ! assert_equal([[]], s) # !
else }
assert_equal([], s) # !
end
end end
def test_04_many_to_one def test_04_many_to_one
s = nil @there.echo_yield_0 {|*s|
@there.echo_yield_0 {|*s|}
assert_equal([], s) assert_equal([], s)
@there.echo_yield(nil) {|*s|} }
@there.echo_yield(nil) {|*s|
assert_equal([nil], s) assert_equal([nil], s)
@there.echo_yield(1) {|*s|} }
@there.echo_yield(1) {|*s|
assert_equal([1], s) assert_equal([1], s)
@there.echo_yield(1, 2) {|*s|} }
@there.echo_yield(1, 2) {|*s|
assert_equal([1, 2], s) assert_equal([1, 2], s)
@there.echo_yield(1, 2, 3) {|*s|} }
@there.echo_yield(1, 2, 3) {|*s|
assert_equal([1, 2, 3], s) assert_equal([1, 2, 3], s)
@there.echo_yield([], []) {|*s|} }
@there.echo_yield([], []) {|*s|
assert_equal([[], []], s) assert_equal([[], []], s)
@there.echo_yield([]) {|*s|} }
@there.echo_yield([]) {|*s|
assert_equal([[]], s) assert_equal([[]], s)
}
end end
def test_05_array_subclass def test_05_array_subclass
@there.xarray_each {|x| assert_kind_of(XArray, x)} @there.xarray_each {|x| assert_kind_of(XArray, x)}
if RUBY_VERSION >= '1.8'
@there.xarray_each {|*x| assert_kind_of(XArray, x[0])} @there.xarray_each {|*x| assert_kind_of(XArray, x[0])}
end end
end
end end
class TestRubyYield < TestDRbYield class TestRubyYield < TestDRbYield

View File

@ -38,5 +38,14 @@ class TestCase < Test::Unit::TestCase
else else
assert(false) assert(false)
end end
case
when true
assert(true)
when false, nil
assert(false)
else
assert(false)
end
end end
end end