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

ruby-changes:22312

From: naruse <ko1@a...>
Date: Mon, 23 Jan 2012 18:19:22 +0900 (JST)
Subject: [ruby-changes:22312] naruse:r34361 (ruby_1_9_3): merge revision(s) r34350:

naruse	2012-01-23 18:19:10 +0900 (Mon, 23 Jan 2012)

  New Revision: 34361

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

  Log:
    merge revision(s) r34350:
    
    * encoding.c (rb_enc_compatible): fix segv on symbols.
      [ruby-core:42204] [Bug #5921]

  Modified files:
    branches/ruby_1_9_3/ChangeLog
    branches/ruby_1_9_3/encoding.c
    branches/ruby_1_9_3/test/ruby/test_encoding.rb
    branches/ruby_1_9_3/version.h

Index: ruby_1_9_3/encoding.c
===================================================================
--- ruby_1_9_3/encoding.c	(revision 34360)
+++ ruby_1_9_3/encoding.c	(revision 34361)
@@ -750,6 +750,7 @@
 {
     int idx1, idx2;
     rb_encoding *enc1, *enc2;
+    int isstr1, isstr2;
 
     idx1 = rb_enc_get_index(str1);
     idx2 = rb_enc_get_index(str2);
@@ -763,33 +764,38 @@
     enc1 = rb_enc_from_index(idx1);
     enc2 = rb_enc_from_index(idx2);
 
-    if (BUILTIN_TYPE(str2) == T_STRING && RSTRING_LEN(str2) == 0)
+    isstr2 = RB_TYPE_P(str2, T_STRING);
+    if (isstr2 && RSTRING_LEN(str2) == 0)
 	return enc1;
-    if (BUILTIN_TYPE(str1) == T_STRING && RSTRING_LEN(str1) == 0)
+    isstr1 = RB_TYPE_P(str1, T_STRING);
+    if (isstr1 && RSTRING_LEN(str1) == 0)
 	return (rb_enc_asciicompat(enc1) && rb_enc_str_asciionly_p(str2)) ? enc1 : enc2;
     if (!rb_enc_asciicompat(enc1) || !rb_enc_asciicompat(enc2)) {
 	return 0;
     }
 
     /* objects whose encoding is the same of contents */
-    if (BUILTIN_TYPE(str2) != T_STRING && idx2 == ENCINDEX_US_ASCII)
+    if (!isstr2 && idx2 == ENCINDEX_US_ASCII)
 	return enc1;
-    if (BUILTIN_TYPE(str1) != T_STRING && idx1 == ENCINDEX_US_ASCII)
+    if (!isstr1 && idx1 == ENCINDEX_US_ASCII)
 	return enc2;
 
-    if (BUILTIN_TYPE(str1) != T_STRING) {
+    if (!isstr1) {
 	VALUE tmp = str1;
 	int idx0 = idx1;
 	str1 = str2;
 	str2 = tmp;
 	idx1 = idx2;
 	idx2 = idx0;
+	idx0 = isstr1;
+	isstr1 = isstr2;
+	isstr2 = idx0;
     }
-    if (BUILTIN_TYPE(str1) == T_STRING) {
+    if (isstr1) {
 	int cr1, cr2;
 
 	cr1 = rb_enc_str_coderange(str1);
-	if (BUILTIN_TYPE(str2) == T_STRING) {
+	if (isstr2) {
 	    cr2 = rb_enc_str_coderange(str2);
 	    if (cr1 != cr2) {
 		/* may need to handle ENC_CODERANGE_BROKEN */
@@ -1069,7 +1075,7 @@
  *
  * If the objects are non-strings their encodings are compatible when they
  * have an encoding and:
- * * Either encoding is US ASCII compatible
+ * * Either encoding is US-ASCII compatible
  * * One of the encodings is a 7-bit encoding
  *
  */
Index: ruby_1_9_3/ChangeLog
===================================================================
--- ruby_1_9_3/ChangeLog	(revision 34360)
+++ ruby_1_9_3/ChangeLog	(revision 34361)
@@ -1,3 +1,8 @@
+Mon Jan 23 18:18:58 2012  NARUSE, Yui  <naruse@r...>
+
+	* encoding.c (rb_enc_compatible): fix segv on symbols.
+	  [ruby-core:42204] [Bug #5921]
+
 Tue Jan 17 17:18:41 2012  Nobuyoshi Nakada  <nobu@r...>
 
 	* configure.in (SPT_TYPE): enable as SPT_REUSEARGV on Darwin.
Index: ruby_1_9_3/version.h
===================================================================
--- ruby_1_9_3/version.h	(revision 34360)
+++ ruby_1_9_3/version.h	(revision 34361)
@@ -1,10 +1,10 @@
 #define RUBY_VERSION "1.9.3"
-#define RUBY_PATCHLEVEL 27
+#define RUBY_PATCHLEVEL 28
 
-#define RUBY_RELEASE_DATE "2012-01-20"
+#define RUBY_RELEASE_DATE "2012-01-23"
 #define RUBY_RELEASE_YEAR 2012
 #define RUBY_RELEASE_MONTH 1
-#define RUBY_RELEASE_DAY 20
+#define RUBY_RELEASE_DAY 23
 
 #include "ruby/version.h"
 
Index: ruby_1_9_3/test/ruby/test_encoding.rb
===================================================================
--- ruby_1_9_3/test/ruby/test_encoding.rb	(revision 34360)
+++ ruby_1_9_3/test/ruby/test_encoding.rb	(revision 34361)
@@ -101,4 +101,10 @@
     bug5279 = '[ruby-dev:44469]'
     assert_ruby_status([], '$SAFE=3; "a".encode("utf-16be")', bug5279)
   end
+
+  def test_compatible_p
+    ua = "abc".force_encoding(Encoding::UTF_8)
+    assert_equal(Encoding::UTF_8, Encoding.compatible?(ua, :abc))
+    assert_equal(nil, Encoding.compatible?(ua, 1))
+  end
 end

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

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