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

source_changes at macosforge.org source_changes at macosforge.org
Thu Jun 11 11:29:23 PDT 2009


Revision: 1836
          http://trac.macosforge.org/projects/ruby/changeset/1836
Author:   pthomson at apple.com
Date:     2009-06-11 11:29:22 -0700 (Thu, 11 Jun 2009)
Log Message:
-----------
Implemented IO#reopen and fixed all but two of the specs.

Modified Paths:
--------------
    MacRuby/branches/experimental/io.c
    MacRuby/branches/experimental/spec/frozen/tags/macruby/core/io/reopen_tags.txt

Modified: MacRuby/branches/experimental/io.c
===================================================================
--- MacRuby/branches/experimental/io.c	2009-06-11 17:22:38 UTC (rev 1835)
+++ MacRuby/branches/experimental/io.c	2009-06-11 18:29:22 UTC (rev 1836)
@@ -372,7 +372,7 @@
 	io_struct->writeStream = NULL;
     }
     if (io_struct->pid != -1) {
-	// Don't commit sepuku!
+	// Don't commit seppuku!
 	if (io_struct->pid != 0 && io_struct->pid != getpid()) {
 	    kill(io_struct->pid, SIGTERM);
 	}
@@ -2284,7 +2284,29 @@
 static VALUE
 rb_io_reopen(VALUE io, SEL sel, int argc, VALUE *argv)
 {
-    rb_notimplement();
+	VALUE path_or_io, mode_string;
+	rb_scan_args(argc, argv, "11", &path_or_io, &mode_string);
+	rb_io_t *io_s = ExtractIOStruct(io);
+	rb_io_assert_open(io_s);
+	
+	if (TYPE(path_or_io) == T_STRING) {
+		// Reassociate it with the stream opened on the given path
+		if (NIL_P(mode_string)) {
+			mode_string = (VALUE)CFSTR("r");
+		}
+		FilePathValue(path_or_io); // Sanitize the name
+		const char *filepath = RSTRING_PTR(path_or_io);
+		int fd = open(filepath, convert_mode_string_to_oflags(mode_string), 0644);
+		prepare_io_from_fd(io_s, fd, convert_mode_string_to_fmode(mode_string), true);
+		GC_WB(&io_s->path, path_or_io);
+		return io;
+	} else {
+		// reassociate it with the stream given in the other io
+		rb_io_t *other = ExtractIOStruct(path_or_io);
+		rb_io_assert_open(other);
+		RFILE(io)->fptr = other;
+		return io;
+	}
 }
 
 /* :nodoc: */

Modified: MacRuby/branches/experimental/spec/frozen/tags/macruby/core/io/reopen_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/macruby/core/io/reopen_tags.txt	2009-06-11 17:22:38 UTC (rev 1835)
+++ MacRuby/branches/experimental/spec/frozen/tags/macruby/core/io/reopen_tags.txt	2009-06-11 18:29:22 UTC (rev 1836)
@@ -1,8 +1,2 @@
-fails:IO#reopen raises IOError on closed stream
-fails:IO#reopen reassociates self to another file/descriptor but returns self
-fails:IO#reopen reassociates self with a new stream opened on path, when self in initial state
-fails:IO#reopen reassociates self with a new stream opened on path, after some reads
 fails:IO#reopen reassociates self with a new stream opened on path, after some writes
-fails:IO#reopen reassociates self with the I/O stream specified as an argument, after some reads
-fails:IO#reopen reassociates self with the I/O stream specified as an argument, after some writes
 fails:IO#reopen reassociates self with new a new stream after some reads
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090611/a8eae827/attachment-0001.html>


More information about the macruby-changes mailing list