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

ruby-changes:35461

From: naruse <ko1@a...>
Date: Fri, 12 Sep 2014 06:23:04 +0900 (JST)
Subject: [ruby-changes:35461] naruse:r47543 (trunk): * string.c (sym_find): remove Symbol.find because we have Symbol GC now.

naruse	2014-09-12 06:22:52 +0900 (Fri, 12 Sep 2014)

  New Revision: 47543

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

  Log:
    * string.c (sym_find): remove Symbol.find because we have Symbol GC now.
      https://bugs.ruby-lang.org/projects/ruby/wiki/DevelopersMeeting20140904Japan
      If you still want this, request again on Redmine. [Feature #7854]
      https://bugs.ruby-lang.org/issues/7854
    
    * ext/-test-/symbol/init.c (sym_find): moved from string.c for tests.

  Modified files:
    trunk/ChangeLog
    trunk/NEWS
    trunk/ext/-test-/symbol/init.c
    trunk/string.c
    trunk/test/-ext-/symbol/test_inadvertent_creation.rb
    trunk/test/ruby/test_symbol.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47542)
+++ ChangeLog	(revision 47543)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Sep 12 06:15:37 2014  NARUSE, Yui  <naruse@r...>
+
+	* string.c (sym_find): remove Symbol.find because we have Symbol GC now.
+	  https://bugs.ruby-lang.org/projects/ruby/wiki/DevelopersMeeting20140904Japan
+	  If you still want this, request again on Redmine. [Feature #7854]
+	  https://bugs.ruby-lang.org/issues/7854
+
+	* ext/-test-/symbol/init.c (sym_find): moved from string.c for tests.
+
 Fri Sep 12 04:24:03 2014  Eric Wong  <e@8...>
 
 	* insns.def (once): define and use fake RUNNING_THREAD_ONCE_DONE
Index: string.c
===================================================================
--- string.c	(revision 47542)
+++ string.c	(revision 47543)
@@ -8341,20 +8341,6 @@ str_scrub_bang(int argc, VALUE *argv, VA https://github.com/ruby/ruby/blob/trunk/string.c#L8341
 
 /*
  *  call-seq:
- *     Symbol.find(str)   -> symbol or nil
- *
- *  Return the related symbol if the symbol already exists.
- *  Return nil if not.
- */
-
-static VALUE
-sym_find(VALUE dummy, VALUE sym)
-{
-    return rb_check_symbol(&sym);
-}
-
-/*
- *  call-seq:
  *     sym == obj   -> true or false
  *
  *  Equality---If <i>sym</i> and <i>obj</i> are exactly the same
@@ -8924,7 +8910,6 @@ Init_String(void) https://github.com/ruby/ruby/blob/trunk/string.c#L8910
     rb_undef_alloc_func(rb_cSymbol);
     rb_undef_method(CLASS_OF(rb_cSymbol), "new");
     rb_define_singleton_method(rb_cSymbol, "all_symbols", rb_sym_all_symbols, 0); /* in symbol.c */
-    rb_define_singleton_method(rb_cSymbol, "find", sym_find, 1);
 
     rb_define_method(rb_cSymbol, "==", sym_equal, 1);
     rb_define_method(rb_cSymbol, "===", sym_equal, 1);
Index: ext/-test-/symbol/init.c
===================================================================
--- ext/-test-/symbol/init.c	(revision 47542)
+++ ext/-test-/symbol/init.c	(revision 47543)
@@ -2,10 +2,17 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/symbol/init.c#L2
 
 #define init(n) {void Init_##n(VALUE klass); Init_##n(klass);}
 
+static VALUE
+sym_find(VALUE dummy, VALUE sym)
+{
+    return rb_check_symbol(&sym);
+}
+
 void
 Init_symbol(void)
 {
     VALUE mBug = rb_define_module("Bug");
     VALUE klass = rb_define_class_under(mBug, "Symbol", rb_cSymbol);
+    rb_define_singleton_method(klass, "find", sym_find, 1);
     TEST_INIT_FUNCS(init);
 }
Index: NEWS
===================================================================
--- NEWS	(revision 47542)
+++ NEWS	(revision 47543)
@@ -64,8 +64,6 @@ with all sufficient information, see the https://github.com/ruby/ruby/blob/trunk/NEWS#L64
     vfork() is faster than fork() when the parent process uses huge memory.
 
 * Symbol
-  * New methods
-    * Symbol.find(str) returns whether given string is defined as symbol or not.
   * Improvements
     * Most symbols which are returned by String#to_sym and
       String#intern are GC-able.
Index: test/ruby/test_symbol.rb
===================================================================
--- test/ruby/test_symbol.rb	(revision 47542)
+++ test/ruby/test_symbol.rb	(revision 47543)
@@ -1,5 +1,4 @@ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_symbol.rb#L1
 require 'test/unit'
-require_relative 'envutil'
 
 class TestSymbol < Test::Unit::TestCase
   # [ruby-core:3573]
@@ -208,20 +207,6 @@ class TestSymbol < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_symbol.rb#L207
     assert_equal(true, :foo.to_sym.frozen?)
   end
 
-  def test_sym_find
-    assert_separately(%w[--disable=gems], <<-"end;")
-      assert_equal :intern, Symbol.find("intern")
-      assert_raise(TypeError){ Symbol.find(true) }
-
-      str = "__noexistent__"
-      assert_equal nil, Symbol.find(str)
-      assert_equal nil, Symbol.find(str)
-      sym = str.intern
-      assert_equal str, sym.to_s
-      assert_equal sym, Symbol.find(str)
-    end;
-  end
-
   def test_symbol_gc_1
     assert_normal_exit('".".intern;GC.start(immediate_sweep:false);eval %[GC.start;".".intern]',
                        '',
@@ -237,24 +222,4 @@ class TestSymbol < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_symbol.rb#L222
                        '',
                        child_env: '--disable-gems')
   end
-
-  def test_gc_attrset
-    assert_separately(['-', '[ruby-core:62226] [Bug #9787]'], <<-'end;') #    begin
-      bug = ARGV.shift
-      def noninterned_name(prefix = "")
-        prefix += "_#{Thread.current.object_id.to_s(36).tr('-', '_')}"
-        begin
-          name = "#{prefix}_#{rand(0x1000).to_s(16)}_#{Time.now.usec}"
-        end while Symbol.find(name) or Symbol.find(name + "=")
-        name
-      end
-      names = Array.new(1000) {noninterned_name("gc")}
-      names.each {|n| n.to_sym}
-      GC.start(immediate_sweep: false)
-      names.each do |n|
-        eval(":#{n}=")
-        assert_nothing_raised(TypeError, bug) {eval("proc{self.#{n} = nil}")}
-      end
-    end;
-  end
 end
Index: test/-ext-/symbol/test_inadvertent_creation.rb
===================================================================
--- test/-ext-/symbol/test_inadvertent_creation.rb	(revision 47542)
+++ test/-ext-/symbol/test_inadvertent_creation.rb	(revision 47543)
@@ -7,7 +7,7 @@ module Test_Symbol https://github.com/ruby/ruby/blob/trunk/test/-ext-/symbol/test_inadvertent_creation.rb#L7
       prefix += "_#{Thread.current.object_id.to_s(36).tr('-', '_')}"
       begin
         name = "#{prefix}_#{rand(0x1000).to_s(16)}_#{Time.now.usec}"
-      end while ::Symbol.find(name)
+      end while Bug::Symbol.find(name)
       name
     end
 
@@ -16,7 +16,7 @@ module Test_Symbol https://github.com/ruby/ruby/blob/trunk/test/-ext-/symbol/test_inadvertent_creation.rb#L16
     end
 
     def assert_not_interned(name, msg = nil)
-      assert_not_send([::Symbol, :find, name], msg)
+      assert_not_send([Bug::Symbol, :find, name], msg)
     end
 
     def assert_not_interned_error(obj, meth, name, msg = nil)
@@ -262,5 +262,25 @@ module Test_Symbol https://github.com/ruby/ruby/blob/trunk/test/-ext-/symbol/test_inadvertent_creation.rb#L262
       assert_raise(NameError) {mod.module_eval {attr_accessor(name)}}
       assert_not_interned(name)
     end
+
+    def test_gc_attrset
+      assert_separately(['-r-test-/symbol', '-', '[ruby-core:62226] [Bug #9787]'], <<-'end;') #    begin
+      bug = ARGV.shift
+      def noninterned_name(prefix = "")
+        prefix += "_#{Thread.current.object_id.to_s(36).tr('-', '_')}"
+        begin
+          name = "#{prefix}_#{rand(0x1000).to_s(16)}_#{Time.now.usec}"
+        end while Bug::Symbol.find(name) or Bug::Symbol.find(name + "=")
+        name
+      end
+      names = Array.new(1000) {noninterned_name("gc")}
+      names.each {|n| n.to_sym}
+      GC.start(immediate_sweep: false)
+      names.each do |n|
+        eval(":#{n}=")
+        assert_nothing_raised(TypeError, bug) {eval("proc{self.#{n} = nil}")}
+      end
+      end;
+    end
   end
 end

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

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