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

ruby-changes:40753

From: nobu <ko1@a...>
Date: Tue, 1 Dec 2015 17:09:35 +0900 (JST)
Subject: [ruby-changes:40753] nobu:r52832 (trunk): cstr.c: split bug_str_cstr_unterm

nobu	2015-12-01 17:09:17 +0900 (Tue, 01 Dec 2015)

  New Revision: 52832

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

  Log:
    cstr.c: split bug_str_cstr_unterm
    
    * ext/-test-/string/cstr.c (bug_str_cstr_unterm): split
      unterminating from bug_str_cstr_term.

  Modified files:
    trunk/ext/-test-/string/cstr.c
    trunk/test/-ext-/string/test_cstr.rb
Index: ext/-test-/string/cstr.c
===================================================================
--- ext/-test-/string/cstr.c	(revision 52831)
+++ ext/-test-/string/cstr.c	(revision 52832)
@@ -9,9 +9,7 @@ bug_str_cstr_term(VALUE str) https://github.com/ruby/ruby/blob/trunk/ext/-test-/string/cstr.c#L9
     int c;
     rb_encoding *enc;
 
-    rb_str_modify(str);
     len = RSTRING_LEN(str);
-    RSTRING_PTR(str)[len] = 'x';
     s = StringValueCStr(str);
     rb_gc();
     enc = rb_enc_get(str);
@@ -20,6 +18,17 @@ bug_str_cstr_term(VALUE str) https://github.com/ruby/ruby/blob/trunk/ext/-test-/string/cstr.c#L18
 }
 
 static VALUE
+bug_str_cstr_unterm(VALUE str, VALUE c)
+{
+    long len;
+
+    rb_str_modify(str);
+    len = RSTRING_LEN(str);
+    RSTRING_PTR(str)[len] = NUM2CHR(c);
+    return str;
+}
+
+static VALUE
 bug_str_cstr_term_char(VALUE str)
 {
     long len;
@@ -42,6 +51,20 @@ bug_str_cstr_term_char(VALUE str) https://github.com/ruby/ruby/blob/trunk/ext/-test-/string/cstr.c#L51
 }
 
 static VALUE
+bug_str_s_cstr_term(VALUE self, VALUE str)
+{
+    Check_Type(str, T_STRING);
+    return bug_str_cstr_term(str);
+}
+
+static VALUE
+bug_str_s_cstr_unterm(VALUE self, VALUE str, VALUE c)
+{
+    Check_Type(str, T_STRING);
+    return bug_str_cstr_unterm(str, c);
+}
+
+static VALUE
 bug_str_s_cstr_term_char(VALUE self, VALUE str)
 {
     Check_Type(str, T_STRING);
@@ -52,6 +75,9 @@ void https://github.com/ruby/ruby/blob/trunk/ext/-test-/string/cstr.c#L75
 Init_cstr(VALUE klass)
 {
     rb_define_method(klass, "cstr_term", bug_str_cstr_term, 0);
+    rb_define_method(klass, "cstr_unterm", bug_str_cstr_unterm, 1);
     rb_define_method(klass, "cstr_term_char", bug_str_cstr_term_char, 0);
+    rb_define_singleton_method(klass, "cstr_term", bug_str_s_cstr_term, 1);
+    rb_define_singleton_method(klass, "cstr_unterm", bug_str_s_cstr_unterm, 2);
     rb_define_singleton_method(klass, "cstr_term_char", bug_str_s_cstr_term_char, 1);
 }
Index: test/-ext-/string/test_cstr.rb
===================================================================
--- test/-ext-/string/test_cstr.rb	(revision 52831)
+++ test/-ext-/string/test_cstr.rb	(revision 52832)
@@ -7,11 +7,13 @@ class Test_StringCStr < Test::Unit::Test https://github.com/ruby/ruby/blob/trunk/test/-ext-/string/test_cstr.rb#L7
   def test_embed
     s = Bug::String.new("abcdef")
     s.set_len(3)
+    s.cstr_unterm('x')
     assert_equal(0, s.cstr_term, Bug4319)
   end
 
   def test_long
     s = Bug::String.new("abcdef")*100000
+    s.cstr_unterm('x')
     assert_equal(0, s.cstr_term, Bug4319)
   end
 
@@ -20,9 +22,11 @@ class Test_StringCStr < Test::Unit::Test https://github.com/ruby/ruby/blob/trunk/test/-ext-/string/test_cstr.rb#L22
   def test_wchar_embed
     WCHARS.each do |enc|
       s = Bug::String.new("\u{4022}a".encode(enc))
+      s.cstr_unterm('x')
       assert_nothing_raised(ArgumentError) {s.cstr_term}
       s.set_len(s.bytesize / 2)
       assert_equal(1, s.size)
+      s.cstr_unterm('x')
       assert_equal(0, s.cstr_term)
     end
   end
@@ -33,9 +37,11 @@ class Test_StringCStr < Test::Unit::Test https://github.com/ruby/ruby/blob/trunk/test/-ext-/string/test_cstr.rb#L37
     len = str.size * n
     WCHARS.each do |enc|
       s = Bug::String.new(str.encode(enc))*n
+      s.cstr_unterm('x')
       assert_nothing_raised(ArgumentError, enc.name) {s.cstr_term}
       s.set_len(s.bytesize / 2)
       assert_equal(len / 2, s.size, enc.name)
+      s.cstr_unterm('x')
       assert_equal(0, s.cstr_term, enc.name)
     end
   end

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

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