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

source_changes at macosforge.org source_changes at macosforge.org
Tue Jul 21 15:28:52 PDT 2009


Revision: 2042
          http://trac.macosforge.org/projects/ruby/changeset/2042
Author:   pthomson at apple.com
Date:     2009-07-21 15:28:51 -0700 (Tue, 21 Jul 2009)
Log Message:
-----------
Re-enabled File#truncate and made sure it passes its specs.

Modified Paths:
--------------
    MacRuby/branches/experimental/file.c
    MacRuby/branches/experimental/include/ruby/io.h
    MacRuby/branches/experimental/io.c

Removed Paths:
-------------
    MacRuby/branches/experimental/spec/frozen/tags/macruby/core/file/truncate_tags.txt

Modified: MacRuby/branches/experimental/file.c
===================================================================
--- MacRuby/branches/experimental/file.c	2009-07-21 22:13:52 UTC (rev 2041)
+++ MacRuby/branches/experimental/file.c	2009-07-21 22:28:51 UTC (rev 2042)
@@ -2752,29 +2752,15 @@
 static VALUE
 rb_file_truncate(VALUE obj, SEL sel, VALUE len)
 {
-//     rb_io_t *fptr;
-//     off_t pos;
-// 
-//     rb_secure(2);
-//     pos = NUM2OFFT(len);
-//     GetOpenFile(obj, fptr);
-//     if (!(fptr->mode & FMODE_WRITABLE)) {
-//  rb_raise(rb_eIOError, "not opened for writing");
-//     }
-//     rb_io_flush(obj);
-// #ifdef HAVE_FTRUNCATE
-//     if (ftruncate(fptr->fd, pos) < 0)
-//  rb_sys_fail(fptr->path);
-// #else
-// # ifdef HAVE_CHSIZE
-//     if (chsize(fptr->fd, pos) < 0)
-//  rb_sys_fail(fptr->path);
-// # else
-//     rb_notimplement();
-// # endif
-// #endif
-//     return INT2FIX(0);
-    rb_notimplement();
+	rb_secure(2);
+	rb_io_t *io = ExtractIOStruct(obj);
+	off_t pos = NUM2OFFT(len);
+	rb_io_assert_writable(io);
+	if (ftruncate(io->fd, pos) < 0)
+	{
+		rb_sys_fail(RSTRING_PTR(io->path));
+	}
+	return INT2FIX(0);
 }
 
 # ifndef LOCK_SH

Modified: MacRuby/branches/experimental/include/ruby/io.h
===================================================================
--- MacRuby/branches/experimental/include/ruby/io.h	2009-07-21 22:13:52 UTC (rev 2041)
+++ MacRuby/branches/experimental/include/ruby/io.h	2009-07-21 22:28:51 UTC (rev 2042)
@@ -76,7 +76,9 @@
 VALUE rb_io_taint_check(VALUE);
 NORETURN(void rb_eof_error(void));
 
+void rb_io_assert_writable(rb_io_t *io);
 
+
 #if defined(__cplusplus)
 #if 0
 { /* satisfy cc-mode */

Modified: MacRuby/branches/experimental/io.c
===================================================================
--- MacRuby/branches/experimental/io.c	2009-07-21 22:13:52 UTC (rev 2041)
+++ MacRuby/branches/experimental/io.c	2009-07-21 22:28:51 UTC (rev 2042)
@@ -222,7 +222,7 @@
     }
 }
 
-static void 
+void 
 rb_io_assert_writable(rb_io_t *io_struct)
 {
     rb_io_assert_initialized(io_struct);

Deleted: MacRuby/branches/experimental/spec/frozen/tags/macruby/core/file/truncate_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/macruby/core/file/truncate_tags.txt	2009-07-21 22:13:52 UTC (rev 2041)
+++ MacRuby/branches/experimental/spec/frozen/tags/macruby/core/file/truncate_tags.txt	2009-07-21 22:28:51 UTC (rev 2042)
@@ -1,9 +0,0 @@
-fails:File#truncate truncates a file
-fails:File#truncate truncates a file size to 0
-fails:File#truncate truncates a file size to 5
-fails:File#truncate truncates a file to a larger size than the original file
-fails:File#truncate truncates a file to the same size as the original file
-fails:File#truncate raises an Errno::EINVAL if the length argument is not valid
-fails:File#truncate raises an IOError if file is closed
-fails:File#truncate raises an IOError if file is not opened for writing
-fails:File#truncate raises a TypeError if not passed an Integer type for the for the argument
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090721/e624a566/attachment-0001.html>


More information about the macruby-changes mailing list