diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-05-30 08:21:16 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-05-30 08:21:16 +0000 |
commit | b3e306a5f48814e883be4ab138ecbaebffcb2765 (patch) | |
tree | 58e06ee289a6417f43fb076ab2036e242e3d0d1e | |
parent | 1d0ddd4218e701d086b3e4f21fd38183fa3a4e8a (diff) |
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]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@35845 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | ext/zlib/zlib.c | 20 | ||||
-rw-r--r-- | test/zlib/test_zlib.rb | 23 | ||||
-rw-r--r-- | version.h | 6 |
4 files changed, 50 insertions, 5 deletions
@@ -1,3 +1,9 @@ +Wed May 30 17:19:56 2012 Eric Hodel <drbrain@segment7.net> + + * 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@ruby-lang.org> * io.c (rb_io_extract_modeenc): fail only if conflicting diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index 42c2c75f92..17f132b1b1 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -1732,7 +1732,7 @@ do_inflate(struct zstream *z, VALUE src) 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,7 +1749,23 @@ do_inflate(struct zstream *z, VALUE src) * * 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 */ diff --git a/test/zlib/test_zlib.rb b/test/zlib/test_zlib.rb index 37781bc8e7..529c3f4154 100644 --- a/test/zlib/test_zlib.rb +++ b/test/zlib/test_zlib.rb @@ -195,6 +195,29 @@ if defined? Zlib 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) @@ -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" |