[前][次][番号順一覧][スレッド一覧]

ruby-changes:8346

From: matz <ko1@a...>
Date: Tue, 21 Oct 2008 23:14:38 +0900 (JST)
Subject: [ruby-changes:8346] Ruby:r19874 (trunk): * ext/stringio/stringio.c (strio_write): should convert writing

matz	2008-10-21 23:14:13 +0900 (Tue, 21 Oct 2008)

  New Revision: 19874

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19874

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/ext/stringio/stringio.c
    trunk/ext/zlib/zlib.c
    trunk/hash.c
    trunk/test/zlib/test_zlib.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 19873)
+++ ChangeLog	(revision 19874)
@@ -1,3 +1,13 @@
+Tue Oct 21 23:12:24 2008  Yukihiro Matsumoto  <matz@r...>
+
+	* 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  <matz@r...>
 
 	* io.c (open_key_args): should adjust argc, argv in struct
Index: ext/zlib/zlib.c
===================================================================
--- ext/zlib/zlib.c	(revision 19873)
+++ ext/zlib/zlib.c	(revision 19874)
@@ -2747,7 +2747,8 @@
 {
     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);
     }
Index: ext/stringio/stringio.c
===================================================================
--- ext/stringio/stringio.c	(revision 19873)
+++ ext/stringio/stringio.c	(revision 19874)
@@ -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 @@
 {
     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);
Index: hash.c
===================================================================
--- hash.c	(revision 19873)
+++ hash.c	(revision 19874)
@@ -79,7 +79,7 @@
       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);
     }
Index: test/zlib/test_zlib.rb
===================================================================
--- test/zlib/test_zlib.rb	(revision 19873)
+++ test/zlib/test_zlib.rb	(revision 19874)
@@ -597,7 +597,7 @@
       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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]