From d6af2a2b214203da5b4bb8ef592026db3c4c1a40 Mon Sep 17 00:00:00 2001 From: usa Date: Thu, 15 Aug 2013 11:53:41 +0000 Subject: * 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42564 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 9 +++++++++ file.c | 4 ++++ internal.h | 1 + io.c | 42 ++++++++++++++++++++++++------------------ test/test_pstore.rb | 2 +- 5 files changed, 39 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index eb1bdae39a..9310cc975d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Thu Aug 15 20:51:29 2013 NAKAMURA Usaku + + * 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 * win32/win32.c (clock_gettime): improve precision when freq is less diff --git a/file.c b/file.c index 02143a147e..3594bbd431 100644 --- a/file.c +++ b/file.c @@ -4244,7 +4244,11 @@ rb_file_truncate(VALUE obj, VALUE len) 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); diff --git a/internal.h b/internal.h index d52b2e9442..e196b23cd2 100644 --- a/internal.h +++ b/internal.h @@ -283,6 +283,7 @@ void ruby_set_inplace_mode(const char *); 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); diff --git a/io.c b/io.c index 9e3c39ce67..e1f0942d32 100644 --- a/io.c +++ b/io.c @@ -1464,24 +1464,8 @@ nogvl_fsync(void *ptr) } #endif -/* - * call-seq: - * ios.flush -> ios - * - * Flushes any buffered data within ios 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 - * - * produces: - * - * 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) 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 @@ -1508,6 +1492,28 @@ rb_io_flush(VALUE io) return io; } +/* + * call-seq: + * ios.flush -> ios + * + * Flushes any buffered data within ios 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 + * + * produces: + * + * no newline + */ + +VALUE +rb_io_flush(VALUE io) +{ + return rb_io_flush_raw(io, 1); +} + /* * call-seq: * ios.pos -> integer diff --git a/test/test_pstore.rb b/test/test_pstore.rb index aa48c73163..ee662669ff 100644 --- a/test/test_pstore.rb +++ b/test/test_pstore.rb @@ -120,7 +120,7 @@ class PStoreTest < Test::Unit::TestCase 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}"} -- cgit v1.2.3