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

ruby-changes:7967

From: akr <ko1@a...>
Date: Tue, 23 Sep 2008 20:56:00 +0900 (JST)
Subject: [ruby-changes:7967] Ruby:r19489 (trunk): * io.c (io_binwrite): add nosync argument.

akr	2008-09-23 20:55:48 +0900 (Tue, 23 Sep 2008)

  New Revision: 19489

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

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/io.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 19488)
+++ ChangeLog	(revision 19489)
@@ -1,3 +1,12 @@
+Tue Sep 23 20:52:25 2008  Tanaka Akira  <akr@f...>
+
+	* 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.
+
 Tue Sep 23 20:24:41 2008  Koichi Sasada  <ko1@a...>
 
 	* signal.c (signal_exec): fix to use rb_proc_call().
Index: io.c
===================================================================
--- io.c	(revision 19488)
+++ io.c	(revision 19489)
@@ -745,7 +745,7 @@
 /* writing functions */
 
 static long
-io_binwrite(VALUE str, rb_io_t *fptr)
+io_binwrite(VALUE str, rb_io_t *fptr, int nosync)
 {
     long len, n, r, l, offset = 0;
 
@@ -757,7 +757,7 @@
         fptr->wbuf_capa = 8192;
         fptr->wbuf = ALLOC_N(char, fptr->wbuf_capa);
     }
-    if ((fptr->mode & (FMODE_SYNC|FMODE_TTY)) ||
+    if ((!nosync && (fptr->mode & (FMODE_SYNC|FMODE_TTY))) ||
         (fptr->wbuf && fptr->wbuf_capa <= fptr->wbuf_len + len)) {
         /* xxx: use writev to avoid double write if available */
         if (fptr->wbuf_len && fptr->wbuf_len+len <= fptr->wbuf_capa) {
@@ -811,8 +811,8 @@
     return len;
 }
 
-static long
-io_fwrite(VALUE str, rb_io_t *fptr)
+static VALUE
+do_writeconv(VALUE str, rb_io_t *fptr)
 {
     if (NEED_WRITECONV(fptr)) {
         VALUE common_encoding = Qnil;
@@ -842,8 +842,14 @@
             str = rb_econv_str_convert(fptr->writeconv, str, ECONV_PARTIAL_INPUT);
         }
     }
+    return str;
+}
 
-    return io_binwrite(str, fptr);
+static long
+io_fwrite(VALUE str, rb_io_t *fptr, int nosync)
+{
+    str = do_writeconv(str, fptr);
+    return io_binwrite(str, fptr, nosync);
 }
 
 long
@@ -855,29 +861,11 @@
     of.stdio_file = f;
     of.mode = FMODE_WRITABLE;
     of.pathv = Qnil;
-    return io_fwrite(rb_str_new(ptr, len), &of);
+    return io_fwrite(rb_str_new(ptr, len), &of, 0);
 }
 
-/*
- *  call-seq:
- *     ios.write(string)    => integer
- *
- *  Writes the given string to <em>ios</em>. The stream must be opened
- *  for writing. If the argument is not a string, it will be converted
- *  to a string using <code>to_s</code>. Returns the number of bytes
- *  written.
- *
- *     count = $stdout.write( "This is a test\n" )
- *     puts "That was #{count} bytes of data"
- *
- *  <em>produces:</em>
- *
- *     This is a test
- *     That was 15 bytes of data
- */
-
 static VALUE
-io_write(VALUE io, VALUE str)
+io_write(VALUE io, VALUE str, int nosync)
 {
     rb_io_t *fptr;
     long n;
@@ -897,12 +885,36 @@
     GetOpenFile(io, fptr);
     rb_io_check_writable(fptr);
 
-    n = io_fwrite(str, fptr);
+    n = io_fwrite(str, fptr, nosync);
     if (n == -1L) rb_sys_fail_path(fptr->pathv);
 
     return LONG2FIX(n);
 }
 
+/*
+ *  call-seq:
+ *     ios.write(string)    => integer
+ *
+ *  Writes the given string to <em>ios</em>. The stream must be opened
+ *  for writing. If the argument is not a string, it will be converted
+ *  to a string using <code>to_s</code>. Returns the number of bytes
+ *  written.
+ *
+ *     count = $stdout.write( "This is a test\n" )
+ *     puts "That was #{count} bytes of data"
+ *
+ *  <em>produces:</em>
+ *
+ *     This is a test
+ *     That was 15 bytes of data
+ */
+
+static VALUE
+io_write_m(VALUE io, VALUE str)
+{
+    return io_write(io, str, 0);
+}
+
 VALUE
 rb_io_write(VALUE io, VALUE str)
 {
@@ -5417,8 +5429,15 @@
 rb_p(VALUE obj) /* for debug print within C code */
 {
     VALUE str = rb_obj_as_string(rb_inspect(obj));
-    rb_str_buf_append(str, rb_default_rs);
-    rb_io_write(rb_stdout, str);
+    if (TYPE(rb_stdout) == T_FILE &&
+        rb_method_basic_definition_p(CLASS_OF(rb_stdout), id_write)) {
+        io_write(rb_stdout, str, 1);
+        io_write(rb_stdout, rb_default_rs, 0);
+    }
+    else {
+        rb_io_write(rb_stdout, str);
+        rb_io_write(rb_stdout, rb_default_rs);
+    }
 }
 
 /*
@@ -7445,7 +7464,7 @@
         rb_str_resize(str,len);
         read_buffered_data(RSTRING_PTR(str), len, src_fptr);
         if (dst_fptr) /* IO or filename */
-            io_fwrite(str, dst_fptr);
+            io_fwrite(str, dst_fptr, 0);
         else /* others such as StringIO */
             rb_io_write(stp->dst, str);
         stp->total += len;
@@ -8273,7 +8292,7 @@
     rb_define_method(rb_cIO, "write_nonblock", rb_io_write_nonblock, 1);
     rb_define_method(rb_cIO, "readpartial",  io_readpartial, -1);
     rb_define_method(rb_cIO, "read",  io_read, -1);
-    rb_define_method(rb_cIO, "write", io_write, 1);
+    rb_define_method(rb_cIO, "write", io_write_m, 1);
     rb_define_method(rb_cIO, "gets",  rb_io_gets_m, -1);
     rb_define_method(rb_cIO, "readline",  rb_io_readline, -1);
     rb_define_method(rb_cIO, "getc",  rb_io_getc, 0);

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

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