[macruby-changes] [1357] MacRuby/branches/experimental

source_changes at macosforge.org source_changes at macosforge.org
Sat Apr 4 16:35:03 PDT 2009


Revision: 1357
          http://trac.macosforge.org/projects/ruby/changeset/1357
Author:   pthomson at apple.com
Date:     2009-04-04 16:35:01 -0700 (Sat, 04 Apr 2009)
Log Message:
-----------
Made the IO#flush and IO#sync properties conform to their respective RubySpecs, even though we don't use them (MacRuby IO is unbuffered.

Modified Paths:
--------------
    MacRuby/branches/experimental/io.c
    MacRuby/branches/experimental/rakelib/spec.rake

Modified: MacRuby/branches/experimental/io.c
===================================================================
--- MacRuby/branches/experimental/io.c	2009-04-04 23:04:23 UTC (rev 1356)
+++ MacRuby/branches/experimental/io.c	2009-04-04 23:35:01 UTC (rev 1357)
@@ -248,6 +248,14 @@
 			(CFReadStreamGetStatus(io_struct->readStream) == kCFStreamStatusOpen));
 }
 
+static void
+rb_io_assert_open(rb_io_t *io_struct)
+{
+	if (!rb_io_is_open(io_struct)) {
+		rb_raise(rb_eIOError, "cannot perform that operation on a closed stream");
+	}
+}
+
 static bool
 rb_io_is_closed_for_reading(rb_io_t *io_struct) 
 {
@@ -472,7 +480,9 @@
 VALUE
 rb_io_flush(VALUE io, SEL sel)
 {
-    // TODO investigate how to flush a CFStream...
+	rb_io_t *io_struct = ExtractIOStruct(io);
+	rb_io_assert_open(io_struct);
+	// rb_warn("IO#flush on MacRuby is a no-op, as MacRuby does not buffer its IO streams internally");
     return io;
 }
 
@@ -663,6 +673,7 @@
 rb_io_sync(VALUE io, SEL sel)
 {
     rb_io_t *io_struct = ExtractIOStruct(io);
+	rb_io_assert_open(io_struct);
     return io_struct->sync ? Qtrue : Qfalse;
 }
 
@@ -685,7 +696,9 @@
 rb_io_set_sync(VALUE io, SEL sel, VALUE mode)
 {
     rb_io_t *io_struct = ExtractIOStruct(io);
+	rb_io_assert_open(io_struct);
     io_struct->sync = RTEST(mode);
+	//if (io_struct->sync) rb_warn("The IO sync property is ignored, MacRuby does not buffer its IO streams internally");
     return mode;
 }
 
@@ -704,7 +717,10 @@
 static VALUE
 rb_io_fsync(VALUE io, SEL sel)
 {
-     rb_notimplement();   
+	rb_io_t *io_struct = ExtractIOStruct(io);
+	rb_io_assert_writable(io_struct);
+	if(fsync(io_struct->fd) < 0) rb_sys_fail("fsync() failed.");
+	return INT2FIX(0);
 }
 
 /*
@@ -723,9 +739,7 @@
 rb_io_fileno(VALUE io, SEL sel)
 {
     rb_io_t *io_struct = ExtractIOStruct(io);
-	if(!rb_io_is_open(io_struct)) {
-		rb_raise(rb_eIOError, "closed stream");
-	}
+	rb_io_assert_open(io_struct);
     return INT2FIX(io_struct->fd);
 }
 

Modified: MacRuby/branches/experimental/rakelib/spec.rake
===================================================================
--- MacRuby/branches/experimental/rakelib/spec.rake	2009-04-04 23:04:23 UTC (rev 1356)
+++ MacRuby/branches/experimental/rakelib/spec.rake	2009-04-04 23:35:01 UTC (rev 1357)
@@ -31,10 +31,13 @@
   KNOWN_GOOD_CORE_IO = %w{
     closed
     fileno
+    fsync
+    flush
     io
     inspect
     putc
     readchar
+    sync
     to_i
     to_io
     initialize
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090404/69cd0dbd/attachment.html>


More information about the macruby-changes mailing list