[macruby-changes] [2335] MacRuby/trunk/io.c

source_changes at macosforge.org source_changes at macosforge.org
Sun Aug 16 00:02:06 PDT 2009


Revision: 2335
          http://trac.macosforge.org/projects/ruby/changeset/2335
Author:   lsansonetti at apple.com
Date:     2009-08-16 00:02:05 -0700 (Sun, 16 Aug 2009)
Log Message:
-----------
fixed a few things

Modified Paths:
--------------
    MacRuby/trunk/io.c

Modified: MacRuby/trunk/io.c
===================================================================
--- MacRuby/trunk/io.c	2009-08-16 02:49:56 UTC (rev 2334)
+++ MacRuby/trunk/io.c	2009-08-16 07:02:05 UTC (rev 2335)
@@ -811,9 +811,9 @@
     rb_io_t *io_struct = ExtractIOStruct(io);
     rb_io_assert_readable(io_struct);
 
-    if ((CFReadStreamGetStatus(io_struct->readStream) == kCFStreamStatusAtEnd)) {
-		// if there's anything left in the ungetc buffer, this io is not at EOF
-		return (io_struct->ungetc_buf_len == 0) ? Qtrue : Qfalse;
+    if (CFReadStreamGetStatus(io_struct->readStream) == kCFStreamStatusAtEnd) {
+	// If there's anything left in the ungetc buffer, this io is not at EOF.
+	return io_struct->ungetc_buf_len == 0 ? Qtrue : Qfalse;
     }
 
     // The stream is still open, however, there might not be any data left.
@@ -1206,7 +1206,7 @@
         return rb_io_read_all(io_struct, outbuf);
     }
 
-    long size = FIX2LONG(len);
+    const long size = FIX2LONG(len);
     if (size == 0) {
 	return rb_str_new2("");
     }
@@ -1215,7 +1215,7 @@
     CFDataIncreaseLength(data, size);
     UInt8 *buf = CFDataGetMutableBytePtr(data);
 
-    long data_read = rb_io_read_internal(io_struct, buf, size);
+    const long data_read = rb_io_read_internal(io_struct, buf, size);
     if (data_read == 0) {
 	return Qnil;
     }
@@ -1330,9 +1330,6 @@
     }
     rb_io_t *io_struct = ExtractIOStruct(io);
     rb_io_assert_readable(io_struct);
-    if (rb_io_eof(io, 0) == Qtrue) {
-	return Qnil;
-    }
 
     if (NIL_P(rb_rs)) {
 	// TODO: Get rid of this when the fix comes in for the $\ variable.
@@ -1355,7 +1352,7 @@
 	    sep = (VALUE)CFSTR("\n\n");
 	}
     }
-    long line_limit = (NIL_P(limit) ? -1 : FIX2LONG(limit));
+    const long line_limit = NIL_P(limit) ? -1 : FIX2LONG(limit);
     // now that we've got our parameters, let's get down to business.
 
     VALUE bstr = rb_bytestring_new();
@@ -1542,12 +1539,8 @@
 static VALUE
 rb_io_each_line(VALUE io, SEL sel, int argc, VALUE *argv)
 {
-	if (!rb_block_given_p())
-	{
-		// return an enumerator unless given a block.
-		return rb_enumeratorize(io, sel_each_line, 0, NULL);
-	}
-	
+    RETURN_ENUMERATOR(io, argc, argv);
+
     VALUE line = rb_io_gets_m(io, sel, argc, argv);
     while (!NIL_P(line)) {
 	rb_vm_yield(1, &line);
@@ -1573,14 +1566,9 @@
 static VALUE
 rb_io_each_byte(VALUE io, SEL sel)
 {
-	if (!rb_block_given_p())
-	{
-		// return an enumerator unless given a block.
-		return rb_enumeratorize(io, sel_each_byte, 0, NULL);
-	}
-	
-    VALUE b = rb_io_getbyte(io, 0);
+    RETURN_ENUMERATOR(io, 0, 0);
 
+    VALUE b = rb_io_getbyte(io, 0);
     while (!NIL_P(b)) {
 	rb_vm_yield(1, &b);
 	b = rb_io_getbyte(io, 0);
@@ -1605,14 +1593,9 @@
 static VALUE
 rb_io_each_char(VALUE io, SEL sel)
 {
-	if (!rb_block_given_p())
-	{
-		// return an enumerator unless given a block.
-		return rb_enumeratorize(io, sel_each_char, 0, NULL);
-	}
-	
+    RETURN_ENUMERATOR(io, 0, 0);
+
     VALUE c = rb_io_getc(io, 0);
-	
     while (!NIL_P(c)) {
 	rb_vm_yield(1, &c);
 	c = rb_io_getc(io, 0);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090816/c190eb96/attachment-0001.html>


More information about the macruby-changes mailing list