ruby-changes:23794
From: naruse <ko1@a...>
Date: Wed, 30 May 2012 17:21:31 +0900 (JST)
Subject: [ruby-changes:23794] naruse:r35845 (ruby_1_9_3): merge revision(s) 34552: [Bug #6516]
naruse 2012-05-30 17:21:16 +0900 (Wed, 30 May 2012) New Revision: 35845 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=35845 Log: merge revision(s) 34552: [Bug #6516] * ext/zlib/zlib.c (do_inflate): Inflate more data if buffered data exists. Allows Zlib::Inflate#set_dictionary to work. [ruby-trunk - Bug #5929] Modified files: branches/ruby_1_9_3/ChangeLog branches/ruby_1_9_3/ext/zlib/zlib.c branches/ruby_1_9_3/test/zlib/test_zlib.rb branches/ruby_1_9_3/version.h Index: ruby_1_9_3/ChangeLog =================================================================== --- ruby_1_9_3/ChangeLog (revision 35844) +++ ruby_1_9_3/ChangeLog (revision 35845) @@ -1,3 +1,9 @@ +Wed May 30 17:19:56 2012 Eric Hodel <drbrain@s...> + + * ext/zlib/zlib.c (do_inflate): Inflate more data if buffered data + exists. Allows Zlib::Inflate#set_dictionary to work. + [ruby-trunk - Bug #5929] + Mon May 28 11:40:19 2012 Nobuyoshi Nakada <nobu@r...> * io.c (rb_io_extract_modeenc): fail only if conflicting Index: ruby_1_9_3/ext/zlib/zlib.c =================================================================== --- ruby_1_9_3/ext/zlib/zlib.c (revision 35844) +++ ruby_1_9_3/ext/zlib/zlib.c (revision 35845) @@ -1732,7 +1732,7 @@ return; } StringValue(src); - if (RSTRING_LEN(src) > 0) { /* prevent Z_BUF_ERROR */ + if (RSTRING_LEN(src) > 0 || z->stream.avail_in > 0) { /* prevent Z_BUF_ERROR */ zstream_run(z, (Bytef*)RSTRING_PTR(src), RSTRING_LEN(src), Z_SYNC_FLUSH); } } @@ -1749,8 +1749,24 @@ * * Raises a Zlib::NeedDict exception if a preset dictionary is needed to * decompress. Set the dictionary by Zlib::Inflate#set_dictionary and then - * call this method again with an empty string. (<i>???</i>) + * call this method again with an empty string to flush the stream: * + * inflater = Zlib::Inflate.new + * + * begin + * out = inflater.inflate compressed + * rescue Zlib::NeedDict + * # ensure the dictionary matches the stream's required dictionary + * raise unless inflater.adler == Zlib.adler32(dictionary) + * + * inflater.set_dictionary dictionary + * inflater.inflate '' + * end + * + * # ... + * + * inflater.close + * * See also Zlib::Inflate.new */ static VALUE Index: ruby_1_9_3/version.h =================================================================== --- ruby_1_9_3/version.h (revision 35844) +++ ruby_1_9_3/version.h (revision 35845) @@ -1,10 +1,10 @@ #define RUBY_VERSION "1.9.3" -#define RUBY_PATCHLEVEL 232 +#define RUBY_PATCHLEVEL 233 -#define RUBY_RELEASE_DATE "2012-05-28" +#define RUBY_RELEASE_DATE "2012-05-30" #define RUBY_RELEASE_YEAR 2012 #define RUBY_RELEASE_MONTH 5 -#define RUBY_RELEASE_DAY 28 +#define RUBY_RELEASE_DAY 30 #include "ruby/version.h" Index: ruby_1_9_3/test/zlib/test_zlib.rb =================================================================== --- ruby_1_9_3/test/zlib/test_zlib.rb (revision 35844) +++ ruby_1_9_3/test/zlib/test_zlib.rb (revision 35845) @@ -195,6 +195,29 @@ z << "foo" # ??? end + def test_inflate_dictionary + dictionary = "foo" + + deflate = Zlib::Deflate.new + deflate.set_dictionary dictionary + compressed = deflate.deflate "foofoofoo", Zlib::FINISH + deflate.close + + out = nil + inflate = Zlib::Inflate.new + + begin + out = inflate.inflate compressed + + flunk "Zlib::NeedDict was not raised" + rescue Zlib::NeedDict + inflate.set_dictionary dictionary + out = inflate.inflate "" + end + + assert_equal "foofoofoo", out + end + def test_sync z = Zlib::Deflate.new s = z.deflate("foo" * 1000, Zlib::FULL_FLUSH) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/