8000 * io.c (io_binwrite): add nosync argument. · documenting-ruby/ruby@55783c6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 55783c6

Browse files
committed
* io.c (io_binwrite): add nosync argument.
(do_writeconv): extracted from io_fwrite. (io_fwrite): add nosync argument. use do_writeconv. (io_write): add nosync argument. (io_write_m): new function for IO#write. (rb_p): don't append record separator. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19489 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 445e26f commit 55783c6

File tree

2 files changed

+58
-30
lines changed

2 files changed

+58
-30
lines changed

ChangeLog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
Tue Sep 23 20:52:25 2008 Tanaka Akira <akr@fsij.org>
2+
3+
* io.c (io_binwrite): add nosync argument.
4+
(do_writeconv): extracted from io_fwrite.
5+
(io_fwrite): add nosync argument. use do_writeconv.
6+
(io_write): add nosync argument.
7+
(io_write_m): new function for IO#write.
8+
(rb_p): don't append record separator.
9+
110
Tue Sep 23 20:24:41 2008 Koichi Sasada <ko1@atdot.net>
211

312
* signal.c (signal_exec): fix to use rb_proc_call().

io.c

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ make_writeconv(rb_io_t *fptr)
745745
/* writing functions */
746746

747747
static long
748-
io_binwrite(VALUE str, rb_io_t *fptr)
748+
io_binwrite(VALUE str, rb_io_t *fptr, int nosync)
749749
{
750750
long len, n, r, l, offset = 0;
751751

@@ -757,7 +757,7 @@ io_binwrite(VALUE str, rb_io_t *fptr)
757757
fptr->wbuf_capa = 8192;
758758
fptr->wbuf = ALLOC_N(char, fptr->wbuf_capa);
759759
}
760-
if ((fptr->mode & (FMODE_SYNC|FMODE_TTY)) ||
760+
if ((!nosync && (fptr->mode & (FMODE_SYNC|FMODE_TTY))) ||
761761
(fptr->wbuf && fptr->wbuf_capa <= fptr->wbuf_len + len)) {
762762
/* xxx: use writev to avoid double write if available */
763763
if (fptr->wbuf_len && fptr->wbuf_len+len <= fptr->wbuf_capa) {
@@ -811,8 +811,8 @@ io_binwrite(VALUE str, rb_io_t *fptr)
811811
return len;
812812
}
813813

814-
static long
815-
io_fwrite(VALUE str, rb_io_t *fptr)
814+
static VALUE
815+
do_writeconv(VALUE str, rb_io_t *fptr)
816816
{
817817
if (NEED_WRITECONV(fptr)) {
818818
VALUE common_encoding = Qnil;
@@ -842,8 +842,14 @@ io_fwrite(VALUE str, rb_io_t *fptr)
842842
str = rb_econv_str_convert(fptr->writeconv, str, ECONV_PARTIAL_INPUT);
843843
}
844844
}
845+
return str;
846+
}
845847

846-
return io_binwrite(str, fptr);
848+
static long
849+
io_fwrite(VALUE str, rb_io_t *fptr, int nosync)
850+
{
851+
str = do_writeconv(str, fptr);
852+
return io_binwrite(str, fptr, nosync);
847853
}
848854

849855
long
@@ -855,29 +861,11 @@ rb_io_fwrite(const char *ptr, long len, FILE *f)
855861
of.stdio_file = f;
856862
of.mode = FMODE_WRITABLE;
857863
of.pathv = Qnil;
858-
return io_fwrite(rb_str_new(ptr, len), &of);
864+
return io_fwrite(rb_str_new(ptr, len), &of, 0);
859865
}
860866

