From 8db0a59d921144bc73a385d664246f4b8bd2985e Mon Sep 17 00:00:00 2001 From: matz Date: Tue, 21 Oct 2008 14:14:13 +0000 Subject: * ext/stringio/stringio.c (strio_write): should convert writing string to the encoding of the buffer. * hash.c (rb_any_hash): typo fixed. * ext/zlib/zlib.c (rb_gzwriter_write): oops, IO string conversion need to be done by to_s. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@19874 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 10 ++++++++++ ext/stringio/stringio.c | 7 +++++++ ext/zlib/zlib.c | 3 ++- hash.c | 2 +- test/zlib/test_zlib.rb | 2 +- 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1e8160066..19d14cf96 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Tue Oct 21 23:12:24 2008 Yukihiro Matsumoto + + * ext/stringio/stringio.c (strio_write): should convert writing + string to the encoding of the buffer. + + * hash.c (rb_any_hash): typo fixed. + + * ext/zlib/zlib.c (rb_gzwriter_write): oops, IO string conversion + need to be done by to_s. + Tue Oct 21 22:38:58 2008 Yukihiro Matsumoto * io.c (open_key_args): should adjust argc, argv in struct diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index c223b8d95..b90704713 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -13,6 +13,7 @@ #include "ruby.h" #include "ruby/io.h" +#include "ruby/encoding.h" #if defined(HAVE_FCNTL_H) || defined(_WIN32) #include #elif defined(HAVE_SYS_FCNTL_H) @@ -992,9 +993,15 @@ strio_write(VALUE self, VALUE str) { struct StringIO *ptr = writable(StringIO(self)); long len, olen; + rb_encoding *enc, *enc2; if (TYPE(str) != T_STRING) str = rb_obj_as_string(str); + enc = rb_enc_get(ptr->string); + enc2 = rb_enc_get(str); + if (enc != enc2 && enc != rb_ascii8bit_encoding()) { + str = rb_str_conv_enc(str, enc2, enc); + } len = RSTRING_LEN(str); if (len == 0) return INT2FIX(0); check_modifiable(ptr); diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index bc0716b83..d2bcf76eb 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -2747,7 +2747,8 @@ rb_gzwriter_write(VALUE obj, VALUE str) { struct gzfile *gz = get_gzfile(obj); - StringValue(str); + if (TYPE(str) != T_STRING) + str = rb_obj_as_string(str); if (gz->enc2 && gz->enc2 != rb_ascii8bit_encoding()) { str = rb_str_conv_enc(str, rb_enc_get(str), gz->enc2); } diff --git a/hash.c b/hash.c index 19646004e..044964c80 100644 --- a/hash.c +++ b/hash.c @@ -79,7 +79,7 @@ rb_any_hash(VALUE a) default: hval = rb_funcall(a, id_hash, 0); if (!FIXNUM_P(hval)) { - hval = rb_funcall(hval, '%', 1, INT2FIX(5368709231)); + hval = rb_funcall(hval, '%', 1, INT2FIX(536870923)); } hnum = (int)FIX2LONG(hval); } diff --git a/test/zlib/test_zlib.rb b/test/zlib/test_zlib.rb index 5a4a87a0f..5746f036e 100644 --- a/test/zlib/test_zlib.rb +++ b/test/zlib/test_zlib.rb @@ -597,7 +597,7 @@ if defined? Zlib assert_equal("foo", Zlib::GzipReader.open(t.path) {|gz| gz.read }) o = Object.new - def o.to_str; "bar"; end + def o.to_s; "bar"; end Zlib::GzipWriter.open(t.path) {|gz| gz.print(o) } assert_equal("bar", Zlib::GzipReader.open(t.path) {|gz| gz.read }) end -- cgit