1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

e ext/zlib/zlib.c (gzfile_reader_get_unused): use rb_str_resurrect

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30773 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2011-02-03 09:56:52 +00:00
parent d6d24991bd
commit b4940b61e3
3 changed files with 33 additions and 4 deletions

View file

@ -1,6 +1,6 @@
Thu Feb 3 18:33:26 2011 NARUSE, Yui <naruse@ruby-lang.org>
* ext/zlib/zlib.c (gzfile_reader_get_unused): use rb_str_new_shared
e ext/zlib/zlib.c (gzfile_reader_get_unused): use rb_str_resurrect
because gz->z.input is hidden string. [ruby-core:35057]
Thu Feb 3 16:34:10 2011 NARUSE, Yui <naruse@ruby-lang.org>

View file

@ -2471,7 +2471,8 @@ gzfile_reader_get_unused(struct gzfile *gz)
}
if (NIL_P(gz->z.input)) return Qnil;
str = rb_str_new_shared(gz->z.input);
str = rb_str_dup(gz->z.input);
str = rb_str_resurrect(str);
OBJ_TAINT(str); /* for safe */
return str;
}

View file

@ -491,13 +491,41 @@ if defined? Zlib
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foobar") }
Zlib::GzipReader.open(t.path) do |f|
assert_equal(nil, f.unused)
assert_equal("foo", f.read(3))
f.unused
assert_equal(nil, f.unused)
assert_equal("bar", f.read)
f.unused
assert_equal(nil, f.unused)
end
end
def test_unused2
zio = StringIO.new
io = Zlib::GzipWriter.new zio
io.write 'aaaa'
io.finish
io = Zlib::GzipWriter.new zio
io.write 'bbbb'
io.finish
zio.rewind
io = Zlib::GzipReader.new zio
assert_equal('aaaa', io.read)
unused = io.unused
assert_equal(24, unused.bytesize)
io.finish
zio.pos -= unused.length
io = Zlib::GzipReader.new zio
assert_equal('bbbb', io.read)
assert_equal(nil, io.unused)
io.finish
end
def test_read
t = Tempfile.new("test_zlib_gzip_reader_read")
t.close