summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-10-30 09:36:41 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-10-30 09:36:41 +0000
commit1a8ccefafc490875a90515907f05a565c4c8f7ba (patch)
tree68dd6036eca5931bd9c70030d9df7bfbe1a1c6cd
parentcf22db8d6910a428b2bb51b3c78c34b86d83bf74 (diff)
* 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
-rw-r--r--ChangeLog10
-rw-r--r--eval.c36
-rw-r--r--io.c16
-rw-r--r--lib/fileutils.rb5
-rw-r--r--test/drb/test_drb.rb134
-rw-r--r--test/ruby/test_case.rb9
6 files changed, 135 insertions, 75 deletions
diff --git a/ChangeLog b/ChangeLog
index a26d0df4ce..84b474857c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
* 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): remove never occurred NODE_WHEN branch.
-
Thu Oct 30 10:14:51 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* lib/test/unit/autorunner.rb: make fox runners work.
diff --git a/eval.c b/eval.c
index 2252dee7c1..d6978b0571 100644
--- a/eval.c
+++ b/eval.c
@@ -2585,6 +2585,42 @@ rb_eval(self, n)
}
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:
{
VALUE val;
diff --git a/io.c b/io.c
index ee030e894a..cac35eb7e6 100644
--- a/io.c
+++ b/io.c
@@ -140,6 +140,10 @@ static VALUE lineno;
/* requires systems own version of the ReadDataPending() */
extern int ReadDataPending();
# 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
#ifndef READ_DATA_PENDING_PTR
@@ -1366,11 +1370,6 @@ rb_io_fptr_cleanup(fptr, noraise)
else {
fptr_finalize(fptr, noraise);
}
-
- if (fptr->path) {
- free(fptr->path);
- fptr->path = 0;
- }
}
void
@@ -1378,6 +1377,9 @@ rb_io_fptr_finalize(fptr)
OpenFile *fptr;
{
if (!fptr) return;
+ if (fptr->path) {
+ free(fptr->path);
+ }
if (!fptr->f && !fptr->f2) return;
if (fileno(fptr->f) < 3) return;
@@ -1510,7 +1512,7 @@ rb_io_sysseek(argc, argv, io)
}
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");
}
if ((fptr->mode & FMODE_WRITABLE) && (fptr->mode & FMODE_WBUF)) {
@@ -1567,7 +1569,7 @@ rb_io_sysread(argc, argv, io)
GetOpenFile(io, 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");
}
if (NIL_P(str)) {
diff --git a/lib/fileutils.rb b/lib/fileutils.rb
index dfec5f9005..e65033f9bd 100644
--- a/lib/fileutils.rb
+++ b/lib/fileutils.rb
@@ -399,9 +399,10 @@ module FileUtils
#
def copy_file( src, dest )
File.open(src, 'rb') {|r|
- File.open(dest, 'wb') {|w|
+ File.open(dest, 'wb') {|w|
copy_stream r, w
- } }
+ }
+ }
end
#
diff --git a/test/drb/test_drb.rb b/test/drb/test_drb.rb
index bd16e86368..753ff09335 100644
--- a/test/drb/test_drb.rb
+++ b/test/drb/test_drb.rb
@@ -16,86 +16,92 @@ class TestDRbYield < Test::Unit::TestCase
end
def test_01_one
- one = nil
- @there.echo_yield_1([]) {|one|}
- assert_equal([], one)
+ @there.echo_yield_1([]) {|one|
+ assert_equal([], one)
+ }
- one = nil
- @there.echo_yield_1(1) {|one|}
- assert_equal(1, one)
+ @there.echo_yield_1(1) {|one|
+ assert_equal(1, one)
+ }
- one = nil
- @there.echo_yield_1(nil) {|one|}
- assert_equal(nil, one)
+ @there.echo_yield_1(nil) {|one|
+ assert_equal(nil, one)
+ }
end
def test_02_two
- one = two = nil
- @there.echo_yield_2([], []) {|one, two|}
- assert_equal([], one)
- assert_equal([], two)
-
- one = two = nil
- @there.echo_yield_2(1, 2) {|one, two|}
- assert_equal(1, one)
- assert_equal(2, two)
-
- one = two = nil
- @there.echo_yield_2(3, nil) {|one, two|}
- assert_equal(3, one)
- assert_equal(nil, two)
-
- one = two = nil
- @there.echo_yield_1([:key, :value]) {|one, two|}
- assert_equal([:key, :value], one)
- assert_equal(nil, two)
+ @there.echo_yield_2([], []) {|one, two|
+ assert_equal([], one)
+ assert_equal([], two)
+ }
+
+ @there.echo_yield_2(1, 2) {|one, two|
+ assert_equal(1, one)
+ assert_equal(2, two)
+ }
+
+ @there.echo_yield_2(3, nil) {|one, two|
+ assert_equal(3, one)
+ assert_equal(nil, two)
+ }
+
+ @there.echo_yield_1([:key, :value]) {|one, two|
+ assert_equal(:key, one)
+ assert_equal(:value, two)
+ }
end
def test_03_many
- s = nil
- @there.echo_yield_0 {|*s|}
- assert_equal([], s)
- @there.echo_yield(nil) {|*s|}
- assert_equal([nil], s)
- @there.echo_yield(1) {|*s|}
- assert_equal([1], s)
- @there.echo_yield(1, 2) {|*s|}
- assert_equal([1, 2], s)
- @there.echo_yield(1, 2, 3) {|*s|}
- assert_equal([1, 2, 3], s)
- @there.echo_yield([], []) {|*s|}
- assert_equal([[], []], s)
- @there.echo_yield([]) {|*s|}
- if RUBY_VERSION >= '1.8'
+ @there.echo_yield_0 {|*s|
+ assert_equal([], s)
+ }
+ @there.echo_yield(nil) {|*s|
+ assert_equal([nil], s)
+ }
+ @there.echo_yield(1) {|*s|
+ assert_equal([1], s)
+ }
+ @there.echo_yield(1, 2) {|*s|
+ assert_equal([1, 2], s)
+ }
+ @there.echo_yield(1, 2, 3) {|*s|
+ assert_equal([1, 2, 3], s)
+ }
+ @there.echo_yield([], []) {|*s|
+ assert_equal([[], []], s)
+ }
+ @there.echo_yield([]) {|*s|
assert_equal([[]], s) # !
- else
- assert_equal([], s) # !
- end
+ }
end
def test_04_many_to_one
- s = nil
- @there.echo_yield_0 {|*s|}
- assert_equal([], s)
- @there.echo_yield(nil) {|*s|}
- assert_equal([nil], s)
- @there.echo_yield(1) {|*s|}
- assert_equal([1], s)
- @there.echo_yield(1, 2) {|*s|}
- assert_equal([1, 2], s)
- @there.echo_yield(1, 2, 3) {|*s|}
- assert_equal([1, 2, 3], s)
- @there.echo_yield([], []) {|*s|}
- assert_equal([[], []], s)
- @there.echo_yield([]) {|*s|}
- assert_equal([[]], s)
+ @there.echo_yield_0 {|*s|
+ assert_equal([], s)
+ }
+ @there.echo_yield(nil) {|*s|
+ assert_equal([nil], s)
+ }
+ @there.echo_yield(1) {|*s|
+ assert_equal([1], s)
+ }
+ @there.echo_yield(1, 2) {|*s|
+ assert_equal([1, 2], s)
+ }
+ @there.echo_yield(1, 2, 3) {|*s|
+ assert_equal([1, 2, 3], s)
+ }
+ @there.echo_yield([], []) {|*s|
+ assert_equal([[], []], s)
+ }
+ @there.echo_yield([]) {|*s|
+ assert_equal([[]], s)
+ }
end
def test_05_array_subclass
@there.xarray_each {|x| assert_kind_of(XArray, x)}
- if RUBY_VERSION >= '1.8'
- @there.xarray_each {|*x| assert_kind_of(XArray, x[0])}
- end
+ @there.xarray_each {|*x| assert_kind_of(XArray, x[0])}
end
end
diff --git a/test/ruby/test_case.rb b/test/ruby/test_case.rb
index 5046193662..2407356965 100644
--- a/test/ruby/test_case.rb
+++ b/test/ruby/test_case.rb
@@ -38,5 +38,14 @@ class TestCase < Test::Unit::TestCase
else
assert(false)
end
+
+ case
+ when true
+ assert(true)
+ when false, nil
+ assert(false)
+ else
+ assert(false)
+ end
end
end