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

ruby-changes:35245

From: normal <ko1@a...>
Date: Sun, 31 Aug 2014 08:53:42 +0900 (JST)
Subject: [ruby-changes:35245] normal:r47327 (trunk): zlib: GzipReader#rewind preserves ZSTREAM_FLAG_GZFILE

normal	2014-08-31 08:53:28 +0900 (Sun, 31 Aug 2014)

  New Revision: 47327

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

  Log:
    zlib: GzipReader#rewind preserves ZSTREAM_FLAG_GZFILE
    
    * ext/zlib/zlib.c (gzfile_reset): preserve ZSTREAM_FLAG_GZFILE
      [Bug #10101]
    
    * test/zlib/test_zlib.rb (test_rewind): test each_byte
    
    We must preserve the ZSTREAM_FLAG_GZFILE flag to prevent
    zstream_detach_buffer from:
    
    a) returning Qnil and breaking out of the `each_byte' loop
    b) yielding a large string to each_byte
    
    Note: the test case in bug report takes a long time.  I found this
    bug because I noticed the massive time descrepancy between
    `each_byte' and `readbyte' loop before this patch.  With this patch,
    `each_byte' and `readbyte' both take very long.

  Modified files:
    trunk/ChangeLog
    trunk/ext/zlib/zlib.c
    trunk/test/zlib/test_zlib.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47326)
+++ ChangeLog	(revision 47327)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Aug 31 08:46:44 2014  Eric Wong  <e@8...>
+
+	* ext/zlib/zlib.c (gzfile_reset): preserve ZSTREAM_FLAG_GZFILE
+	  [Bug #10101]
+
+	* test/zlib/test_zlib.rb (test_rewind): test each_byte
+
 Sat Aug 30 19:22:47 2014  Eric Wong  <e@8...>
 
 	* symbol.c (rb_sym2id): do not return garbage object
Index: ext/zlib/zlib.c
===================================================================
--- ext/zlib/zlib.c	(revision 47326)
+++ ext/zlib/zlib.c	(revision 47327)
@@ -2293,6 +2293,7 @@ static void https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L2293
 gzfile_reset(struct gzfile *gz)
 {
     zstream_reset(&gz->z);
+    gz->z.flags |= ZSTREAM_FLAG_GZFILE;
     gz->crc = crc32(0, Z_NULL, 0);
     gz->lineno = 0;
     gz->ungetc = 0;
Index: test/zlib/test_zlib.rb
===================================================================
--- test/zlib/test_zlib.rb	(revision 47326)
+++ test/zlib/test_zlib.rb	(revision 47327)
@@ -695,6 +695,11 @@ if defined? Zlib https://github.com/ruby/ruby/blob/trunk/test/zlib/test_zlib.rb#L695
           assert_equal("foo", f.read)
           f.rewind
           assert_equal("foo", f.read)
+
+          f.rewind
+          bytes = []
+          f.each_byte { |b| bytes << b }
+          assert_equal "foo".bytes.to_a, bytes, '[Bug #10101]'
         end
         open(t.path, "rb") do |f|
           gz = Zlib::GzipReader.new(f)

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

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