Skip to content

Commit

Permalink
* ext/zlib/zlib.c (rb_gzwriter_write): conversion should be done
Browse files Browse the repository at this point in the history
  using to_str, not to_s.

* ext/zlib/zlib.c (rb_gzwriter_write): need proper conversion
  according to gz encoding.

* ext/zlib/zlib.c (rb_gzreader_ungetc): convert string encoding
  before unget.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19872 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
matz committed Oct 21, 2008
1 parent ac466de commit 42a6550
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
11 changes: 11 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
Tue Oct 21 21:52:00 2008 Yukihiro Matsumoto <[email protected]>

* ext/zlib/zlib.c (rb_gzwriter_write): conversion should be done
using to_str, not to_s.

* ext/zlib/zlib.c (rb_gzwriter_write): need proper conversion
according to gz encoding.

* ext/zlib/zlib.c (rb_gzreader_ungetc): convert string encoding
before unget.

Tue Oct 21 21:33:36 2008 Nobuyoshi Nakada <[email protected]>

* lib/test/unit.rb (assert_nothing_raised): raise with backtrace.
Expand Down
11 changes: 8 additions & 3 deletions ext/zlib/zlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -2747,10 +2747,10 @@ rb_gzwriter_write(VALUE obj, VALUE str)
{
struct gzfile *gz = get_gzfile(obj);

if (TYPE(str) != T_STRING) {
str = rb_obj_as_string(str);
StringValue(str);
if (gz->enc2 && gz->enc2 != rb_ascii8bit_encoding()) {
str = rb_str_conv_enc(str, rb_enc_get(str), gz->enc2);
}
str = rb_str_export(str);
gzfile_write(gz, (Bytef*)RSTRING_PTR(str), RSTRING_LEN(str));
return INT2FIX(RSTRING_LEN(str));
}
Expand Down Expand Up @@ -3075,6 +3075,11 @@ static VALUE
rb_gzreader_ungetc(VALUE obj, VALUE s)
{
struct gzfile *gz = get_gzfile(obj);

StringValue(s);
if (gz->enc2 && gz->enc2 != rb_ascii8bit_encoding()) {
s = rb_str_conv_enc(s, rb_enc_get(s), gz->enc2);
}
gzfile_ungets(gz, (const Bytef*)RSTRING_PTR(s), RSTRING_LEN(s));
return Qnil;
}
Expand Down
2 changes: 1 addition & 1 deletion test/zlib/test_zlib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ def test_write
assert_equal("foo", Zlib::GzipReader.open(t.path) {|gz| gz.read })

o = Object.new
def o.to_s; "bar"; end
def o.to_str; "bar"; end
Zlib::GzipWriter.open(t.path) {|gz| gz.print(o) }
assert_equal("bar", Zlib::GzipReader.open(t.path) {|gz| gz.read })
end
Expand Down

0 comments on commit 42a6550

Please sign in to comment.