[macruby-changes] [1360] MacRuby/branches/experimental
source_changes at macosforge.org
source_changes at macosforge.org
Sat Apr 4 17:01:59 PDT 2009
Revision: 1360
http://trac.macosforge.org/projects/ruby/changeset/1360
Author: pthomson at apple.com
Date: 2009-04-04 17:01:59 -0700 (Sat, 04 Apr 2009)
Log Message:
-----------
Specified IO#syswrite, #sysread, and #sysseek to be aliases of the regular commands.
Modified Paths:
--------------
MacRuby/branches/experimental/io.c
MacRuby/branches/experimental/rakelib/spec.rake
MacRuby/branches/experimental/spec/frozen/core/io/shared/write.rb
MacRuby/branches/experimental/string.c
Modified: MacRuby/branches/experimental/io.c
===================================================================
--- MacRuby/branches/experimental/io.c 2009-04-04 23:54:43 UTC (rev 1359)
+++ MacRuby/branches/experimental/io.c 2009-04-05 00:01:59 UTC (rev 1360)
@@ -371,6 +371,19 @@
/*
* call-seq:
+ * ios.syswrite(string) => integer
+ *
+ * Writes the given string to <em>ios</em> using a low-level write.
+ * Returns the number of bytes written. Do not mix with other methods
+ * that write to <em>ios</em> or you may get unpredictable results.
+ * Raises <code>SystemCallError</code> on error.
+ *
+ * f = File.new("out", "w")
+ * f.syswrite("ABCDEF") #=> 6
+ */
+
+/*
+ * call-seq:
* ios.write(string) => integer
*
* Writes the given string to <em>ios</em>. The stream must be opened
@@ -402,7 +415,6 @@
// TODO: Account for the port not being IO, use funcall to call .write()
// instead.
- // TODO: Honor io_struct->sync
to_write = rb_obj_as_string(to_write);
@@ -543,6 +555,20 @@
/*
* call-seq:
+ * ios.sysseek(offset, whence=SEEK_SET) => integer
+ *
+ * Seeks to a given <i>offset</i> in the stream according to the value
+ * of <i>whence</i> (see <code>IO#seek</code> for values of
+ * <i>whence</i>). Returns the new offset into the file.
+ *
+ * f = File.new("testfile")
+ * f.sysseek(-13, IO::SEEK_END) #=> 53
+ * f.sysread(10) #=> "And so on."
+ */
+
+
+/*
+ * call-seq:
* ios.seek(amount, whence=SEEK_SET) -> 0
*
* Seeks to a given offset <i>anInteger</i> in the stream according to
@@ -1005,6 +1031,22 @@
/*
* call-seq:
+ * ios.sysread(integer[, outbuf]) => string
+ *
+ * Reads <i>integer</i> bytes from <em>ios</em> using a low-level
+ * read and returns them as a string. Do not mix with other methods
+ * that read from <em>ios</em> or you may get unpredictable results.
+ * If the optional <i>outbuf</i> argument is present, it must reference
+ * a String, which will receive the data.
+ * Raises <code>SystemCallError</code> on error and
+ * <code>EOFError</code> at end of file.
+ *
+ * f = File.new("testfile")
+ * f.sysread(16) #=> "This is line one"
+ */
+
+/*
+ * call-seq:
* ios.read([length [, buffer]]) => string, buffer, or nil
*
* Reads at most <i>length</i> bytes from the I/O stream, or to the
@@ -1036,9 +1078,9 @@
if (NIL_P(outbuf)) {
outbuf = rb_bytestring_new();
- } else {
- // TODO: Promote outbuf to a ByteString
- abort();
+ } else if(CLASS_OF(outbuf) != rb_cByteString) {
+ // TODO: Get the magical pointer incantations right.
+ rb_raise(rb_eIOError, "writing to non-bytestrings is not supported at this time.");
}
if(NIL_P(len)) {
@@ -1750,66 +1792,6 @@
return rb_io_gets_m(io, 0, 0, NULL);
}
-/*
- * call-seq:
- * ios.sysseek(offset, whence=SEEK_SET) => integer
- *
- * Seeks to a given <i>offset</i> in the stream according to the value
- * of <i>whence</i> (see <code>IO#seek</code> for values of
- * <i>whence</i>). Returns the new offset into the file.
- *
- * f = File.new("testfile")
- * f.sysseek(-13, IO::SEEK_END) #=> 53
- * f.sysread(10) #=> "And so on."
- */
-
-static VALUE
-rb_io_sysseek(VALUE io, SEL sel, int argc, VALUE *argv)
-{
-rb_notimplement();
-}
-
-/*
- * call-seq:
- * ios.syswrite(string) => integer
- *
- * Writes the given string to <em>ios</em> using a low-level write.
- * Returns the number of bytes written. Do not mix with other methods
- * that write to <em>ios</em> or you may get unpredictable results.
- * Raises <code>SystemCallError</code> on error.
- *
- * f = File.new("out", "w")
- * f.syswrite("ABCDEF") #=> 6
- */
-
-static VALUE
-rb_io_syswrite(VALUE io, SEL sel, VALUE str)
-{
-rb_notimplement();
-}
-
-/*
- * call-seq:
- * ios.sysread(integer[, outbuf]) => string
- *
- * Reads <i>integer</i> bytes from <em>ios</em> using a low-level
- * read and returns them as a string. Do not mix with other methods
- * that read from <em>ios</em> or you may get unpredictable results.
- * If the optional <i>outbuf</i> argument is present, it must reference
- * a String, which will receive the data.
- * Raises <code>SystemCallError</code> on error and
- * <code>EOFError</code> at end of file.
- *
- * f = File.new("testfile")
- * f.sysread(16) #=> "This is line one"
- */
-
-static VALUE
-rb_io_sysread(VALUE io, SEL sel, int argc, VALUE *argv)
-{
-rb_notimplement();
-}
-
VALUE
rb_io_binmode(VALUE io, SEL sel)
{
@@ -3907,8 +3889,8 @@
rb_objc_define_method(rb_cIO, "bytes", rb_io_bytes, 0);
rb_objc_define_method(rb_cIO, "chars", rb_io_chars, 0);
- rb_objc_define_method(rb_cIO, "syswrite", rb_io_syswrite, 1);
- rb_objc_define_method(rb_cIO, "sysread", rb_io_sysread, -1);
+ rb_objc_define_method(rb_cIO, "syswrite", io_write, 1);
+ rb_objc_define_method(rb_cIO, "sysread", io_read, -1);
rb_objc_define_method(rb_cIO, "fileno", rb_io_fileno, 0);
rb_define_alias(rb_cIO, "to_i", "fileno");
@@ -3959,7 +3941,7 @@
rb_objc_define_method(rb_cIO, "isatty", rb_io_isatty, 0);
rb_objc_define_method(rb_cIO, "tty?", rb_io_isatty, 0);
rb_objc_define_method(rb_cIO, "binmode", rb_io_binmode_m, 0);
- rb_objc_define_method(rb_cIO, "sysseek", rb_io_sysseek, -1);
+ rb_objc_define_method(rb_cIO, "sysseek", rb_io_seek, -1);
rb_objc_define_method(rb_cIO, "ioctl", rb_io_ioctl, -1);
rb_objc_define_method(rb_cIO, "fcntl", rb_io_fcntl, -1);
Modified: MacRuby/branches/experimental/rakelib/spec.rake
===================================================================
--- MacRuby/branches/experimental/rakelib/spec.rake 2009-04-04 23:54:43 UTC (rev 1359)
+++ MacRuby/branches/experimental/rakelib/spec.rake 2009-04-05 00:01:59 UTC (rev 1360)
@@ -38,6 +38,7 @@
putc
readchar
sync
+ syswrite
to_i
to_io
initialize
Modified: MacRuby/branches/experimental/spec/frozen/core/io/shared/write.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/io/shared/write.rb 2009-04-04 23:54:43 UTC (rev 1359)
+++ MacRuby/branches/experimental/spec/frozen/core/io/shared/write.rb 2009-04-05 00:01:59 UTC (rev 1360)
@@ -1,6 +1,6 @@
require File.dirname(__FILE__) + '/../fixtures/classes'
-describe :io_write, :shared => true do
+describe(:io_write, {:shared => true}) do
before :each do
@filename = tmp("IO_syswrite_file") + $$.to_s
File.open(@filename, "w") do |file|
Modified: MacRuby/branches/experimental/string.c
===================================================================
--- MacRuby/branches/experimental/string.c 2009-04-04 23:54:43 UTC (rev 1359)
+++ MacRuby/branches/experimental/string.c 2009-04-05 00:01:59 UTC (rev 1360)
@@ -5285,6 +5285,7 @@
static void inline
rb_bytestring_copy_cfstring_content(VALUE bstr, CFStringRef str)
{
+ if (CFStringGetLength(str) == 0) return;
const char *cptr = CFStringGetCStringPtr(str, kCFStringEncodingUTF8);
assert(cptr != NULL); // TODO handle UTF-16 strings
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090404/70e727c9/attachment-0001.html>
More information about the macruby-changes
mailing list