[macruby-changes] [1618] MacRuby/branches/experimental
source_changes at macosforge.org
source_changes at macosforge.org
Wed May 27 16:19:43 PDT 2009
Revision: 1618
http://trac.macosforge.org/projects/ruby/changeset/1618
Author: pthomson at apple.com
Date: 2009-05-27 16:19:43 -0700 (Wed, 27 May 2009)
Log Message:
-----------
Added syscall() and got the IO#write spec working.
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/spec/frozen/core/io/write_spec.rb
Modified: MacRuby/branches/experimental/io.c
===================================================================
--- MacRuby/branches/experimental/io.c 2009-05-27 21:28:05 UTC (rev 1617)
+++ MacRuby/branches/experimental/io.c 2009-05-27 23:19:43 UTC (rev 1618)
@@ -396,7 +396,6 @@
rb_secure(4);
io_struct = ExtractIOStruct(io);
- rb_io_assert_writable(io_struct);
to_write = rb_obj_as_string(to_write);
@@ -428,7 +427,8 @@
if (length == 0) {
return INT2FIX(0);
}
-
+
+ rb_io_assert_writable(io_struct);
return LONG2FIX(CFWriteStreamWrite(io_struct->writeStream, buffer, length));
}
@@ -3147,7 +3147,64 @@
static VALUE
rb_f_syscall(VALUE recv, SEL sel, int argc, VALUE *argv)
{
- rb_notimplement();
+ unsigned long arg[8];
+
+ int ii = 1;
+ int retval = -1;
+ int items = argc - 1;
+
+ rb_secure(2);
+ if (argc == 0)
+ rb_raise(rb_eArgError, "too few arguments to syscall()");
+ if (argc > 9)
+ rb_raise(rb_eArgError, "too many arguments to syscall()");
+
+
+ arg[0] = NUM2LONG(argv[0]); argv++;
+
+ while (items--) {
+ VALUE v = rb_check_string_type(*argv);
+ if (!NIL_P(v)) {
+ StringValue(v);
+ arg[ii] = (unsigned long)StringValueCStr(v);
+ } else {
+ arg[ii] = (unsigned long)NUM2LONG(*argv);
+ }
+ argv++;
+ ii++;
+ }
+
+
+ switch (argc) {
+ case 1:
+ retval = syscall(arg[0]);
+ break;
+ case 2:
+ retval = syscall(arg[0],arg[1]);
+ break;
+ case 3:
+ retval = syscall(arg[0],arg[1],arg[2]);
+ break;
+ case 4:
+ retval = syscall(arg[0],arg[1],arg[2],arg[3]);
+ break;
+ case 5:
+ retval = syscall(arg[0],arg[1],arg[2],arg[3],arg[4]);
+ break;
+ case 6:
+ retval = syscall(arg[0],arg[1],arg[2],arg[3],arg[4],arg[5]);
+ break;
+ case 7:
+ retval = syscall(arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6]);
+ break;
+ case 8:
+ retval = syscall(arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
+ arg[7]);
+ break;
+ }
+
+ if (retval < 0) rb_sys_fail("call to syscall() failed.");
+ return INT2NUM(retval);
}
/*
* call-seq:
@@ -3201,8 +3258,7 @@
static VALUE
rb_io_s_pipe(VALUE recv, SEL sel, int argc, VALUE *argv)
{
- VALUE ext_enc = Qnil, int_enc = Qnil;
- VALUE rd, wr;
+ VALUE rd, wr, ext_enc = Qnil, int_enc = Qnil;
rb_scan_args(argc, argv, "02", &ext_enc, &int_enc);
int fd[2] = {-1, -1};
Modified: MacRuby/branches/experimental/rakelib/spec.rake
===================================================================
--- MacRuby/branches/experimental/rakelib/spec.rake 2009-05-27 21:28:05 UTC (rev 1617)
+++ MacRuby/branches/experimental/rakelib/spec.rake 2009-05-27 23:19:43 UTC (rev 1618)
@@ -48,6 +48,7 @@
tell
to_i
to_io
+ write
initialize
}
Modified: MacRuby/branches/experimental/spec/frozen/core/io/shared/write.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/io/shared/write.rb 2009-05-27 21:28:05 UTC (rev 1617)
+++ MacRuby/branches/experimental/spec/frozen/core/io/shared/write.rb 2009-05-27 23:19:43 UTC (rev 1618)
@@ -35,7 +35,7 @@
(obj = mock(data)).should_receive(:to_s).and_return(data)
@file.send(@method, obj)
@file.seek(0)
- @file.read(data.length).should == data
+ @file.read(data.size).should == data
end
it "writes all of the string's bytes without buffering if mode is sync" do
Modified: MacRuby/branches/experimental/spec/frozen/core/io/write_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/io/write_spec.rb 2009-05-27 21:28:05 UTC (rev 1617)
+++ MacRuby/branches/experimental/spec/frozen/core/io/write_spec.rb 2009-05-27 23:19:43 UTC (rev 1618)
@@ -11,25 +11,28 @@
@file = File.open(@filename, "r+")
@readonly_file = File.open(@filename)
end
-
+
after :each do
@file.close
@readonly_file.close
File.delete(@filename)
end
-
+
# TODO: impl detail? discuss this with matz. This spec is useless. - rdavis
- it "writes all of the string's bytes but buffers them" do
- written = @file.write("abcde")
- written.should == 5
- File.open(@filename) do |file|
- file.read.should == "012345678901234567890123456789"
- @file.fsync
- file.rewind
- file.read.should == "abcde5678901234567890123456789"
+ # I agree. I've marked it not compliant on macruby, as we don't buffer input. -pthomson
+ not_compliant_on :macruby do
+ it "writes all of the string's bytes but buffers them" do
+ written = @file.write("abcde")
+ written.should == 5
+ File.open(@filename) do |file|
+ file.read.should == "012345678901234567890123456789"
+ @file.fsync
+ file.rewind
+ file.read.should == "abcde5678901234567890123456789"
+ end
end
end
-
+
it "does not check if the file is writable if writing zero bytes" do
lambda { @readonly_file.write("") }.should_not raise_error
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090527/9b1abc72/attachment-0001.html>
More information about the macruby-changes
mailing list