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

ruby-changes:43917

From: nobu <ko1@a...>
Date: Tue, 23 Aug 2016 10:15:16 +0900 (JST)
Subject: [ruby-changes:43917] nobu:r55990 (trunk): string.c: rb_fs_setter

nobu	2016-08-23 10:15:04 +0900 (Tue, 23 Aug 2016)

  New Revision: 55990

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

  Log:
    string.c: rb_fs_setter
    
    * string.c (rb_fs_setter): check and convert $; value at
      assignment.

  Modified files:
    trunk/ChangeLog
    trunk/string.c
    trunk/test/ruby/test_string.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 55989)
+++ ChangeLog	(revision 55990)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Aug 23 10:15:01 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* string.c (rb_fs_setter): check and convert $; value at
+	  assignment.
+
 Tue Aug 23 02:09:57 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* string.c (rb_str_split_m): show $; name in error message when it
Index: string.c
===================================================================
--- string.c	(revision 55989)
+++ string.c	(revision 55990)
@@ -7126,7 +7126,7 @@ rb_str_split_m(int argc, VALUE *argv, VA https://github.com/ruby/ruby/blob/trunk/string.c#L7126
 		split_type = regexp;
 	    }
 	    else if (rb_enc_asciicompat(enc2) == 1) {
-		if (RSTRING_LEN(spat) == 1 && RSTRING_PTR(spat)[0] == ' '){
+		if (RSTRING_LEN(spat) == 1 && RSTRING_PTR(spat)[0] == ' ') {
 		    split_type = awk;
 		}
 	    }
@@ -8861,6 +8861,18 @@ rb_str_setter(VALUE val, ID id, VALUE *v https://github.com/ruby/ruby/blob/trunk/string.c#L8861
     *var = val;
 }
 
+static void
+rb_fs_setter(VALUE val, ID id, VALUE *var)
+{
+    val = rb_fs_check(val);
+    if (!val) {
+	rb_raise(rb_eTypeError,
+		 "value of %"PRIsVALUE" must be String or Regexp",
+		 rb_id2str(id));
+    }
+    *var = val;
+}
+
 
 /*
  *  call-seq:
@@ -9879,8 +9891,8 @@ Init_String(void) https://github.com/ruby/ruby/blob/trunk/string.c#L9891
     rb_define_method(rb_cString, "ascii_only?", rb_str_is_ascii_only_p, 0);
 
     rb_fs = Qnil;
-    rb_define_variable("$;", &rb_fs);
-    rb_define_variable("$-F", &rb_fs);
+    rb_define_hooked_variable("$;", &rb_fs, 0, rb_fs_setter);
+    rb_define_hooked_variable("$-F", &rb_fs, 0, rb_fs_setter);
 
     rb_cSymbol = rb_define_class("Symbol", rb_cObject);
     rb_include_module(rb_cSymbol, rb_mComparable);
Index: test/ruby/test_string.rb
===================================================================
--- test/ruby/test_string.rb	(revision 55989)
+++ test/ruby/test_string.rb	(revision 55990)
@@ -1389,13 +1389,14 @@ CODE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L1389
     assert_equal([], "".split(//, 1))
 
     assert_equal("[2, 3]", [1,2,3].slice!(1,10000).inspect, "moved from btest/knownbug")
+  ensure
+    $; = fs
+  end
 
-    $; = []
+  def test_fs
     assert_raise_with_message(TypeError, /\$;/) {
-      "".split
+      $; = []
     }
-  ensure
-    $; = fs
   end
 
   def test_split_encoding

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

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