Project

General

Profile

Backport #5704 » commitlog.txt

h.shirosaki (Hiroshi Shirosaki), 02/04/2012 08:52 PM

 
merge revision(s) 33200,33662,33666,33770,33937,33944,33946,33981,34043,
34045,34132:

* io.c (rb_sys_fail_path): move the definition.
Move above for using it in set_binary_mode_with_seek_cur().

* io.c (set_binary_mode_with_seek_cur): fix improper seek cursor.
Seeking file cursor with setting binary mode has possibility to
cause infinite loop. Fixed the bug and refined error handling.,
Introduced at r34043.

And cleanups as below.
Remove unnecessary parentheses of `fptr`.
Use return value of setmode().

* test/ruby/test_io_m17n.rb
(TestIO_M17N#test_seek_with_setting_binmode): add a test for above.
[ruby-core:41671] [Bug #5714]

* test/ruby/test_io_m17n.rb
(TestIO_M17N#test_{read_with_binmode_and_get[cs]}): only for Windows.

* win32/win32.c, include/ruby/win32.h (rb_w32_fd_is_text): new function.

* win32/win32.c (init_stdhandle): set default mode of stdin as binmode.

* io.c (set_binary_mode_with_seek_cur): new function to replace
SET_BINARY_MODE_WITH_SEEK_CUR macro. now returns previous mode of the
fd and take care of LF in rbuf.

* io.c (do_writeconv): set text mode when needed.

* io.c (io_read): need to change the mode of the IO to binmode
temporally when the length for IO#read, because IO#read with length
must behave so.

* test/ruby/test_io_m17n.rb (TestIO_M17N#test_{read_with_length,
read_with_length_binmode,get[cs]_and_read_with_binmode,
read_with_binmode_and_get[cs],read_write_with_binmode}): tests for
above changes.

all patches are written by Hiroshi Shirosaki. [ruby-core:41496]
[Feature #5714]

* test/rexml/test_order.rb (OrderTester#test_more_ordering): use
GZip::GzReader.open instead of GZip::GzReader.new with File.new.
fixed a test error on Windows introduced at r33946.

* ext/zlib/zlib.c (rb_gzreader_initialize): revert a part of r33937.
1st, to change the mode of an IO is very sensitive problem, so
the maintainer of this library should judge it.
2nd, usually Zlib::GzReader.new is not called directly. #initialize
is called via .open, and in the method the I/O is opened in binary
mode, so there is no problem without changing the mode in #initialize.

* ext/zlib/zlib.c (rb_gzreader_initialize): use binary mode by default
under Windows. Patch by Hiroshi Shirosaki. [ruby-core:40706]
[Feature #5562]

* include/ruby/encoding.h (void rb_econv_binmode): define NEWLINE
decorator.

* io.c (rb_cloexec_fcntl_dupfd): Introduce NEED_READCONV and
NEED_WRITECONV to replace universal newline decorator by CRLF only
when required to improve file reading and writing under Windows.
Patch by Hiroshi Shirosaki. [ruby-core:40706] [Feature #5562]
* io.c (do_writeconv): adjust binary mode if required.
* io.c (read_all, appendline, swallow, rb_io_getline_1): ditto.
* io.c (io_getc, rb_io_each_codepoint, rb_io_ungetc): ditto.
* io.c (rb_io_binmode, rb_io_ascii8bit_binmode): ditto.
* io.c (rb_io_extract_modeenc, rb_sysopen): ditto.
* io.c (pipe_open, prep_stdio, io_encoding_set): ditto.
* io.c (rb_io_s_pipe, copy_stream_body): ditto.

* test/ruby/test_io_m17n.rb (EOT): add test for pipe and stdin in
binary mode.

* win32/win32.c (init_stdhandle): remove O_BINARY from stdhandle
initialization.
* win32/win32.c (rb_w32_write): use FTEXT mode accordingly.

* io.c (argf_next_argv): wrong timing of setting ecflags.
fixed the failure of TestArgf#test_textmode introduced at r33662.

* include/ruby/encoding.h (ECONV_NEWLINE_DECORATOR_READ_MASK,
ECONV_NEWLINE_DECORATOR_WRITE_MASK): new macro.

* io.c (rb_io_extract_modeenc, pipe_open, prep_stdio, argf_next_argv):
set TEXTMODE_NEWLINE_DECORATOR_ON_WRITE for textmode on creating IO
if the flag is available.

* io.c (make_writeconv): drop decorators for reading.

* io.c (make_readconv): drop decorators for writing.

* io.c (do_writeconv): existing writeconv is not the condition to raise
ArgumentError. should check textmode or not.

* test/ruby/test_io_m17n.rb
(TestIO_M17N#test_{cr,lf,crlf}_decorator_on_stdout): test above
changes.

* transcode.c: enabled econv newline option.
(1-1/2)