diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-08-15 11:53:41 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-08-15 11:53:41 +0000 |
commit | d6af2a2b214203da5b4bb8ef592026db3c4c1a40 (patch) | |
tree | b715d017ae6f8e479678fc4a7dc35ef5e79d9615 | |
parent | 12a0b0c8f48f168994245198e62d1d40cab5d594 (diff) | |
download | ruby-d6af2a2b214203da5b4bb8ef592026db3c4c1a40.tar.gz |
* 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
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | file.c | 4 | ||||
-rw-r--r-- | internal.h | 1 | ||||
-rw-r--r-- | io.c | 42 | ||||
-rw-r--r-- | test/test_pstore.rb | 2 |
5 files changed, 39 insertions, 19 deletions
@@ -1,3 +1,12 @@ +Thu Aug 15 20:51:29 2013 NAKAMURA Usaku <usa@ruby-lang.org> + + * 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@ruby-lang.org> * win32/win32.c (clock_gettime): improve precision when freq is less @@ -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); @@ -1464,24 +1464,8 @@ nogvl_fsync(void *ptr) } #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) 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 @@ -1510,6 +1494,28 @@ rb_io_flush(VALUE io) /* * 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 * 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}"} |