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

ruby-changes:37569

From: naruse <ko1@a...>
Date: Thu, 19 Feb 2015 17:32:42 +0900 (JST)
Subject: [ruby-changes:37569] naruse:r49650 (ruby_2_2): merge revision(s) 49402, 49403, 49414:

naruse	2015-02-19 17:32:27 +0900 (Thu, 19 Feb 2015)

  New Revision: 49650

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

  Log:
    merge revision(s) 49402,49403,49414:
    
    cstr.c: get rid of exception
    
    * ext/-test-/string/cstr.c (bug_str_cstr_term_char): get rid of
      invalid byte sequence exception.

  Modified directories:
    branches/ruby_2_2/
  Modified files:
    branches/ruby_2_2/ext/-test-/string/cstr.c
    branches/ruby_2_2/version.h
Index: ruby_2_2/ext/-test-/string/cstr.c
===================================================================
--- ruby_2_2/ext/-test-/string/cstr.c	(revision 49649)
+++ ruby_2_2/ext/-test-/string/cstr.c	(revision 49650)
@@ -28,8 +28,24 @@ bug_str_cstr_term_char(VALUE str) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/ext/-test-/string/cstr.c#L28
     rb_encoding *enc = rb_enc_get(str);
 
     RSTRING_GETMEM(str, s, len);
-    c = rb_enc_codepoint(&s[len], &s[len+rb_enc_mbminlen(enc)], enc);
-    return c ? rb_enc_uint_chr((unsigned int)c, enc) : Qnil;
+    s += len;
+    len = rb_enc_mbminlen(enc);
+    c = rb_enc_precise_mbclen(s, s + len, enc);
+    if (!MBCLEN_CHARFOUND_P(c)) {
+	c = (unsigned char)*s;
+    }
+    else {
+	c = rb_enc_mbc_to_codepoint(s, s + len, enc);
+	if (!c) return Qnil;
+    }
+    return rb_enc_uint_chr((unsigned int)c, enc);
+}
+
+static VALUE
+bug_str_s_cstr_term_char(VALUE self, VALUE str)
+{
+    Check_Type(str, T_STRING);
+    return bug_str_cstr_term_char(str);
 }
 
 void
@@ -37,4 +53,5 @@ Init_cstr(VALUE klass) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/ext/-test-/string/cstr.c#L53
 {
     rb_define_method(klass, "cstr_term", bug_str_cstr_term, 0);
     rb_define_method(klass, "cstr_term_char", bug_str_cstr_term_char, 0);
+    rb_define_singleton_method(klass, "cstr_term_char", bug_str_s_cstr_term_char, 1);
 }
Index: ruby_2_2/version.h
===================================================================
--- ruby_2_2/version.h	(revision 49649)
+++ ruby_2_2/version.h	(revision 49650)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/version.h#L1
 #define RUBY_VERSION "2.2.0"
 #define RUBY_RELEASE_DATE "2015-02-19"
-#define RUBY_PATCHLEVEL 60
+#define RUBY_PATCHLEVEL 61
 
 #define RUBY_RELEASE_YEAR 2015
 #define RUBY_RELEASE_MONTH 2

Property changes on: ruby_2_2
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r49402-49403,49414


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

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