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

ruby-changes:44674

From: nobu <ko1@a...>
Date: Sat, 12 Nov 2016 18:43:09 +0900 (JST)
Subject: [ruby-changes:44674] nobu:r56747 (trunk): class.c: no fstring singleton class

nobu	2016-11-12 18:43:05 +0900 (Sat, 12 Nov 2016)

  New Revision: 56747

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

  Log:
    class.c: no fstring singleton class
    
    * class.c (singleton_class_of): prohibit fstrings from creating
      singleton classes.
      temporary measure for [ruby-dev:49867] [Bug #12923]

  Modified files:
    trunk/class.c
    trunk/test/-ext-/string/test_fstring.rb
Index: test/-ext-/string/test_fstring.rb
===================================================================
--- test/-ext-/string/test_fstring.rb	(revision 56746)
+++ test/-ext-/string/test_fstring.rb	(revision 56747)
@@ -1,8 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/test/-ext-/string/test_fstring.rb#L1
 # frozen_string_literal: false
 require 'test/unit'
 require '-test-/string'
+require_relative '../symbol/noninterned_name'
 
 class Test_String_Fstring < Test::Unit::TestCase
+  include Test_Symbol::NonInterned
+
   def assert_fstring(str)
     fstr = Bug::String.fstring(str)
     yield str
@@ -54,6 +57,12 @@ class Test_String_Fstring < Test::Unit:: https://github.com/ruby/ruby/blob/trunk/test/-ext-/string/test_fstring.rb#L57
     assert_fstring(str) {|s| assert_send([s, :respond_to?, :foo])}
   end
 
+  def test_singleton_class
+    str = noninterned_name.force_encoding("us-ascii")
+    fstr = Bug::String.fstring(str)
+    assert_raise(RuntimeError) {fstr.singleton_class}
+  end
+
   class S < String
   end
 
Index: class.c
===================================================================
--- class.c	(revision 56746)
+++ class.c	(revision 56747)
@@ -1602,6 +1602,9 @@ singleton_class_of(VALUE obj) https://github.com/ruby/ruby/blob/trunk/class.c#L1602
 	switch (BUILTIN_TYPE(obj)) {
 	  case T_FLOAT: case T_BIGNUM: case T_SYMBOL:
 	    goto no_singleton;
+	  case T_STRING:
+	    if (FL_TEST_RAW(obj, RSTRING_FSTR)) goto no_singleton;
+	    break;
 	}
     }
 

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

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