[前][次][番号順一覧][スレッド一覧]

ruby-changes:30485

From: usa <ko1@a...>
Date: Thu, 15 Aug 2013 20:53:47 +0900 (JST)
Subject: [ruby-changes:30485] usa:r42564 (trunk): * io.c, internal.h (rb_io_flush_raw): new function to select calling

usa	2013-08-15 20:53:41 +0900 (Thu, 15 Aug 2013)

  New Revision: 42564

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42564

  Log:
    * io.c, internal.h (rb_io_flush_raw): new function to select calling
      fsync() (on Windows).
    
    * io.c (rb_io_flush_raw): use above function.
    
    * file.c (rb_file_truncate): use above function.

  Modified files:
    trunk/ChangeLog
    trunk/file.c
    trunk/internal.h
    trunk/io.c
    trunk/test/test_pstore.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42563)
+++ ChangeLog	(revision 42564)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Aug 15 20:51:29 2013  NAKAMURA Usaku  <usa@r...>
+
+	* io.c, internal.h (rb_io_flush_raw): new function to select calling
+	  fsync() (on Windows).
+
+	* io.c (rb_io_flush_raw): use above function.
+
+	* file.c (rb_file_truncate): use above function.
+
 Thu Aug 15 18:39:31 2013  NAKAMURA Usaku  <usa@r...>
 
 	* win32/win32.c (clock_gettime): improve precision when freq is less
Index: io.c
===================================================================
--- io.c	(revision 42563)
+++ io.c	(revision 42564)
@@ -1464,24 +1464,8 @@ nogvl_fsync(void *ptr) https://github.com/ruby/ruby/blob/trunk/io.c#L1464
 }
 #endif
 
-/*
- *  call-seq:
- *     ios.flush    -> ios
- *
- *  Flushes any buffered data within <em>ios</em> to the underlying
- *  operating system (note that this is Ruby internal buffering only;
- *  the OS may buffer the data as well).
- *
- *     $stdout.print "no newline"
- *     $stdout.flush
- *
- *  <em>produces:</em>
- *
- *     no newline
- */
-
 VALUE
-rb_io_flush(VALUE io)
+rb_io_flush_raw(VALUE io, int sync)
 {
     rb_io_t *fptr;
 
@@ -1496,7 +1480,7 @@ rb_io_flush(VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L1480
         if (io_fflush(fptr) < 0)
             rb_sys_fail(0);
 #ifdef _WIN32
-	if (GetFileType((HANDLE)rb_w32_get_osfhandle(fptr->fd)) == FILE_TYPE_DISK) {
+	if (sync && GetFileType((HANDLE)rb_w32_get_osfhandle(fptr->fd)) == FILE_TYPE_DISK) {
 	    rb_thread_io_blocking_region(nogvl_fsync, fptr, fptr->fd);
 	}
 #endif
@@ -1509,6 +1493,28 @@ rb_io_flush(VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L1493
 }
 
 /*
+ *  call-seq:
+ *     ios.flush    -> ios
+ *
+ *  Flushes any buffered data within <em>ios</em> to the underlying
+ *  operating system (note that this is Ruby internal buffering only;
+ *  the OS may buffer the data as well).
+ *
+ *     $stdout.print "no newline"
+ *     $stdout.flush
+ *
+ *  <em>produces:</em>
+ *
+ *     no newline
+ */
+
+VALUE
+rb_io_flush(VALUE io)
+{
+    return rb_io_flush_raw(io, 1);
+}
+
+/*
  *  call-seq:
  *     ios.pos     -> integer
  *     ios.tell    -> integer
Index: internal.h
===================================================================
--- internal.h	(revision 42563)
+++ internal.h	(revision 42564)
@@ -283,6 +283,7 @@ void ruby_set_inplace_mode(const char *) https://github.com/ruby/ruby/blob/trunk/internal.h#L283
 ssize_t rb_io_bufread(VALUE io, void *buf, size_t size);
 void rb_stdio_set_default_encoding(void);
 void rb_write_error_str(VALUE mesg);
+VALUE rb_io_flush_raw(VALUE, int);
 
 /* iseq.c */
 VALUE rb_iseq_clone(VALUE iseqval, VALUE newcbase);
Index: test/test_pstore.rb
===================================================================
--- test/test_pstore.rb	(revision 42563)
+++ test/test_pstore.rb	(revision 42564)
@@ -120,7 +120,7 @@ class PStoreTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/test_pstore.rb#L120
   def test_pstore_files_are_accessed_as_binary_files
     bug5311 = '[ruby-core:39503]'
     n = 128
-    assert_in_out_err(["-Eutf-8:utf-8", "-rpstore", "-", @pstore_file], <<-SRC, [bug5311], [], bug5311, timeout: 60)
+    assert_in_out_err(["-Eutf-8:utf-8", "-rpstore", "-", @pstore_file], <<-SRC, [bug5311], [], bug5311, timeout: 15)
       @pstore = PStore.new(ARGV[0])
       (1..#{n}).each do |i|
         @pstore.transaction {@pstore["Key\#{i}"] = "value \#{i}"}
Index: file.c
===================================================================
--- file.c	(revision 42563)
+++ file.c	(revision 42564)
@@ -4244,7 +4244,11 @@ rb_file_truncate(VALUE obj, VALUE len) https://github.com/ruby/ruby/blob/trunk/file.c#L4244
     if (!(fptr->mode & FMODE_WRITABLE)) {
 	rb_raise(rb_eIOError, "not opened for writing");
     }
+#ifndef _WIN32
     rb_io_flush(obj);
+#else
+    rb_io_flush_raw(obj, 0);
+#endif
 #ifdef HAVE_FTRUNCATE
     if (ftruncate(fptr->fd, pos) < 0)
 	rb_sys_fail_path(fptr->pathv);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]