ruby-changes:48264
From: nobu <ko1@a...>
Date: Mon, 23 Oct 2017 16:06:18 +0900 (JST)
Subject: [ruby-changes:48264] nobu:r60379 (trunk): zlib.c: multiple arguments to write
nobu 2017-10-23 16:06:12 +0900 (Mon, 23 Oct 2017) New Revision: 60379 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60379 Log: zlib.c: multiple arguments to write * ext/zlib/zlib.c (rb_gzwriter_write): accepts multiple arguments. Modified files: trunk/NEWS trunk/ext/zlib/zlib.c trunk/test/zlib/test_zlib.rb Index: NEWS =================================================================== --- NEWS (revision 60378) +++ NEWS (revision 60379) @@ -211,6 +211,9 @@ with all sufficient information, see the https://github.com/ruby/ruby/blob/trunk/NEWS#L211 * Add Server Name Indication (SNI) support [Feature #13729] +* Zlilb + * Zlib::GzipWriter#write accepts multiple arguments + === Compatibility issues (excluding feature bug fixes) * BasicSocket#read_nonblock and BasicSocket#write_nonblock no Index: test/zlib/test_zlib.rb =================================================================== --- test/zlib/test_zlib.rb (revision 60378) +++ test/zlib/test_zlib.rb (revision 60379) @@ -1057,6 +1057,14 @@ if defined? Zlib https://github.com/ruby/ruby/blob/trunk/test/zlib/test_zlib.rb#L1057 } end + def test_puts + Tempfile.create("test_zlib_gzip_writer_puts") {|t| + t.close + Zlib::GzipWriter.open(t.path) {|gz| gz.puts("foo") } + assert_equal("foo\n", Zlib::GzipReader.open(t.path) {|gz| gz.read }) + } + end + def test_writer_wrap Tempfile.create("test_zlib_gzip_writer_wrap") {|t| t.binmode Index: ext/zlib/zlib.c =================================================================== --- ext/zlib/zlib.c (revision 60378) +++ ext/zlib/zlib.c (revision 60379) @@ -197,7 +197,7 @@ static VALUE rb_gzwriter_s_allocate(VALU https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L197 static VALUE rb_gzwriter_s_open(int, VALUE*, VALUE); static VALUE rb_gzwriter_initialize(int, VALUE*, VALUE); static VALUE rb_gzwriter_flush(int, VALUE*, VALUE); -static VALUE rb_gzwriter_write(VALUE, VALUE); +static VALUE rb_gzwriter_write(int, VALUE*, VALUE); static VALUE rb_gzwriter_putc(VALUE, VALUE); static VALUE rb_gzreader_s_allocate(VALUE); @@ -3566,18 +3566,23 @@ rb_gzwriter_flush(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L3566 * Same as IO. */ static VALUE -rb_gzwriter_write(VALUE obj, VALUE str) +rb_gzwriter_write(int argc, VALUE *argv, VALUE obj) { struct gzfile *gz = get_gzfile(obj); + size_t total = 0; - if (!RB_TYPE_P(str, T_STRING)) - str = rb_obj_as_string(str); - if (gz->enc2 && gz->enc2 != rb_ascii8bit_encoding()) { - str = rb_str_conv_enc(str, rb_enc_get(str), gz->enc2); + while (argc-- > 0) { + VALUE str = *argv++; + if (!RB_TYPE_P(str, T_STRING)) + str = rb_obj_as_string(str); + if (gz->enc2 && gz->enc2 != rb_ascii8bit_encoding()) { + str = rb_str_conv_enc(str, rb_enc_get(str), gz->enc2); + } + gzfile_write(gz, (Bytef*)RSTRING_PTR(str), RSTRING_LEN(str)); + total += RSTRING_LEN(str); + RB_GC_GUARD(str); } - gzfile_write(gz, (Bytef*)RSTRING_PTR(str), RSTRING_LEN(str)); - RB_GC_GUARD(str); - return INT2FIX(RSTRING_LEN(str)); + return SIZET2NUM(total); } /* @@ -4650,7 +4655,7 @@ Init_zlib(void) https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L4655 rb_define_alloc_func(cGzipWriter, rb_gzwriter_s_allocate); rb_define_method(cGzipWriter, "initialize", rb_gzwriter_initialize,-1); rb_define_method(cGzipWriter, "flush", rb_gzwriter_flush, -1); - rb_define_method(cGzipWriter, "write", rb_gzwriter_write, 1); + rb_define_method(cGzipWriter, "write", rb_gzwriter_write, -1); rb_define_method(cGzipWriter, "putc", rb_gzwriter_putc, 1); rb_define_method(cGzipWriter, "<<", rb_gzwriter_addstr, 1); rb_define_method(cGzipWriter, "printf", rb_gzwriter_printf, -1); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/