diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-10-21 14:14:13 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-10-21 14:14:13 +0000 |
commit | 16549e33da58396d243234e5880f4f1dae6ab339 (patch) | |
tree | f39da42c5b6371821cedfa3d5a3916f3a5c5ac9d /ext | |
parent | c5377c2bccb7c46e4f8a958f0ddfd487c487000c (diff) | |
download | ruby-16549e33da58396d243234e5880f4f1dae6ab339.tar.gz |
* 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@19874 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r-- | ext/stringio/stringio.c | 7 | ||||
-rw-r--r-- | ext/zlib/zlib.c | 3 |
2 files changed, 9 insertions, 1 deletions
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index c223b8d95c..b907047137 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 <fcntl.h> #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 bc0716b835..d2bcf76eb4 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); } |