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

ruby-changes:45885

From: nobu <ko1@a...>
Date: Mon, 13 Mar 2017 18:12:09 +0900 (JST)
Subject: [ruby-changes:45885] nobu:r57958 (trunk): string.c: $; is a GC-root

nobu	2017-03-13 18:12:05 +0900 (Mon, 13 Mar 2017)

  New Revision: 57958

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

  Log:
    string.c: $; is a GC-root
    
    * string.c (Init_String): $; must be a GC-root, not to be
      collected.  [ruby-core:79582]

  Modified files:
    trunk/string.c
    trunk/test/ruby/test_string.rb
Index: string.c
===================================================================
--- string.c	(revision 57957)
+++ string.c	(revision 57958)
@@ -10191,6 +10191,7 @@ Init_String(void) https://github.com/ruby/ruby/blob/trunk/string.c#L10191
     rb_fs = Qnil;
     rb_define_hooked_variable("$;", &rb_fs, 0, rb_fs_setter);
     rb_define_hooked_variable("$-F", &rb_fs, 0, rb_fs_setter);
+    rb_gc_register_address(&rb_fs);
 
     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 57957)
+++ test/ruby/test_string.rb	(revision 57958)
@@ -1451,6 +1451,17 @@ CODE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L1451
     assert_raise_with_message(TypeError, /\$;/) {
       $; = []
     }
+
+    assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
+    bug = '[ruby-core:79582] $; must not be GCed'
+    begin;
+      $; = " "
+      $a = nil
+      alias $; $a
+      alias $-F $a
+      GC.start
+      assert_equal([], "".split, bug)
+    end;
   end
 
   def test_split_encoding

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

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