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

ruby-changes:35173

From: nagachika <ko1@a...>
Date: Sat, 23 Aug 2014 02:38:15 +0900 (JST)
Subject: [ruby-changes:35173] nagachika:r47255 (ruby_2_1): merge revision(s) r46896, r46897, r46898: [Backport #10078]

nagachika	2014-08-23 02:37:57 +0900 (Sat, 23 Aug 2014)

  New Revision: 47255

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

  Log:
    merge revision(s) r46896,r46897,r46898: [Backport #10078]
    
    * string.c (rb_str_count): fix wrong single-byte optimization.
      7bit ascii can be a trailing byte in Shift_JIS.
      [ruby-dev:48442] [Bug #10078]

  Modified directories:
    branches/ruby_2_1/
  Modified files:
    branches/ruby_2_1/ChangeLog
    branches/ruby_2_1/string.c
    branches/ruby_2_1/test/ruby/test_m17n.rb
    branches/ruby_2_1/test/ruby/test_m17n_comb.rb
    branches/ruby_2_1/version.h
Index: ruby_2_1/ChangeLog
===================================================================
--- ruby_2_1/ChangeLog	(revision 47254)
+++ ruby_2_1/ChangeLog	(revision 47255)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1
+Sat Aug 23 02:22:02 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* string.c (rb_str_count): fix wrong single-byte optimization.
+	  7bit ascii can be a trailing byte in Shift_JIS.
+	  [ruby-dev:48442] [Bug #10078]
+
 Thu Aug 21 01:44:46 2014  Tanaka Akira  <akr@f...>
 
 	* gc.c (mark_current_machine_context): Call SET_STACK_END.
Index: ruby_2_1/string.c
===================================================================
--- ruby_2_1/string.c	(revision 47254)
+++ ruby_2_1/string.c	(revision 47255)
@@ -6059,21 +6059,25 @@ rb_str_count(int argc, VALUE *argv, VALU https://github.com/ruby/ruby/blob/trunk/ruby_2_1/string.c#L6059
 {
     char table[TR_TABLE_SIZE];
     rb_encoding *enc = 0;
-    VALUE del = 0, nodel = 0;
+    VALUE del = 0, nodel = 0, tstr;
     char *s, *send;
     int i;
     int ascompat;
 
     rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);
-    for (i=0; i<argc; i++) {
-	VALUE tstr = argv[i];
-	unsigned char c;
 
-	StringValue(tstr);
-	enc = rb_enc_check(str, tstr);
-	if (argc == 1 && RSTRING_LEN(tstr) == 1 && rb_enc_asciicompat(enc) &&
-	    (c = RSTRING_PTR(tstr)[0]) < 0x80 && !is_broken_string(str)) {
+    tstr = argv[0];
+    StringValue(tstr);
+    enc = rb_enc_check(str, tstr);
+    if (argc == 1) {
+	const char *ptstr;
+	if (RSTRING_LEN(tstr) == 1 && rb_enc_asciicompat(enc) &&
+	    (ptstr = RSTRING_PTR(tstr),
+	     ONIGENC_IS_ALLOWED_REVERSE_MATCH(enc, (const unsigned char *)ptstr, (const unsigned char *)ptstr+1)) &&
+	    !is_broken_string(str)) {
 	    int n = 0;
+	    int clen;
+	    unsigned char c = rb_enc_codepoint_len(ptstr, ptstr+1, &clen, enc);
 
 	    s = RSTRING_PTR(str);
 	    if (!s || RSTRING_LEN(str) == 0) return INT2FIX(0);
@@ -6083,7 +6087,14 @@ rb_str_count(int argc, VALUE *argv, VALU https://github.com/ruby/ruby/blob/trunk/ruby_2_1/string.c#L6087
 	    }
 	    return INT2NUM(n);
 	}
-	tr_setup_table(tstr, table, i==0, &del, &nodel, enc);
+    }
+
+    tr_setup_table(tstr, table, TRUE, &del, &nodel, enc);
+    for (i=1; i<argc; i++) {
+	tstr = argv[i];
+	StringValue(tstr);
+	enc = rb_enc_check(str, tstr);
+	tr_setup_table(tstr, table, FALSE, &del, &nodel, enc);
     }
 
     s = RSTRING_PTR(str);
Index: ruby_2_1/version.h
===================================================================
--- ruby_2_1/version.h	(revision 47254)
+++ ruby_2_1/version.h	(revision 47255)
@@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1
 #define RUBY_VERSION "2.1.2"
-#define RUBY_RELEASE_DATE "2014-08-21"
-#define RUBY_PATCHLEVEL 205
+#define RUBY_RELEASE_DATE "2014-08-23"
+#define RUBY_PATCHLEVEL 206
 
 #define RUBY_RELEASE_YEAR 2014
 #define RUBY_RELEASE_MONTH 8
-#define RUBY_RELEASE_DAY 21
+#define RUBY_RELEASE_DAY 23
 
 #include "ruby/version.h"
 
Index: ruby_2_1/test/ruby/test_m17n.rb
===================================================================
--- ruby_2_1/test/ruby/test_m17n.rb	(revision 47254)
+++ ruby_2_1/test/ruby/test_m17n.rb	(revision 47255)
@@ -1037,6 +1037,11 @@ class TestM17N < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_m17n.rb#L1037
     assert_raise(Encoding::CompatibilityError){s.count(a("\xa3\xb0"))}
   end
 
+  def test_count_sjis_trailing_byte
+    bug10078 = '[ruby-dev:48442] [Bug #10078]'
+    assert_equal(0, s("\x98\x61").count("a"), bug10078)
+  end
+
   def test_delete
     assert_equal(1, e("\xa1\xa2").delete("z").length)
     s = e("\xa3\xb0\xa3\xb1\xa3\xb2\xa3\xb3\xa3\xb4")
Index: ruby_2_1/test/ruby/test_m17n_comb.rb
===================================================================
--- ruby_2_1/test/ruby/test_m17n_comb.rb	(revision 47254)
+++ ruby_2_1/test/ruby/test_m17n_comb.rb	(revision 47255)
@@ -87,7 +87,7 @@ class TestM17NComb < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_m17n_comb.rb#L87
     r
   end
 
-  def assert_enccall(recv, meth, *args, &block)
+  def encdumpcall(recv, meth, *args, &block)
     desc = ''
     if String === recv
       desc << encdump(recv)
@@ -110,6 +110,11 @@ class TestM17NComb < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_m17n_comb.rb#L110
     if block
       desc << ' {}'
     end
+    desc
+  end
+
+  def assert_enccall(recv, meth, *args, &block)
+    desc = encdumpcall(recv, meth, *args, &block)
     result = nil
     assert_nothing_raised(desc) {
       result = recv.send(meth, *args, &block)
@@ -709,12 +714,13 @@ class TestM17NComb < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_m17n_comb.rb#L714
 
   def test_str_count
     combination(STRINGS, STRINGS) {|s1, s2|
+      desc = proc {encdumpcall(s1, :count, s2)}
       if !s1.valid_encoding? || !s2.valid_encoding?
-        assert_raise(ArgumentError, Encoding::CompatibilityError) { s1.count(s2) }
+        assert_raise(ArgumentError, Encoding::CompatibilityError, desc) { s1.count(s2) }
         next
       end
       if !s1.ascii_only? && !s2.ascii_only? && s1.encoding != s2.encoding
-        assert_raise(Encoding::CompatibilityError) { s1.count(s2) }
+        assert_raise(Encoding::CompatibilityError, desc) { s1.count(s2) }
         next
       end
       n = enccall(s1, :count, s2)

Property changes on: ruby_2_1
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r46896-46898


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

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