861-
/*
862-
* call-seq:
863-
* ios.write(string) => integer
864-
*
865-
* Writes the given string to <em>ios</em>. The stream must be opened
866-
* for writing. If the argument is not a string, it will be converted
867-
* to a string using <code>to_s</code>. Returns the number of bytes
868-
* written.
869-
*
870-
* count = $stdout.write( "This is a test\n" )
871-
* puts "That was #{count} bytes of data"
872-
*
873-
* <em>produces:</em>
874-
*
875-
* This is a test
876-
* That was 15 bytes of data
877-
*/
878-
879867
static VALUE
880-
io_write(VALUE io, VALUE str)
868+
io_write(VALUE io, VALUE str, int nosync)
881869
{
882870
rb_io_t *fptr;
883871
long n;
@@ -897,12 +885,36 @@ io_write(VALUE io, VALUE str)
897885
GetOpenFile(io, fptr);
898886
rb_io_check_writable(fptr);
899887

900-
n = io_fwrite(str, fptr);
888+
n = io_fwrite(str, fptr, nosync);
901889
if (n == -1L) rb_sys_fail_path(fptr->pathv);
902890

903891
return LONG2FIX(n);
904892
}
905893

894+
/*
895+
* call-seq:
896+
* ios.write(string) => integer
897+
*
898+
* Writes the given string to <em>ios</em>. The stream must be opened
899+
* for writing. If the argument is not a string, it will be converted
900+
* to a string using <code>to_s</code>. Returns the number of bytes
901+
* written.
902+
*
903+
* count = $stdout.write( "This is a test\n" )
904+
* puts "That was #{count} bytes of data"
905+
*
906+
* <em>produces:</em>
907+
*
908+
* This is a test
909+
* That was 15 bytes of data
910+
*/
911+
912+
static VALUE
913+
io_write_m(VALUE io, VALUE str)
914+
{
915+
return io_write(io, str, 0);
916+
}
917+
906918
VALUE
907919
rb_io_write(VALUE io, VALUE str)
908920
{
@@ -5417,8 +5429,15 @@ void
54175429
rb_p(VALUE obj) /* for debug print within C code */
54185430
{
54195431
VALUE str = rb_obj_as_string(rb_inspect(obj));
5420-
rb_str_buf_append(str, rb_default_rs);
5421-
rb_io_write(rb_stdout, str);
5432+
if (TYPE(rb_stdout) == T_FILE &&
5433+
rb_method_basic_definition_p(CLASS_OF(rb_stdout), id_write)) {
5434+
io_write(rb_stdout, str, 1);
5435+
io_write(rb_stdout, rb_default_rs, 0);
5436+
}
5437+
else {
5438+
rb_io_write(rb_stdout, str);
5439+
rb_io_write(rb_stdout, rb_default_rs);
5440+
}
54225441
}
54235442

54245443
/*
@@ -7445,7 +7464,7 @@ copy_stream_body(VALUE arg)
74457464
rb_str_resize(str,len);
74467465
read_buffered_data(RSTRING_PTR(str), len, src_fptr);
74477466
if (dst_fptr) /* IO or filename */
7448-
io_fwrite(str, dst_fptr);
7467+
io_fwrite(str, dst_fptr, 0);
74497468
else /* others such as StringIO */
74507469
rb_io_write(stp->dst, str);
74517470
stp->total += len;
@@ -8273,7 +8292,7 @@ Init_IO(void)
82738292
rb_define_method(rb_cIO, "write_nonblock", rb_io_write_nonblock, 1);
82748293
rb_define_method(rb_cIO, "readpartial", io_readpartial, -1);
82758294
rb_define_method(rb_cIO, "read", io_read, -1);
8276-
rb_define_method(rb_cIO, "write", io_write, 1);
8295+
rb_define_method(rb_cIO, "write", io_write_m, 1);
82778296
rb_define_method(rb_cIO, "gets", rb_io_gets_m, -1);
82788297
rb_define_method(rb_cIO, "readline", rb_io_readline, -1);
82798298
rb_define_method(rb_cIO, "getc", rb_io_getc, 0);

0 commit comments

Comments
 (0)
0