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

ruby-changes:55395

From: nobu <ko1@a...>
Date: Thu, 18 Apr 2019 18:34:46 +0900 (JST)
Subject: [ruby-changes:55395] nobu:r67603 (trunk): string.c: warn non-nil $;

nobu	2019-04-18 18:34:40 +0900 (Thu, 18 Apr 2019)

  New Revision: 67603

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

  Log:
    string.c: warn non-nil $;
    
    * string.c (rb_str_split_m): warn use of non-nil $;.
    
    * string.c (rb_fs_setter): warn when set to non-nil value.

  Modified files:
    trunk/NEWS
    trunk/string.c
    trunk/test/ruby/test_string.rb
Index: test/ruby/test_string.rb
===================================================================
--- test/ruby/test_string.rb	(revision 67602)
+++ test/ruby/test_string.rb	(revision 67603)
@@ -1702,7 +1702,7 @@ CODE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L1702
 
     assert_equal([], "".split(//, 1))
   ensure
-    $; = fs
+    EnvUtil.suppress_warning {$; = fs}
   end
 
   def test_split_with_block
@@ -1742,7 +1742,7 @@ CODE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L1742
     result = []; "".split(//, 1) {|s| result << s}
     assert_equal([], result)
   ensure
-    $; = fs
+    EnvUtil.suppress_warning {$; = fs}
   end
 
   def test_fs
@@ -1750,7 +1750,7 @@ CODE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L1750
       $; = []
     }
 
-    assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
+    assert_separately(%W[-W0], "#{<<~"begin;"}\n#{<<~'end;'}")
     bug = '[ruby-core:79582] $; must not be GCed'
     begin;
       $; = " "
@@ -1760,6 +1760,13 @@ CODE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L1760
       GC.start
       assert_equal([], "".split, bug)
     end;
+
+    begin
+      fs = $;
+      assert_warn(/\$; will be deprecated/) {$; = " "}
+    ensure
+      EnvUtil.suppress_warning {$; = fs}
+    end
   end
 
   def test_split_encoding
Index: string.c
===================================================================
--- string.c	(revision 67602)
+++ string.c	(revision 67603)
@@ -7793,6 +7793,9 @@ rb_str_split_m(int argc, VALUE *argv, VA https://github.com/ruby/ruby/blob/trunk/string.c#L7793
     else if (!(spat = rb_fs_check(spat))) {
 	rb_raise(rb_eTypeError, "value of $; must be String or Regexp");
     }
+    else {
+        rb_warn("$; is set to non-nil value");
+    }
     if (split_type != awk) {
 	if (BUILTIN_TYPE(spat) == T_STRING) {
 	    rb_encoding *enc2 = STR_ENC_GET(spat);
@@ -9918,6 +9921,9 @@ rb_fs_setter(VALUE val, ID id, VALUE *va https://github.com/ruby/ruby/blob/trunk/string.c#L9921
 		 "value of %"PRIsVALUE" must be String or Regexp",
 		 rb_id2str(id));
     }
+    if (!NIL_P(val)) {
+        rb_warn("non-nil $; will be deprecated");
+    }
     *var = val;
 }
 
Index: NEWS
===================================================================
--- NEWS	(revision 67602)
+++ NEWS	(revision 67603)
@@ -36,6 +36,9 @@ sufficient information, see the ChangeLo https://github.com/ruby/ruby/blob/trunk/NEWS#L36
      ary[..3]  # identical to ary[0..3]
      where(sales: ..100)
 
+* Setting <code>$;</code> to non-nil value is warned now.  Use of it in
+  String#split is warned too.
+
 === Core classes updates (outstanding ones only)
 
 Enumerable::

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

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